@@ -28,13 +28,14 @@ module Database.Bloodhound.Client
28 , Seminearring(..)
28 , Seminearring(..)
29 , BoolMatch(..)
29 , BoolMatch(..)
30 , Term(..)
30 , Term(..)
31− , GeoConstraint(..)
31+ , GeoPoint(..)
32 , GeoBoundingBoxConstraint(..)
32 , GeoBoundingBoxConstraint(..)
33 , GeoBoundingBox(..)
33 , GeoBoundingBox(..)
34 , GeoFilterType(..)
34 , GeoFilterType(..)
35 , Distance(..)
35 , Distance(..)
36 , DistanceUnit(..)
36 , DistanceUnit(..)
37 , DistanceType(..)
37 , DistanceType(..)
38 , OptimizeBbox(..)
39 , OptimizeBbox(..)
39 , LatLon(..)
40 , LatLon(..)
@@ -371,7 +372,8 @@ data Filter = AndFilter [Filter] Cache
371 | BoolFilter BoolMatch
372 | BoolFilter BoolMatch
372 | ExistsFilter FieldName -- always cached
373 | ExistsFilter FieldName -- always cached
373 | GeoBoundingBoxFilter GeoBoundingBoxConstraint GeoFilterType
374 | GeoBoundingBoxFilter GeoBoundingBoxConstraint GeoFilterType
374− | GeoDistanceFilter GeoConstraint Distance DistanceType OptimizeBbox Cache
375+ | GeoDistanceFilter GeoPoint Distance DistanceType OptimizeBbox Cache
376+ | GeoDistanceRangeFilter GeoPoint DistanceRange
375 deriving (Eq, Show)
377 deriving (Eq, Show)
377class Monoid a => Seminearring a where
379class Monoid a => Seminearring a where
@@ -413,18 +415,24 @@ instance ToJSON Filter where
413 object ["geo_bounding_box" .= toJSON bbConstraint
415 object ["geo_bounding_box" .= toJSON bbConstraint
414 , "type" .= toJSON filterType]
416 , "type" .= toJSON filterType]
416− toJSON (GeoDistanceFilter (GeoConstraint geoField latLon)
418+ toJSON (GeoDistanceFilter (GeoPoint geoField latLon)
417 distance distanceType optimizeBbox cache) =
419 distance distanceType optimizeBbox cache) =
418 object ["geo_distance" .=
420 object ["geo_distance" .=
419 object ["distance" .= toJSON distance
421 object ["distance" .= toJSON distance
420 , "distance_type" .= toJSON distanceType
422 , "distance_type" .= toJSON distanceType
421 , "optimize_bbox" .= optimizeBbox
423 , "optimize_bbox" .= optimizeBbox
422 , geoField .= toJSON latLon
424 , geoField .= toJSON latLon
423− , "_cache" .= cache
425+ , "_cache" .= cache]]
427+ toJSON (GeoDistanceRangeFilter (GeoPoint geoField latLon)
428+ (DistanceRange distanceFrom distanceTo)) =
429+ object ["geo_distance_range" .=
430+ object ["from" .= toJSON distanceFrom
431+ , "to" .= toJSON distanceTo
432+ , geoField .= toJSON latLon]]
426−instance ToJSON GeoConstraint where
434+instance ToJSON GeoPoint where
427− toJSON (GeoConstraint geoField latLon) =
435+ toJSON (GeoPoint geoField latLon) =
428 object [geoField .= toJSON latLon]
436 object [geoField .= toJSON latLon]
430showText :: Show a => a -> Text
438showText :: Show a => a -> Text
@@ -513,9 +521,9 @@ data GeoBoundingBoxConstraint =
513 , bbConstraintcache :: Cache
521 , bbConstraintcache :: Cache
514 } deriving (Eq, Show)
522 } deriving (Eq, Show)
516−data GeoConstraint =
524+data GeoPoint =
517− GeoConstraint { geoField :: FieldName
525+ GeoPoint { geoField :: FieldName
518− , latLon :: LatLon} deriving (Eq, Show)
526+ , latLon :: LatLon} deriving (Eq, Show)
520data DistanceUnit = Miles
528data DistanceUnit = Miles
@@ -538,6 +546,10 @@ data Distance =
538 Distance { coefficient :: Double
546 Distance { coefficient :: Double
539 , unit :: DistanceUnit } deriving (Eq, Show)
547 , unit :: DistanceUnit } deriving (Eq, Show)
550+ DistanceRange { distanceFrom :: Distance
551+ , distanceTo :: Distance } deriving (Eq, Show)
541data FromJSON a => SearchResult a =
553data FromJSON a => SearchResult a =
542 SearchResult { took :: Int
554 SearchResult { took :: Int
543 , timedOut :: Bool
555 , timedOut :: Bool