@@ -283,6 +283,199 @@ Right [Hit {hitIndex = IndexName "twitter"
284*** Filtering
284*** Filtering
286+**** And, Not, and Or filters
288+Filters form a monoid and seminearring.
292+instance Monoid Filter where
293+ mempty = IdentityFilter
294+ mappend a b = AndFilter [a, b] defaultCache
296+instance Seminearring Filter where
297+ a <||> b = OrFilter [a, b] defaultCache
299+-- AndFilter and OrFilter take [Filter] as an argument.
301+-- This will return anything, because IdentityFilter returns everything
302+OrFilter [IdentityFilter, someOtherFilter] False
304+-- This will return exactly what someOtherFilter returns
305+AndFilter [IdentityFilter, someOtherFilter] False
307+-- Thanks to the seminearring and monoid, the above can be expressed as:
310+IdentityFilter <&&> someOtherFilter
313+IdentityFilter <||> someOtherFilter
315+-- Also there is a NotFilter, it only accepts a single filter, not a list.
317+NotFilter someOtherFilter False
325+-- And'ing two Identity
326+let queryFilter = IdentityFilter <&&> IdentityFilter
328+let search = mkSearch Nothing (Just queryFilter)
330+reply <- searchByType testServer testIndex testMapping search
336+Similar to boolean queries.
340+-- Will return only items whose "user" field contains the term "bitemyapp"
341+let queryFilter = BoolFilter (MustMatch (Term "user" "bitemyapp") False)
343+-- Will return only items whose "user" field does not contain the term "bitemyapp"
344+let queryFilter = BoolFilter (MustNotMatch (Term "user" "bitemyapp") False)
346+-- The clause (query) should appear in the matching document.
347+-- In a boolean query with no must clauses, one or more should
348+-- clauses must match a document. The minimum number of should
349+-- clauses to match can be set using the minimum_should_match parameter.
350+let queryFilter = BoolFilter (ShouldMatch [(Term "user" "bitemyapp")] False)
358+-- Will filter for documents that have the field "user"
359+let existsFilter = ExistsFilter (FieldName "user")
363+**** Geo BoundingBox Filter
367+-- topLeft and bottomRight
368+let box = GeoBoundingBox (LatLon 40.73 (-74.1)) (LatLon 40.10 (-71.12))
370+let constraint = GeoBoundingBoxConstraint (FieldName "tweet.location") box False
372+-- second argument is GeoFilterType, memory or indexed.
373+let geoFilter = GeoBoundingBoxFilter constraint GeoFilterMemory
377+**** Geo Distance Filter
381+let geoPoint = GeoPoint (FieldName "tweet.location") (LatLon 40.12 (-71.34))
383+-- coefficient and units
384+let distance = Distance 10.0 Miles
386+-- GeoFilterType or NoOptimizeBbox
387+let optimizeBbox = OptimizeGeoFilterType GeoFilterMemory
389+-- SloppyArc is the usual/default optimization in Elasticsearch today
390+-- but pre-1.0 versions will need to pick Arc or Plane.
392+let geoFilter = GeoDistanceFilter geoPoint distance SloppyArc optimizeBbox False
396+**** Geo Distance Range Filter
398+Think of a donut and you won't be far off.
402+let geoPoint = GeoPoint (FieldName "tweet.location") (LatLon 40.12 (-71.34))
404+let distanceRange = DistanceRange (Distance 0.0 Miles) (Distance 10.0 Miles)
406+let geoFilter = GeoDistanceRangeFilter geoPoint distanceRange
410+**** Geo Polygon Filter
414+-- I think I drew a square here.
415+let points = [LatLon 40.0 (-70.00),
416+ LatLon 40.0 (-72.00),
417+ LatLon 41.0 (-70.00),
418+ LatLon 41.0 (-72.00)]
420+let geoFilter = GeoPolygonFilter (FieldName "tweet.location") points
424+**** Document IDs filter
428+-- takes a mapping name and a list of DocIds
429+IdsFilter (MappingName "tweet") [DocId "1"]
439+-- RangeFilter :: FieldName
440+-- -> Either HalfRange Range
442+-- -> Cache -> Filter
444+let filter = RangeFilter (FieldName "age")
445+ (Right (RangeLtGt (LessThan 100000.0) (GreaterThan 1000.0)))
446+ RangeExecutionIndex False
454+let filter = RangeFilter (FieldName "age")
455+ (Left (HalfRangeLt (LessThan 100000.0)))
456+ RangeExecutionIndex False
472+let filter = RegexpFilter (FieldName "user") (Regexp "bite.*app")
473+ RegexpAll (CacheName "test") False (CacheKey "key")
475+-- RegexpFlags can be a combination of RegexpAll, Complement,
476+-- Interval, Intersection, AnyString, and a combination of two options thereof.
287* Possible future functionality
480* Possible future functionality