@@ -1,5 +1,4 @@
1{-# LANGUAGE DeriveGeneric #-}
1{-# LANGUAGE DeriveGeneric #-}
2−{-# LANGUAGE OverloadedStrings #-}
4module Database.Bloodhound.Client
3module Database.Bloodhound.Client
5 ( createIndex
4 ( createIndex
@@ -330,22 +329,45 @@ queryStringQuery query = emptyQueryStringQuery { query = query }
330type FieldName = Text
329type FieldName = Text
332type Cache = Bool -- caching on/off
331type Cache = Bool -- caching on/off
333−data Filter = AndFilter [Filter] (Maybe Cache)
332+data Filter = AndFilter [Filter] Cache
334− | OrFilter [Filter] (Maybe Cache)
333+ | OrFilter [Filter] Cache
335− | BoolFilter BoolMatch (Maybe Cache)
334+ | BoolFilter BoolMatch Cache
336 | ExistsFilter FieldName -- always cached
335 | ExistsFilter FieldName -- always cached
337− | GeoBoundingBoxFilter GeoBoundingBoxConstraint GeoFilterType (Maybe Cache)
336+ | GeoBoundingBoxFilter GeoBoundingBoxConstraint GeoFilterType Cache
338− | GeoDistanceFilter GeoConstraint Distance (Maybe Cache)
337+ | GeoDistanceFilter GeoConstraint Distance Cache
339 deriving (Show)
338 deriving (Show)
340+instance ToJSON Filter where
341+ toJSON (AndFilter filters cache) =
342+ object ["and" .= fmap toJSON filters
343+ , "_cache" .= cache]
344+ toJSON (OrFilter filters cache) =
345+ object ["or" .= fmap toJSON filters
346+ , "_cache" .= cache]
347+ toJSON (ExistsFilter fieldName) =
348+ object ["exists" .= object
349+ ["field" .= fieldName]]
350+ toJSON (BoolFilter boolMatch cache) =
351+ object ["bool" .= toJSON boolMatch
352+ , "_cache" .= cache]
341-- I dunno.
354-- I dunno.
342data Term = Term { termField :: Text
355data Term = Term { termField :: Text
343 , termValue :: Text } deriving (Show)
356 , termValue :: Text } deriving (Show)
358+instance ToJSON Term where
359+ toJSON (Term termField termValue) = object ["term" .= object
360+ [termField .= termValue]]
345data BoolMatch = MustMatch Term
362data BoolMatch = MustMatch Term
346 | MustNotMatch Term
363 | MustNotMatch Term
347 | ShouldMatch [Term] deriving (Show)
364 | ShouldMatch [Term] deriving (Show)
366+instance ToJSON BoolMatch where
367+ toJSON (MustMatch term) = object ["must" .= toJSON term]
368+ toJSON (MustNotMatch term) = object ["must_not" .= toJSON term]
369+ toJSON (ShouldMatch terms) = object ["should" .= fmap toJSON terms]
349-- "memory" or "indexed"
371-- "memory" or "indexed"
350data GeoFilterType = GeoFilterMemory | GeoFilterIndexed deriving (Show)
372data GeoFilterType = GeoFilterMemory | GeoFilterIndexed deriving (Show)