@@ -13,6 +13,7 @@ import Data.Monoid
1313import qualified Data.Text as T
1414import Database.Bloodhound.Types
1515import Database.Bloodhound.Types.Class
16+import Data.Scientific
1617
1718instance Monoid Filter where
1819 mempty = IdentityFilter
@@ -129,9 +130,7 @@ instance ToJSON Query where
129130 object [termField .= object merged]]
130131 where
131132 base = [ "value" .= termValue ]
132− boosted = case boost of
133− (Just boostValue) -> [ "boost" .= boostValue ]
134− Nothing -> []
133+ boosted = maybe [] (return . ("boost" .=)) boost
135134 merged = mappend base boosted
136135
137136 toJSON (QueryMatchQuery matchQuery) =
@@ -146,11 +145,36 @@ instance ToJSON Query where
146145 toJSON (QueryBoostingQuery boostingQuery) =
147146 object ["boosting" .= toJSON boostingQuery]
148147
148+ toJSON (QueryCommonTermsQuery commonTermsQuery) =
149+ object ["common" .= toJSON commonTermsQuery]
149150
150151mField :: (ToJSON a, Functor f) => T.Text -> f a -> f (T.Text, Value)
151152mField field = fmap ((field .=) . toJSON)
152153
153154
155+instance ToJSON CommonTermsQuery where
156+ toJSON (CommonTermsQuery (FieldName fieldName)
157+ (QueryString query) cf lfo hfo msm
158+ boost analyzer disableCoord) =
159+ object [fieldName .= object conjoined]
160+ where base = [ "query" .= query
161+ , "cutoff_frequency" .= toJSON cf
162+ , "low_freq_operator" .= toJSON lfo
163+ , "high_freq_operator" .= toJSON hfo ]
164+ extension = catMaybes
165+ [ mField "minimum_should_match" msm
166+ , mField "boost" boost
167+ , mField "analyzer" analyzer
168+ , mField "disable_coord" disableCoord ]
169+ conjoined = base ++ extension
170+
171+
172+instance ToJSON CommonMinimumMatch where
173+ toJSON (CommonMinimumMatch mm) = toJSON mm
174+ toJSON (CommonMinimumMatchHighLow (MinimumMatchHighLow lowF highF)) =
175+ object [ "low_freq" .= toJSON lowF
176+ , "high_freq" .= toJSON highF ]
177+
154178instance ToJSON BoostingQuery where
155179 toJSON (BoostingQuery positiveQuery negativeQuery negativeBoost) =
156180 object [ "positive" .= toJSON positiveQuery