git.iko.soy/typeable/bloodhound
on master help sign in
well, stuff type checks now
commit5095c95e852792bf12cd83febad3294225d20e12 authorChris Allen <cma@bitemyapp.com> dateFri 2 May 2014, 22:54 (12 years ago) parenta2cd1f8
3 files changed+92−48
Database/Bloodhound/Types.hs+32−16 Database/Bloodhound/Types/Instances.hs+57−31 bloodhound.cabal+3−1
Database/Bloodhound/Types.hs+32−16
@@ -80,7 +80,7 @@ module Database.Bloodhound.Types
8080 , FuzzyQuery(..)
8181 , HasChildQuery(..)
8282 , HasParentQuery(..)
83− , AnIndicesQuery(..)
83+ , IndicesQuery(..)
8484 , MoreLikeThisQuery(..)
8585 , MoreLikeThisFieldQuery(..)
8686 , NestedQuery(..)
@@ -103,6 +103,22 @@ module Database.Bloodhound.Types
103103 , DisableCoord(..)
104104 , CommonMinimumMatch(..)
105105 , 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(..)
106122 ) where
107123
108124import Data.Aeson
@@ -226,30 +242,30 @@ newtype MaxExpansions = MaxExpansions Int deriving (Eq, Show, Generic
226242newtype Lenient = Lenient Bool deriving (Eq, Show, Generic)
227243newtype Tiebreaker = Tiebreaker Double deriving (Eq, Show, Generic)
228244newtype Boost = Boost Double deriving (Eq, Show, Generic)
229−newtype BoostTerms = BoostTerms Double deriving (Eq, Show)
245+newtype BoostTerms = BoostTerms Double deriving (Eq, Show, Generic)
230246newtype MinimumMatch = MinimumMatch Int deriving (Eq, Show, Generic)
231247newtype MinimumMatchText = MinimumMatchText Text deriving (Eq, Show)
232248newtype DisableCoord = DisableCoord Bool deriving (Eq, Show, Generic)
233−newtype IgnoreTermFrequency = IgnoreTermFrequency Bool deriving (Eq, Show)
234−newtype MinimumTermFrequency = MinimumTermFrequency Int deriving (Eq, Show)
235−newtype MaxQueryTerms = MaxQueryTerms Int deriving (Eq, Show)
236−newtype Fuzziness = Fuzziness Double deriving (Eq, Show)
237−newtype PrefixLength = PrefixLength Int deriving (Eq, Show)
238−newtype TypeName = TypeName Text deriving (Eq, Show)
239−newtype PercentMatch = PercentMatch Double deriving (Eq, Show)
240−newtype StopWord = StopWord Text deriving (Eq, Show)
241−newtype QueryPath = QueryPath Text deriving (Eq, Show)
249+newtype IgnoreTermFrequency = IgnoreTermFrequency Bool deriving (Eq, Show, Generic)
250+newtype MinimumTermFrequency = MinimumTermFrequency Int deriving (Eq, Show, Generic)
251+newtype MaxQueryTerms = MaxQueryTerms Int deriving (Eq, Show, Generic)
252+newtype Fuzziness = Fuzziness Double deriving (Eq, Show, Generic)
253+newtype PrefixLength = PrefixLength Int deriving (Eq, Show, Generic)
254+newtype TypeName = TypeName Text deriving (Eq, Show, Generic)
255+newtype PercentMatch = PercentMatch Double deriving (Eq, Show, Generic)
256+newtype StopWord = StopWord Text deriving (Eq, Show, Generic)
257+newtype QueryPath = QueryPath Text deriving (Eq, Show, Generic)
242258newtype AllowLeadingWildcard = AllowLeadingWildcard Bool deriving (Eq, Show)
243259newtype LowercaseExpanded = LowercaseExpanded Bool deriving (Eq, Show)
244260newtype EnablePositionIncrements = EnablePositionIncrements Bool deriving (Eq, Show)
245261newtype AnalyzeWildcard = AnalyzeWildcard Bool deriving (Eq, Show)
246262newtype GeneratePhraseQueries = GeneratePhraseQueries Bool deriving (Eq, Show)
247263newtype Locale = Locale Text deriving (Eq, Show)
248−newtype MaxWordLength = MaxWordLength Int deriving (Eq, Show)
249−newtype MinWordLength = MinWordLength Int deriving (Eq, Show)
250−newtype PhraseSlop = PhraseSlop Int deriving (Eq, Show)
251−newtype MinDocFrequency = MinDocFrequency Int deriving (Eq, Show)
252−newtype MaxDocFrequency = MaxDocFrequency Int deriving (Eq, Show)
264+newtype MaxWordLength = MaxWordLength Int deriving (Eq, Show, Generic)
265+newtype MinWordLength = MinWordLength Int deriving (Eq, Show, Generic)
266+newtype PhraseSlop = PhraseSlop Int deriving (Eq, Show, Generic)
267+newtype MinDocFrequency = MinDocFrequency Int deriving (Eq, Show, Generic)
268+newtype MaxDocFrequency = MaxDocFrequency Int deriving (Eq, Show, Generic)
253269
254270unpackId :: DocId -> String
255271unpackId (DocId docId) = docId
Database/Bloodhound/Types/Instances.hs+57−31
@@ -153,7 +153,7 @@ instance ToJSON Query where
153153 , "boost" .= toJSON boost]
154154
155155 toJSON (ConstantScoreQuery query boost) =
156− object [ "constant_score" .= toJSON filter
156+ object [ "constant_score" .= toJSON query
157157 , "boost" .= toJSON boost]
158158
159159 toJSON (QueryDisMaxQuery disMaxQuery) =
@@ -182,7 +182,7 @@ instance ToJSON Query where
182182
183183 toJSON (MatchAllQuery boost) =
184184 object [ "match_all" .= object maybeAdd ]
185− where maybeAdd catMaybes [ mField "boost" boost ]
185+ where maybeAdd = catMaybes [ mField "boost" boost ]
186186
187187 toJSON (QueryMoreLikeThisQuery query) =
188188 object [ "more_like_this" .= toJSON query ]
@@ -201,29 +201,28 @@ mField :: (ToJSON a, Functor f) => T.Text -> f a -> f (T.Text, Value)
201201mField field = fmap ((field .=) . toJSON)
202202
203203
204−instance PrefixQuery where
204+instance ToJSON PrefixQuery where
205205 toJSON (PrefixQuery (FieldName fieldName) queryValue boost) =
206206 object [ fieldName .= object conjoined ]
207207 where base = [ "value" .= toJSON queryValue ]
208− maybeAdd = [ mField "boost" boost ]
208+ maybeAdd = catMaybes [ mField "boost" boost ]
209209 conjoined = base ++ maybeAdd
210210
211211
212−instance NestedQuery where
212+instance ToJSON NestedQuery where
213213 toJSON (NestedQuery path scoreType query) =
214214 object [ "path" .= toJSON path
215215 , "score_mode" .= toJSON scoreType
216216 , "query" .= toJSON query ]
217217
218218
219−instance MoreLikeThisFieldQuery where
219+instance ToJSON MoreLikeThisFieldQuery where
220220 toJSON (MoreLikeThisFieldQuery text (FieldName fieldName)
221221 percent mtf mqt stopwords mindf maxdf
222222 minwl maxwl boostTerms boost analyzer) =
223223 object [ fieldName .= object conjoined ]
224224 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
227226 , mField "min_term_freq" mtf
228227 , mField "max_query_terms" mqt
229228 , mField "stop_words" stopwords
@@ -260,22 +259,22 @@ instance ToJSON MoreLikeThisQuery where
260259
261260instance ToJSON IndicesQuery where
262261 toJSON (IndicesQuery indices query noMatch) =
263− object [ "indices" .= toJSON indices
264− , "query" .= toJSON query ] ++ maybeAdd
262+ object $ [ "indices" .= toJSON indices
263+ , "query" .= toJSON query ] ++ maybeAdd
265264 where maybeAdd = catMaybes [ mField "no_match_query" noMatch ]
266265
267266
268267instance ToJSON HasParentQuery where
269268 toJSON (HasParentQuery queryType query scoreType) =
270− object [ "parent_type" .= toJSON queryType
271− , "query" .= toJSON query ] ++ maybeAdd
269+ object $ [ "parent_type" .= toJSON queryType
270+ , "query" .= toJSON query ] ++ maybeAdd
272271 where maybeAdd = catMaybes [ mField "score_type" scoreType ]
273272
274273
275274instance ToJSON HasChildQuery where
276275 toJSON (HasChildQuery queryType query scoreType) =
277− object [ "query" .= toJSON query
278− , "type" .= toJSON queryType ] ++ maybeAdd
276+ object $ [ "query" .= toJSON query
277+ , "type" .= toJSON queryType ] ++ maybeAdd
279278 where maybeAdd = catMaybes [ mField "score_type" scoreType ]
280279
281280
@@ -295,27 +294,29 @@ instance ToJSON FuzzyLikeFieldQuery where
295294 toJSON (FuzzyLikeFieldQuery (FieldName fieldName)
296295 fieldText maxTerms ignoreFreq fuzziness prefixLength
297296 boost analyzer) =
298− object [ fieldName .=
299− object [ "like_text" .= toJSON fieldText
300− , "max_query_terms" .= toJSON maxTerms
301− , "ignore_tf" .= toJSON ignoreFreq
302− , "fuzziness" .= toJSON fuzziness
303− , "prefix_length" .= toJSON prefixLength
304− , "boost" .= toJSON boost ]] ++ maybeAdd
297+ object $ [ fieldName .=
298+ object [ "like_text" .= toJSON fieldText
299+ , "max_query_terms" .= toJSON maxTerms
300+ , "ignore_tf" .= toJSON ignoreFreq
301+ , "fuzziness" .= toJSON fuzziness
302+ , "prefix_length" .= toJSON prefixLength
303+ , "boost" .= toJSON boost ]] ++ maybeAdd
305304 where maybeAdd = catMaybes [ mField "analyzer" analyzer ]
306305
307306
308307instance ToJSON FuzzyLikeThisQuery where
309308 toJSON (FuzzyLikeThisQuery fields text maxTerms
310309 ignoreFreq fuzziness prefixLength boost analyzer) =
311− object [ "fields" .= toJSON fields
312− , "like_text" .= toJSON text
313− , "max_query_terms" .= toJSON maxTerms
314− , "ignore_tf" .= toJSON ignoreFreq
315− , "fuzziness" .= toJSON fuzziness
316− , "prefix_length" .= toJSON prefixLength
317− , "boost" .= toJSON boost ] ++ maybeAdd
318− where maybeAdd = catMaybes [ mField "analyzer" analyzer ]
310+ object conjoined
311+ where base = [ "fields" .= toJSON fields
312+ , "like_text" .= toJSON text
313+ , "max_query_terms" .= toJSON maxTerms
314+ , "ignore_tf" .= toJSON ignoreFreq
315+ , "fuzziness" .= toJSON fuzziness
316+ , "prefix_length" .= toJSON prefixLength
317+ , "boost" .= toJSON boost ]
318+ maybeAdd = catMaybes [ mField "analyzer" analyzer ]
319+ conjoined = base ++ maybeAdd
319320
320321
321322instance ToJSON FilteredQuery where
@@ -326,9 +327,11 @@ instance ToJSON FilteredQuery where
326327
327328instance ToJSON DisMaxQuery where
328329 toJSON (DisMaxQuery queries tiebreaker boost) =
329− object [ "queries" .= toJSON queries
330− , "tie_breaker" .= toJSON tiebreaker ] ++ maybeAdd
330+ object conjoined
331331 where maybeAdd = catMaybes [mField "boost" boost]
332+ base = [ "queries" .= toJSON queries
333+ , "tie_breaker" .= toJSON tiebreaker ]
334+ conjoined = base ++ maybeAdd
332335
333336
334337instance ToJSON CommonTermsQuery where
@@ -440,6 +443,22 @@ instance ToJSON Version
440443instance ToJSON Tiebreaker
441444instance ToJSON MinimumMatch
442445instance 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
443462instance FromJSON Version
444463instance FromJSON IndexName
445464instance FromJSON MappingName
@@ -521,6 +540,13 @@ instance ToJSON Missing where
521540 toJSON (CustomMissing txt) = String txt
522541
523542
543+instance ToJSON ScoreType where
544+ toJSON ScoreTypeMax = "max"
545+ toJSON ScoreTypeAvg = "avg"
546+ toJSON ScoreTypeSum = "sum"
547+ toJSON ScoreTypeNone = "none"
548+
549+
524550instance ToJSON Distance where
525551 toJSON (Distance coefficient unit) =
526552 String boltedTogether where
bloodhound.cabal+3−1
@@ -40,7 +40,9 @@ library
4040 http-types >= 0.8,
4141 blaze-builder >= 0.3,
4242 failure >= 0.2,
43− semigroups >= 0.12
43+ semigroups >= 0.12,
44+ containers ,
45+ scientific
4446 default-language: Haskell2010
4547
4648test-suite tests