@@ -28,13 +28,14 @@ module Database.Bloodhound.Client
2828 , Seminearring(..)
2929 , BoolMatch(..)
3030 , Term(..)
31− , GeoConstraint(..)
31+ , GeoPoint(..)
3232 , GeoBoundingBoxConstraint(..)
3333 , GeoBoundingBox(..)
3434 , GeoFilterType(..)
3535 , Distance(..)
3636 , DistanceUnit(..)
3737 , DistanceType(..)
38+ , DistanceRange(..)
3839 , OptimizeBbox(..)
3940 , LatLon(..)
4041 )
@@ -371,7 +372,8 @@ data Filter = AndFilter [Filter] Cache
371372 | BoolFilter BoolMatch
372373 | ExistsFilter FieldName -- always cached
373374 | GeoBoundingBoxFilter GeoBoundingBoxConstraint GeoFilterType
374− | GeoDistanceFilter GeoConstraint Distance DistanceType OptimizeBbox Cache
375+ | GeoDistanceFilter GeoPoint Distance DistanceType OptimizeBbox Cache
376+ | GeoDistanceRangeFilter GeoPoint DistanceRange
375377 deriving (Eq, Show)
376378
377379class Monoid a => Seminearring a where
@@ -413,18 +415,24 @@ instance ToJSON Filter where
413415 object ["geo_bounding_box" .= toJSON bbConstraint
414416 , "type" .= toJSON filterType]
415417
416− toJSON (GeoDistanceFilter (GeoConstraint geoField latLon)
418+ toJSON (GeoDistanceFilter (GeoPoint geoField latLon)
417419 distance distanceType optimizeBbox cache) =
418420 object ["geo_distance" .=
419421 object ["distance" .= toJSON distance
420422 , "distance_type" .= toJSON distanceType
421423 , "optimize_bbox" .= optimizeBbox
422424 , geoField .= toJSON latLon
423− , "_cache" .= cache
424− ]]
425+ , "_cache" .= cache]]
425426
426−instance ToJSON GeoConstraint where
427− toJSON (GeoConstraint geoField latLon) =
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]]
433+
434+instance ToJSON GeoPoint where
435+ toJSON (GeoPoint geoField latLon) =
428436 object [geoField .= toJSON latLon]
429437
430438showText :: Show a => a -> Text
@@ -513,9 +521,9 @@ data GeoBoundingBoxConstraint =
513521 , bbConstraintcache :: Cache
514522 } deriving (Eq, Show)
515523
516−data GeoConstraint =
517− GeoConstraint { geoField :: FieldName
518− , latLon :: LatLon} deriving (Eq, Show)
524+data GeoPoint =
525+ GeoPoint { geoField :: FieldName
526+ , latLon :: LatLon} deriving (Eq, Show)
519527
520528data DistanceUnit = Miles
521529 | Yards
@@ -538,6 +546,10 @@ data Distance =
538546 Distance { coefficient :: Double
539547 , unit :: DistanceUnit } deriving (Eq, Show)
540548
549+data DistanceRange =
550+ DistanceRange { distanceFrom :: Distance
551+ , distanceTo :: Distance } deriving (Eq, Show)
552+
541553data FromJSON a => SearchResult a =
542554 SearchResult { took :: Int
543555 , timedOut :: Bool