git.iko.soy/typeable/bloodhound
on master help sign in
more query support
11b3b3eChris Allen
Database/Bloodhound/Types.hs+2−11
@@ -283,7 +283,7 @@ data Query = TermQuery Term (Maybe Boost)
283 | QueryHasChildQuery HasChildQuery
283 | QueryHasChildQuery HasChildQuery
284 | QueryHasParentQuery HasParentQuery
284 | QueryHasParentQuery HasParentQuery
285 | IdsQuery MappingName [DocId]
285 | IdsQuery MappingName [DocId]
286− | QueryIndicesQuery AnIndicesQuery
286+ | QueryIndicesQuery IndicesQuery
287 | MatchAllQuery (Maybe Boost)
287 | MatchAllQuery (Maybe Boost)
288 | QueryMoreLikeThisQuery MoreLikeThisQuery
288 | QueryMoreLikeThisQuery MoreLikeThisQuery
289 | QueryMoreLikeThisFieldQuery MoreLikeThisFieldQuery
289 | QueryMoreLikeThisFieldQuery MoreLikeThisFieldQuery
@@ -399,22 +399,13 @@ data MoreLikeThisQuery =
399 , moreLikeThisAnalyzer :: Maybe Analyzer
399 , moreLikeThisAnalyzer :: Maybe Analyzer
400 } deriving (Eq, Show)
400 } deriving (Eq, Show)
401
401
402−data AnIndicesQuery = AnIndexQuery IndexQuery
403− | AnIndicesQuery IndicesQuery deriving (Eq, Show)
404−
405
402
406data IndicesQuery =
403data IndicesQuery =
407− IndicesQuery { indicesQueryIndexName :: IndexName
404+ IndicesQuery { indicesQueryIndices :: [IndexName]
408 , indicesQuery :: Query
405 , indicesQuery :: Query
409 -- default "all"
406 -- default "all"
410 , indicesQueryNoMatch :: Maybe Query } deriving (Eq, Show)
407 , indicesQueryNoMatch :: Maybe Query } deriving (Eq, Show)
411
408
412−data IndexQuery =
413− IndexQuery { indexQueryIndexName :: IndexName
414− , indexQuery :: Query
415− -- default "all"
416− , indexQueryNoMatch :: Maybe Query } deriving (Eq, Show)
417−
418data HasParentQuery =
409data HasParentQuery =
419 HasParentQuery { hasParentQueryType :: TypeName
410 HasParentQuery { hasParentQueryType :: TypeName
420 , hasParentQuery :: Query
411 , hasParentQuery :: Query
Database/Bloodhound/Types/Instances.hs+170−2
@@ -143,15 +143,183 @@ instance ToJSON Query where
143 object [ "bool" .= toJSON boolQuery ]
143 object [ "bool" .= toJSON boolQuery ]
144
144
145 toJSON (QueryBoostingQuery boostingQuery) =
145 toJSON (QueryBoostingQuery boostingQuery) =
146− object ["boosting" .= toJSON boostingQuery]
146+ object [ "boosting" .= toJSON boostingQuery ]
147
147
148 toJSON (QueryCommonTermsQuery commonTermsQuery) =
148 toJSON (QueryCommonTermsQuery commonTermsQuery) =
149− object ["common" .= toJSON commonTermsQuery]
149+ object [ "common" .= toJSON commonTermsQuery ]
150+
151+ toJSON (ConstantScoreFilter filter boost) =
152+ object [ "constant_score" .= toJSON filter
153+ , "boost" .= toJSON boost]
154+
155+ toJSON (ConstantScoreQuery query boost) =
156+ object [ "constant_score" .= toJSON filter
157+ , "boost" .= toJSON boost]
158+
159+ toJSON (QueryDisMaxQuery disMaxQuery) =
160+ object [ "dis_max" .= toJSON disMaxQuery ]
161+
162+ toJSON (QueryFilteredQuery filteredQuery) =
163+ object [ "filtered" .= toJSON filteredQuery ]
164+
165+ toJSON (QueryFuzzyLikeThisQuery fuzzyQuery) =
166+ object [ "fuzzy_like_this" .= toJSON fuzzyQuery ]
167+
168+ toJSON (QueryFuzzyLikeFieldQuery fuzzyFieldQuery) =
169+ object [ "fuzzy_like_this_field" .= toJSON fuzzyFieldQuery ]
170+
171+ toJSON (QueryFuzzyQuery fuzzyQuery) =
172+ object [ "fuzzy" .= toJSON fuzzyQuery ]
173+
174+ toJSON (QueryHasChildQuery childQuery) =
175+ object [ "has_child" .= toJSON childQuery ]
176+
177+ toJSON (QueryHasParentQuery parentQuery) =
178+ object [ "has_parent" .= toJSON parentQuery ]
179+
180+ toJSON (QueryIndicesQuery indicesQuery) =
181+ object [ "indices" .= toJSON indicesQuery ]
182+
183+ toJSON (MatchAllQuery boost) =
184+ object [ "match_all" .= object maybeAdd ]
185+ where maybeAdd catMaybes [ mField "boost" boost ]
186+
187+ toJSON (QueryMoreLikeThisQuery query) =
188+ object [ "more_like_this" .= toJSON query ]
189+
190+ toJSON (QueryMoreLikeThisFieldQuery query) =
191+ object [ "more_like_this_field" .= toJSON query ]
192+
193+ toJSON (QueryNestedQuery query) =
194+ object [ "nested" .= toJSON query ]
195+
150
196
151mField :: (ToJSON a, Functor f) => T.Text -> f a -> f (T.Text, Value)
197mField :: (ToJSON a, Functor f) => T.Text -> f a -> f (T.Text, Value)
152mField field = fmap ((field .=) . toJSON)
198mField field = fmap ((field .=) . toJSON)
153
199
154
200
201+instance NestedQuery where
202+ toJSON (NestedQuery path scoreType query) =
203+ object [ "path" .= toJSON path
204+ , "score_mode" .= toJSON scoreType
205+ , "query" .= toJSON query ]
206+
207+
208+instance MoreLikeThisFieldQuery where
209+ toJSON (MoreLikeThisFieldQuery text (FieldName fieldName)
210+ percent mtf mqt stopwords mindf maxdf
211+ minwl maxwl boostTerms boost analyzer) =
212+ object [ fieldName .= object conjoined ]
213+ where base = [ "like_text" .= toJSON text ]
214+ maybeAdd = catMaybes [ mField "fields" fields
215+ , mField "percent_terms_to_match" percent
216+ , mField "min_term_freq" mtf
217+ , mField "max_query_terms" mqt
218+ , mField "stop_words" stopwords
219+ , mField "min_doc_freq" mindf
220+ , mField "max_doc_freq" maxdf
221+ , mField "min_word_length" minwl
222+ , mField "max_word_length" maxwl
223+ , mField "boost_terms" boostTerms
224+ , mField "boost" boost
225+ , mField "analyzer" analyzer ]
226+ conjoined = base ++ maybeAdd
227+
228+
229+instance ToJSON MoreLikeThisQuery where
230+ toJSON (MoreLikeThisQuery text fields percent
231+ mtf mqt stopwords mindf maxdf
232+ minwl maxwl boostTerms boost analyzer) =
233+ object conjoined
234+ where base = [ "like_text" .= toJSON text ]
235+ maybeAdd = catMaybes [ mField "fields" fields
236+ , mField "percent_terms_to_match" percent
237+ , mField "min_term_freq" mtf
238+ , mField "max_query_terms" mqt
239+ , mField "stop_words" stopwords
240+ , mField "min_doc_freq" mindf
241+ , mField "max_doc_freq" maxdf
242+ , mField "min_word_length" minwl
243+ , mField "max_word_length" maxwl
244+ , mField "boost_terms" boostTerms
245+ , mField "boost" boost
246+ , mField "analyzer" analyzer ]
247+ conjoined = base ++ maybeAdd
248+
249+
250+instance ToJSON IndicesQuery where
251+ toJSON (IndicesQuery indices query noMatch) =
252+ object [ "indices" .= toJSON indices
253+ , "query" .= toJSON query ] ++ maybeAdd
254+ where maybeAdd = catMaybes [ mField "no_match_query" noMatch ]
255+
256+
257+instance ToJSON HasParentQuery where
258+ toJSON (HasParentQuery queryType query scoreType) =
259+ object [ "parent_type" .= toJSON queryType
260+ , "query" .= toJSON query ] ++ maybeAdd
261+ where maybeAdd = catMaybes [ mField "score_type" scoreType ]
262+
263+
264+instance ToJSON HasChildQuery where
265+ toJSON (HasChildQuery queryType query scoreType) =
266+ object [ "query" .= toJSON query
267+ , "type" .= toJSON queryType ] ++ maybeAdd
268+ where maybeAdd = catMaybes [ mField "score_type" scoreType ]
269+
270+
271+instance ToJSON FuzzyQuery where
272+ toJSON (FuzzyQuery (FieldName fieldName) queryText
273+ prefixLength maxEx fuzziness boost) =
274+ object [ fieldName .= object conjoined ]
275+ where base = [ "value" .= toJSON queryText
276+ , "fuzziness" .= toJSON fuzziness
277+ , "prefix_length" .= toJSON prefixLength
278+ , "max_expansions" .= toJSON maxEx ]
279+ maybeAdd = catMaybes [ mField "boost" boost ]
280+ conjoined = base ++ maybeAdd
281+
282+
283+instance ToJSON FuzzyLikeFieldQuery where
284+ toJSON (FuzzyLikeFieldQuery (FieldName fieldName)
285+ fieldText maxTerms ignoreFreq fuzziness prefixLength
286+ boost analyzer) =
287+ object [ fieldName .=
288+ object [ "like_text" .= toJSON fieldText
289+ , "max_query_terms" .= toJSON maxTerms
290+ , "ignore_tf" .= toJSON ignoreFreq
291+ , "fuzziness" .= toJSON fuzziness
292+ , "prefix_length" .= toJSON prefixLength
293+ , "boost" .= toJSON boost ]] ++ maybeAdd
294+ where maybeAdd = catMaybes [ mField "analyzer" analyzer ]
295+
296+
297+instance ToJSON FuzzyLikeThisQuery where
298+ toJSON (FuzzyLikeThisQuery fields text maxTerms
299+ ignoreFreq fuzziness prefixLength boost analyzer) =
300+ object [ "fields" .= toJSON fields
301+ , "like_text" .= toJSON text
302+ , "max_query_terms" .= toJSON maxTerms
303+ , "ignore_tf" .= toJSON ignoreFreq
304+ , "fuzziness" .= toJSON fuzziness
305+ , "prefix_length" .= toJSON prefixLength
306+ , "boost" .= toJSON boost ] ++ maybeAdd
307+ where maybeAdd = catMaybes [ mField "analyzer" analyzer ]
308+
309+
310+instance ToJSON FilteredQuery where
311+ toJSON (FilteredQuery query filter) =
312+ object [ "query" .= toJSON query
313+ , "filter" .= toJSON filter ]
314+
315+
316+instance ToJSON DisMaxQuery where
317+ toJSON (DisMaxQuery queries tiebreaker boost) =
318+ object [ "queries" .= toJSON queries
319+ , "tie_breaker" .= toJSON tiebreaker ] ++ maybeAdd
320+ where maybeAdd = catMaybes [mField "boost" boost]
321+
322+
155instance ToJSON CommonTermsQuery where
323instance ToJSON CommonTermsQuery where
156 toJSON (CommonTermsQuery (FieldName fieldName)
324 toJSON (CommonTermsQuery (FieldName fieldName)
157 (QueryString query) cf lfo hfo msm
325 (QueryString query) cf lfo hfo msm