IdsFilter w/ validation

This commit is contained in:
Chris Allen 2014-04-10 20:04:24 -05:00
parent a800719f53
commit 631b8631e6
3 changed files with 30 additions and 1 deletions

View File

@ -375,6 +375,7 @@ data Filter = AndFilter [Filter] Cache
| GeoDistanceFilter GeoPoint Distance DistanceType OptimizeBbox Cache
| GeoDistanceRangeFilter GeoPoint DistanceRange
| GeoPolygonFilter FieldName [LatLon]
| IdsFilter MappingName [DocumentID]
deriving (Eq, Show)
class Monoid a => Seminearring a where
@ -437,6 +438,11 @@ instance ToJSON Filter where
object [geoField .=
object ["points" .= fmap toJSON latLons]]]
toJSON (IdsFilter mappingName values) =
object ["ids" .=
object ["type" .= mappingName
, "values" .= fmap T.pack values]]
instance ToJSON GeoPoint where
toJSON (GeoPoint geoField latLon) =
object [geoField .= toJSON latLon]

View File

@ -6,7 +6,23 @@ Elasticsearch client and query DSL for Haskell
** Possible future functionality
Runtime checking for cycles in data structures:
*** GeoShapeFilter
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-filter.html
*** Geohash cell filter
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geohash-cell-filter.html
*** HasChild Filter
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-has-child-filter.html
*** HasParent Filter
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-has-parent-filter.html
*** Runtime checking for cycles in data structures
check for n > 1 occurrences in DFS:

View File

@ -178,3 +178,10 @@ main = hspec $ do
let geoFilter = GeoPolygonFilter "tweet.location" points
let search = Search Nothing (Just geoFilter)
searchExpectNoResults search
it "returns document for ids filter" $ do
_ <- insertData
let filter = IdsFilter "tweet" ["1"]
let search = Search Nothing (Just filter)
myTweet <- searchTweet search
myTweet `shouldBe` Right exampleTweet