All parsing tests passing now!

This commit is contained in:
Michael Xavier 2015-10-28 19:13:29 -07:00
parent 4768fbdabf
commit 1bffa02a16
2 changed files with 61 additions and 8 deletions

View File

@ -1825,12 +1825,12 @@ instance ToJSON Query where
object [ "common" .= commonTermsQuery ]
toJSON (ConstantScoreFilter csFilter boost) =
object [ "constant_score" .= csFilter
object ["filter" .= object ["constant_score" .= csFilter]
, "boost" .= boost]
toJSON (ConstantScoreQuery query boost) =
object [ "constant_score" .= query
, "boost" .= boost]
object ["query" .= object ["constant_score" .= query]
, "boost" .= boost]
toJSON (QueryDisMaxQuery disMaxQuery) =
object [ "dis_max" .= disMaxQuery ]
@ -1926,10 +1926,15 @@ instance FromJSON Query where
queryBoolQuery = pure . QueryBoolQuery
queryBoostingQuery = pure . QueryBoostingQuery
queryCommonTermsQuery = pure . QueryCommonTermsQuery
constantScoreFilter o = ConstantScoreFilter <$> o .: "constant_score"
<*> o .: "boost"
constantScoreQuery o = ConstantScoreQuery <$> o .: "constant_score"
--FIXME: these are ambiguous
constantScoreFilter o = case HM.lookup "filter" o of
Just (Object o') -> ConstantScoreFilter <$> o' .: "constant_score"
<*> o .: "boost"
_ -> fail "Does not appear to be a ConstantScoreFilter"
constantScoreQuery o = case HM.lookup "query" o of
Just (Object o') -> ConstantScoreQuery <$> o' .: "constant_score"
<*> o .: "boost"
_ -> fail "Does not appear to be a ConstantScoreFilter"
queryDisMaxQuery = pure . QueryDisMaxQuery
queryFilteredQuery = pure . QueryFilteredQuery
queryFuzzyLikeThisQuery = pure . QueryFuzzyLikeThisQuery

View File

@ -351,6 +351,56 @@ instance Arbitrary RegexpFlags where
instance Arbitrary IndexAliasCreate where
arbitrary = IndexAliasCreate <$> arbitrary <*> reduceSize arbitrary
instance Arbitrary Query where
arbitrary = reduceSize $ oneof [ TermQuery <$> arbitrary <*> arbitrary
, TermsQuery <$> arbitrary <*> arbitrary
, QueryMatchQuery <$> arbitrary
, QueryMultiMatchQuery <$> arbitrary
, QueryBoolQuery <$> arbitrary
, QueryBoostingQuery <$> arbitrary
, QueryCommonTermsQuery <$> arbitrary
, ConstantScoreFilter <$> arbitrary <*> arbitrary
, ConstantScoreQuery <$> arbitrary <*> arbitrary
, QueryDisMaxQuery <$> arbitrary
, QueryFilteredQuery <$> arbitrary
, QueryFuzzyLikeThisQuery <$> arbitrary
, QueryFuzzyLikeFieldQuery <$> arbitrary
, QueryFuzzyQuery <$> arbitrary
, QueryHasChildQuery <$> arbitrary
, QueryHasParentQuery <$> arbitrary
, IdsQuery <$> arbitrary <*> arbitrary
, QueryIndicesQuery <$> arbitrary
, MatchAllQuery <$> arbitrary
, QueryMoreLikeThisQuery <$> arbitrary
, QueryMoreLikeThisFieldQuery <$> arbitrary
, QueryNestedQuery <$> arbitrary
, QueryPrefixQuery <$> arbitrary
, QueryQueryStringQuery <$> arbitrary
, QuerySimpleQueryStringQuery <$> arbitrary
, QueryRangeQuery <$> arbitrary
, QueryRegexpQuery <$> arbitrary
]
instance Arbitrary Filter where
arbitrary = reduceSize $ oneof [ AndFilter <$> arbitrary <*> arbitrary
, OrFilter <$> arbitrary <*> arbitrary
, NotFilter <$> arbitrary <*> arbitrary
, pure IdentityFilter
, BoolFilter <$> arbitrary
, ExistsFilter <$> arbitrary
, GeoBoundingBoxFilter <$> arbitrary
, GeoDistanceFilter <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
, GeoDistanceRangeFilter <$> arbitrary <*> arbitrary
, GeoPolygonFilter <$> arbitrary <*> arbitrary
, IdsFilter <$> arbitrary <*> arbitrary
, LimitFilter <$> arbitrary
, MissingFilter <$> arbitrary <*> arbitrary <*> arbitrary
, PrefixFilter <$> arbitrary <*> arbitrary <*> arbitrary
, QueryFilter <$> arbitrary <*> arbitrary
, RangeFilter <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
, RegexpFilter <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
, TermFilter <$> arbitrary <*> arbitrary]
$(derive makeArbitrary ''IndexName)
$(derive makeArbitrary ''MappingName)
$(derive makeArbitrary ''DocId)
@ -394,8 +444,6 @@ $(derive makeArbitrary ''PhraseSlop)
$(derive makeArbitrary ''MinDocFrequency)
$(derive makeArbitrary ''MaxDocFrequency)
$(derive makeArbitrary ''Regexp)
$(derive makeArbitrary ''Filter)
$(derive makeArbitrary ''Query)
$(derive makeArbitrary ''SimpleQueryStringQuery)
$(derive makeArbitrary ''FieldOrFields)
$(derive makeArbitrary ''SimpleQueryFlag)