git.iko.soy/typeable/bloodhound
on master help sign in
well, stuff type checks now
5095c95Chris Allen
Database/Bloodhound/Types.hs+32−16
@@ -80,7 +80,7 @@ module Database.Bloodhound.Types
80 , FuzzyQuery(..)
80 , FuzzyQuery(..)
81 , HasChildQuery(..)
81 , HasChildQuery(..)
82 , HasParentQuery(..)
82 , HasParentQuery(..)
83− , AnIndicesQuery(..)
83+ , IndicesQuery(..)
84 , MoreLikeThisQuery(..)
84 , MoreLikeThisQuery(..)
85 , MoreLikeThisFieldQuery(..)
85 , MoreLikeThisFieldQuery(..)
86 , NestedQuery(..)
86 , NestedQuery(..)
@@ -103,6 +103,22 @@ module Database.Bloodhound.Types
103 , DisableCoord(..)
103 , DisableCoord(..)
104 , CommonMinimumMatch(..)
104 , CommonMinimumMatch(..)
105 , MinimumMatchHighLow(..)
105 , MinimumMatchHighLow(..)
106+ , PrefixLength(..)
107+ , Fuzziness(..)
108+ , IgnoreTermFrequency(..)
109+ , MaxQueryTerms(..)
110+ , ScoreType(..)
111+ , TypeName(..)
112+ , BoostTerms(..)
113+ , MaxWordLength(..)
114+ , MinWordLength(..)
115+ , MaxDocFrequency(..)
116+ , MinDocFrequency(..)
117+ , PhraseSlop(..)
118+ , StopWord(..)
119+ , QueryPath(..)
120+ , MinimumTermFrequency(..)
121+ , PercentMatch(..)
106 ) where
122 ) where
107
123
108import Data.Aeson
124import Data.Aeson
@@ -226,30 +242,30 @@ newtype MaxExpansions = MaxExpansions Int deriving (Eq, Show, Generic
226newtype Lenient = Lenient Bool deriving (Eq, Show, Generic)
242newtype Lenient = Lenient Bool deriving (Eq, Show, Generic)
227newtype Tiebreaker = Tiebreaker Double deriving (Eq, Show, Generic)
243newtype Tiebreaker = Tiebreaker Double deriving (Eq, Show, Generic)
228newtype Boost = Boost Double deriving (Eq, Show, Generic)
244newtype Boost = Boost Double deriving (Eq, Show, Generic)
229−newtype BoostTerms = BoostTerms Double deriving (Eq, Show)
245+newtype BoostTerms = BoostTerms Double deriving (Eq, Show, Generic)
230newtype MinimumMatch = MinimumMatch Int deriving (Eq, Show, Generic)
246newtype MinimumMatch = MinimumMatch Int deriving (Eq, Show, Generic)
231newtype MinimumMatchText = MinimumMatchText Text deriving (Eq, Show)
247newtype MinimumMatchText = MinimumMatchText Text deriving (Eq, Show)
232newtype DisableCoord = DisableCoord Bool deriving (Eq, Show, Generic)
248newtype DisableCoord = DisableCoord Bool deriving (Eq, Show, Generic)
233−newtype IgnoreTermFrequency = IgnoreTermFrequency Bool deriving (Eq, Show)
249+newtype IgnoreTermFrequency = IgnoreTermFrequency Bool deriving (Eq, Show, Generic)
234−newtype MinimumTermFrequency = MinimumTermFrequency Int deriving (Eq, Show)
250+newtype MinimumTermFrequency = MinimumTermFrequency Int deriving (Eq, Show, Generic)
235−newtype MaxQueryTerms = MaxQueryTerms Int deriving (Eq, Show)
251+newtype MaxQueryTerms = MaxQueryTerms Int deriving (Eq, Show, Generic)
236−newtype Fuzziness = Fuzziness Double deriving (Eq, Show)
252+newtype Fuzziness = Fuzziness Double deriving (Eq, Show, Generic)
237−newtype PrefixLength = PrefixLength Int deriving (Eq, Show)
253+newtype PrefixLength = PrefixLength Int deriving (Eq, Show, Generic)
238−newtype TypeName = TypeName Text deriving (Eq, Show)
254+newtype TypeName = TypeName Text deriving (Eq, Show, Generic)
239−newtype PercentMatch = PercentMatch Double deriving (Eq, Show)
255+newtype PercentMatch = PercentMatch Double deriving (Eq, Show, Generic)
240−newtype StopWord = StopWord Text deriving (Eq, Show)
256+newtype StopWord = StopWord Text deriving (Eq, Show, Generic)
241−newtype QueryPath = QueryPath Text deriving (Eq, Show)
257+newtype QueryPath = QueryPath Text deriving (Eq, Show, Generic)
242newtype AllowLeadingWildcard = AllowLeadingWildcard Bool deriving (Eq, Show)
258newtype AllowLeadingWildcard = AllowLeadingWildcard Bool deriving (Eq, Show)
243newtype LowercaseExpanded = LowercaseExpanded Bool deriving (Eq, Show)
259newtype LowercaseExpanded = LowercaseExpanded Bool deriving (Eq, Show)
244newtype EnablePositionIncrements = EnablePositionIncrements Bool deriving (Eq, Show)
260newtype EnablePositionIncrements = EnablePositionIncrements Bool deriving (Eq, Show)
245newtype AnalyzeWildcard = AnalyzeWildcard Bool deriving (Eq, Show)
261newtype AnalyzeWildcard = AnalyzeWildcard Bool deriving (Eq, Show)
246newtype GeneratePhraseQueries = GeneratePhraseQueries Bool deriving (Eq, Show)
262newtype GeneratePhraseQueries = GeneratePhraseQueries Bool deriving (Eq, Show)
247newtype Locale = Locale Text deriving (Eq, Show)
263newtype Locale = Locale Text deriving (Eq, Show)
248−newtype MaxWordLength = MaxWordLength Int deriving (Eq, Show)
264+newtype MaxWordLength = MaxWordLength Int deriving (Eq, Show, Generic)
249−newtype MinWordLength = MinWordLength Int deriving (Eq, Show)
265+newtype MinWordLength = MinWordLength Int deriving (Eq, Show, Generic)
250−newtype PhraseSlop = PhraseSlop Int deriving (Eq, Show)
266+newtype PhraseSlop = PhraseSlop Int deriving (Eq, Show, Generic)
251−newtype MinDocFrequency = MinDocFrequency Int deriving (Eq, Show)
267+newtype MinDocFrequency = MinDocFrequency Int deriving (Eq, Show, Generic)
252−newtype MaxDocFrequency = MaxDocFrequency Int deriving (Eq, Show)
268+newtype MaxDocFrequency = MaxDocFrequency Int deriving (Eq, Show, Generic)
253
269
254unpackId :: DocId -> String
270unpackId :: DocId -> String
255unpackId (DocId docId) = docId
271unpackId (DocId docId) = docId
Database/Bloodhound/Types/Instances.hs+57−31
@@ -153,7 +153,7 @@ instance ToJSON Query where
153 , "boost" .= toJSON boost]
153 , "boost" .= toJSON boost]
154
154
155 toJSON (ConstantScoreQuery query boost) =
155 toJSON (ConstantScoreQuery query boost) =
156− object [ "constant_score" .= toJSON filter
156+ object [ "constant_score" .= toJSON query
157 , "boost" .= toJSON boost]
157 , "boost" .= toJSON boost]
158
158
159 toJSON (QueryDisMaxQuery disMaxQuery) =
159 toJSON (QueryDisMaxQuery disMaxQuery) =
@@ -182,7 +182,7 @@ instance ToJSON Query where
182
182
183 toJSON (MatchAllQuery boost) =
183 toJSON (MatchAllQuery boost) =
184 object [ "match_all" .= object maybeAdd ]
184 object [ "match_all" .= object maybeAdd ]
185− where maybeAdd catMaybes [ mField "boost" boost ]
185+ where maybeAdd = catMaybes [ mField "boost" boost ]
186
186
187 toJSON (QueryMoreLikeThisQuery query) =
187 toJSON (QueryMoreLikeThisQuery query) =
188 object [ "more_like_this" .= toJSON query ]
188 object [ "more_like_this" .= toJSON query ]
@@ -201,29 +201,28 @@ mField :: (ToJSON a, Functor f) => T.Text -> f a -> f (T.Text, Value)
201mField field = fmap ((field .=) . toJSON)
201mField field = fmap ((field .=) . toJSON)
202
202
203
203
204−instance PrefixQuery where
204+instance ToJSON PrefixQuery where
205 toJSON (PrefixQuery (FieldName fieldName) queryValue boost) =
205 toJSON (PrefixQuery (FieldName fieldName) queryValue boost) =
206 object [ fieldName .= object conjoined ]
206 object [ fieldName .= object conjoined ]
207 where base = [ "value" .= toJSON queryValue ]
207 where base = [ "value" .= toJSON queryValue ]
208− maybeAdd = [ mField "boost" boost ]
208+ maybeAdd = catMaybes [ mField "boost" boost ]
209 conjoined = base ++ maybeAdd
209 conjoined = base ++ maybeAdd
210
210
211
211
212−instance NestedQuery where
212+instance ToJSON NestedQuery where
213 toJSON (NestedQuery path scoreType query) =
213 toJSON (NestedQuery path scoreType query) =
214 object [ "path" .= toJSON path
214 object [ "path" .= toJSON path
215 , "score_mode" .= toJSON scoreType
215 , "score_mode" .= toJSON scoreType
216 , "query" .= toJSON query ]
216 , "query" .= toJSON query ]
217
217
218
218
219−instance MoreLikeThisFieldQuery where
219+instance ToJSON MoreLikeThisFieldQuery where
220 toJSON (MoreLikeThisFieldQuery text (FieldName fieldName)
220 toJSON (MoreLikeThisFieldQuery text (FieldName fieldName)
221 percent mtf mqt stopwords mindf maxdf
221 percent mtf mqt stopwords mindf maxdf
222 minwl maxwl boostTerms boost analyzer) =
222 minwl maxwl boostTerms boost analyzer) =
223 object [ fieldName .= object conjoined ]
223 object [ fieldName .= object conjoined ]
224 where base = [ "like_text" .= toJSON text ]
224 where base = [ "like_text" .= toJSON text ]
225− maybeAdd = catMaybes [ mField "fields" fields
226− , mField "percent_terms_to_match" percent
225+ maybeAdd = catMaybes [ mField "percent_terms_to_match" percent
227 , mField "min_term_freq" mtf
226 , mField "min_term_freq" mtf
228 , mField "max_query_terms" mqt
227 , mField "max_query_terms" mqt
229 , mField "stop_words" stopwords
228 , mField "stop_words" stopwords
@@ -260,22 +259,22 @@ instance ToJSON MoreLikeThisQuery where
260
259
261instance ToJSON IndicesQuery where
260instance ToJSON IndicesQuery where
262 toJSON (IndicesQuery indices query noMatch) =
261 toJSON (IndicesQuery indices query noMatch) =
263− object [ "indices" .= toJSON indices
262+ object $ [ "indices" .= toJSON indices
264− , "query" .= toJSON query ] ++ maybeAdd
263+ , "query" .= toJSON query ] ++ maybeAdd
265 where maybeAdd = catMaybes [ mField "no_match_query" noMatch ]
264 where maybeAdd = catMaybes [ mField "no_match_query" noMatch ]
266
265
267
266
268instance ToJSON HasParentQuery where
267instance ToJSON HasParentQuery where
269 toJSON (HasParentQuery queryType query scoreType) =
268 toJSON (HasParentQuery queryType query scoreType) =
270− object [ "parent_type" .= toJSON queryType
269+ object $ [ "parent_type" .= toJSON queryType
271− , "query" .= toJSON query ] ++ maybeAdd
270+ , "query" .= toJSON query ] ++ maybeAdd
272 where maybeAdd = catMaybes [ mField "score_type" scoreType ]
271 where maybeAdd = catMaybes [ mField "score_type" scoreType ]
273
272
274
273
275instance ToJSON HasChildQuery where
274instance ToJSON HasChildQuery where
276 toJSON (HasChildQuery queryType query scoreType) =
275 toJSON (HasChildQuery queryType query scoreType) =
277− object [ "query" .= toJSON query
276+ object $ [ "query" .= toJSON query
278− , "type" .= toJSON queryType ] ++ maybeAdd
277+ , "type" .= toJSON queryType ] ++ maybeAdd
279 where maybeAdd = catMaybes [ mField "score_type" scoreType ]
278 where maybeAdd = catMaybes [ mField "score_type" scoreType ]
280
279
281
280
@@ -295,27 +294,29 @@ instance ToJSON FuzzyLikeFieldQuery where
295 toJSON (FuzzyLikeFieldQuery (FieldName fieldName)
294 toJSON (FuzzyLikeFieldQuery (FieldName fieldName)
296 fieldText maxTerms ignoreFreq fuzziness prefixLength
295 fieldText maxTerms ignoreFreq fuzziness prefixLength
297 boost analyzer) =
296 boost analyzer) =
298− object [ fieldName .=
297+ object $ [ fieldName .=
299− object [ "like_text" .= toJSON fieldText
298+ object [ "like_text" .= toJSON fieldText
300− , "max_query_terms" .= toJSON maxTerms
299+ , "max_query_terms" .= toJSON maxTerms
301− , "ignore_tf" .= toJSON ignoreFreq
300+ , "ignore_tf" .= toJSON ignoreFreq
302− , "fuzziness" .= toJSON fuzziness
301+ , "fuzziness" .= toJSON fuzziness
303− , "prefix_length" .= toJSON prefixLength
302+ , "prefix_length" .= toJSON prefixLength
304− , "boost" .= toJSON boost ]] ++ maybeAdd
303+ , "boost" .= toJSON boost ]] ++ maybeAdd
305 where maybeAdd = catMaybes [ mField "analyzer" analyzer ]
304 where maybeAdd = catMaybes [ mField "analyzer" analyzer ]
306
305
307
306
308instance ToJSON FuzzyLikeThisQuery where
307instance ToJSON FuzzyLikeThisQuery where
309 toJSON (FuzzyLikeThisQuery fields text maxTerms
308 toJSON (FuzzyLikeThisQuery fields text maxTerms
310 ignoreFreq fuzziness prefixLength boost analyzer) =
309 ignoreFreq fuzziness prefixLength boost analyzer) =
310+ object conjoined
311− object [ "fields" .= toJSON fields
311+ where base = [ "fields" .= toJSON fields
312− , "like_text" .= toJSON text
312+ , "like_text" .= toJSON text
313− , "max_query_terms" .= toJSON maxTerms
313+ , "max_query_terms" .= toJSON maxTerms
314− , "ignore_tf" .= toJSON ignoreFreq
314+ , "ignore_tf" .= toJSON ignoreFreq
315− , "fuzziness" .= toJSON fuzziness
315+ , "fuzziness" .= toJSON fuzziness
316− , "prefix_length" .= toJSON prefixLength
316+ , "prefix_length" .= toJSON prefixLength
317− , "boost" .= toJSON boost ] ++ maybeAdd
317+ , "boost" .= toJSON boost ]
318− where maybeAdd = catMaybes [ mField "analyzer" analyzer ]
318+ maybeAdd = catMaybes [ mField "analyzer" analyzer ]
319+ conjoined = base ++ maybeAdd
319
320
320
321
321instance ToJSON FilteredQuery where
322instance ToJSON FilteredQuery where
@@ -326,9 +327,11 @@ instance ToJSON FilteredQuery where
326
327
327instance ToJSON DisMaxQuery where
328instance ToJSON DisMaxQuery where
328 toJSON (DisMaxQuery queries tiebreaker boost) =
329 toJSON (DisMaxQuery queries tiebreaker boost) =
329− object [ "queries" .= toJSON queries
330+ object conjoined
330− , "tie_breaker" .= toJSON tiebreaker ] ++ maybeAdd
331 where maybeAdd = catMaybes [mField "boost" boost]
331 where maybeAdd = catMaybes [mField "boost" boost]
332+ base = [ "queries" .= toJSON queries
333+ , "tie_breaker" .= toJSON tiebreaker ]
334+ conjoined = base ++ maybeAdd
332
335
333
336
334instance ToJSON CommonTermsQuery where
337instance ToJSON CommonTermsQuery where
@@ -440,6 +443,22 @@ instance ToJSON Version
440instance ToJSON Tiebreaker
443instance ToJSON Tiebreaker
441instance ToJSON MinimumMatch
444instance ToJSON MinimumMatch
442instance ToJSON DisableCoord
445instance ToJSON DisableCoord
446+instance ToJSON PrefixLength
447+instance ToJSON Fuzziness
448+instance ToJSON IgnoreTermFrequency
449+instance ToJSON MaxQueryTerms
450+instance ToJSON TypeName
451+instance ToJSON IndexName
452+instance ToJSON BoostTerms
453+instance ToJSON MaxWordLength
454+instance ToJSON MinWordLength
455+instance ToJSON MaxDocFrequency
456+instance ToJSON MinDocFrequency
457+instance ToJSON PhraseSlop
458+instance ToJSON StopWord
459+instance ToJSON QueryPath
460+instance ToJSON MinimumTermFrequency
461+instance ToJSON PercentMatch
443instance FromJSON Version
462instance FromJSON Version
444instance FromJSON IndexName
463instance FromJSON IndexName
445instance FromJSON MappingName
464instance FromJSON MappingName
@@ -521,6 +540,13 @@ instance ToJSON Missing where
521 toJSON (CustomMissing txt) = String txt
540 toJSON (CustomMissing txt) = String txt
522
541
523
542
543+instance ToJSON ScoreType where
544+ toJSON ScoreTypeMax = "max"
545+ toJSON ScoreTypeAvg = "avg"
546+ toJSON ScoreTypeSum = "sum"
547+ toJSON ScoreTypeNone = "none"
548+
549+
524instance ToJSON Distance where
550instance ToJSON Distance where
525 toJSON (Distance coefficient unit) =
551 toJSON (Distance coefficient unit) =
526 String boltedTogether where
552 String boltedTogether where
bloodhound.cabal+3−1
@@ -40,7 +40,9 @@ library
40 http-types >= 0.8,
40 http-types >= 0.8,
41 blaze-builder >= 0.3,
41 blaze-builder >= 0.3,
42 failure >= 0.2,
42 failure >= 0.2,
43− semigroups >= 0.12
43+ semigroups >= 0.12,
44+ containers ,
45+ scientific
44 default-language: Haskell2010
46 default-language: Haskell2010
45
47
46test-suite tests
48test-suite tests