git.iko.soy/typeable/bloodhound
on master help sign in
Merge pull request #12 from ccarter/master

ES > 1.0.1 fixes for AND Filter and GeoBoundingBoxFilter

commit4b23604732a5284bb5a970abe1f78ae6de6bbbf2 authorChris Allen <cma@bitemyapp.com> dateFri 15 Aug 2014, 15:33 (12 years ago) parent09b0d1a42fd0a9
4 files changed+18−19
Database/Bloodhound/Types.hs+11−9 README.org+2−5 bloodhound.cabal+1−1 tests/tests.hs+4−4
Database/Bloodhound/Types.hs+11−9
@@ -796,7 +796,7 @@ data Filter = AndFilter [Filter] Cache
796796 | IdentityFilter
797797 | BoolFilter BoolMatch
798798 | ExistsFilter FieldName -- always cached
799− | GeoBoundingBoxFilter GeoBoundingBoxConstraint GeoFilterType
799+ | GeoBoundingBoxFilter GeoBoundingBoxConstraint
800800 | GeoDistanceFilter GeoPoint Distance DistanceType OptimizeBbox Cache
801801 | GeoDistanceRangeFilter GeoPoint DistanceRange
802802 | GeoPolygonFilter FieldName [LatLon]
@@ -880,6 +880,7 @@ data GeoBoundingBoxConstraint =
880880 GeoBoundingBoxConstraint { geoBBField :: FieldName
881881 , constraintBox :: GeoBoundingBox
882882 , bbConstraintcache :: Cache
883+ , geoType :: GeoFilterType
883884 } deriving (Eq, Show)
884885
885886data GeoPoint =
@@ -949,8 +950,9 @@ instance Seminearring Filter where
949950
950951instance ToJSON Filter where
951952 toJSON (AndFilter filters cache) =
952− object ["and" .= fmap toJSON filters
953− , "_cache" .= cache]
953+ object ["and" .=
954+ object [ "filters" .= fmap toJSON filters
955+ , "_cache" .= cache]]
954956
955957 toJSON (OrFilter filters cache) =
956958 object ["or" .= fmap toJSON filters
@@ -976,9 +978,8 @@ instance ToJSON Filter where
976978 toJSON (BoolFilter boolMatch) =
977979 object ["bool" .= toJSON boolMatch]
978980
979− toJSON (GeoBoundingBoxFilter bbConstraint filterType) =
980− object ["geo_bounding_box" .= toJSON bbConstraint
981− , "type" .= toJSON filterType]
981+ toJSON (GeoBoundingBoxFilter bbConstraint) =
982+ object ["geo_bounding_box" .= toJSON bbConstraint]
982983
983984 toJSON (GeoDistanceFilter (GeoPoint (FieldName distanceGeoField) geoDistLatLon)
984985 distance distanceType optimizeBbox cache) =
@@ -1282,7 +1283,7 @@ instance ToJSON MoreLikeThisQuery where
12821283 mtf mqt stopwords mindf maxdf
12831284 minwl maxwl boostTerms boost analyzer) =
12841285 omitNulls base
1285− where base = [ "like_text" .= toJSON text
1286+ where base = [ "like_text" .= toJSON text
12861287 , "fields" .= fields
12871288 , "percent_terms_to_match" .= percent
12881289 , "min_term_freq" .= mtf
@@ -1616,9 +1617,10 @@ instance ToJSON OptimizeBbox where
16161617
16171618instance ToJSON GeoBoundingBoxConstraint where
16181619 toJSON (GeoBoundingBoxConstraint
1619− (FieldName gbbcGeoBBField) gbbcConstraintBox cache) =
1620+ (FieldName gbbcGeoBBField) gbbcConstraintBox cache type') =
16201621 object [gbbcGeoBBField .= toJSON gbbcConstraintBox
1621− , "_cache" .= cache]
1622+ , "_cache" .= cache
1623+ , "type" .= type']
16221624
16231625
16241626instance ToJSON GeoFilterType where
README.org+2−5
@@ -212,7 +212,7 @@ resp <- indexDocument testServer testIndex testMapping exampleTweet (DocId "1")
212212
213213Response {responseStatus =
214214 Status {statusCode = 200, statusMessage = "OK"}
215− , responseVersion = HTTP/1.1, responseHeaders =
215+ , responseVersion = HTTP/1.1, responseHeaders =
216216 [("Content-Type","application/json; charset=UTF-8"),
217217 ("Content-Length","75")]
218218 , responseBody = "{\"_index\":\"twitter\",\"_type\":\"tweet\",\"_id\":\"1\",\"_version\":2,\"created\":false}"
@@ -479,10 +479,7 @@ let existsFilter = ExistsFilter (FieldName "user")
479479-- topLeft and bottomRight
480480let box = GeoBoundingBox (LatLon 40.73 (-74.1)) (LatLon 40.10 (-71.12))
481481
482−let constraint = GeoBoundingBoxConstraint (FieldName "tweet.location") box False
483−
484−-- second argument is GeoFilterType, memory or indexed.
485−let geoFilter = GeoBoundingBoxFilter constraint GeoFilterMemory
482+let constraint = GeoBoundingBoxConstraint (FieldName "tweet.location") box False GeoFilterMemory
486483
487484#+END_SRC
488485
bloodhound.cabal+1−1
@@ -1,5 +1,5 @@
11name: bloodhound
2−version: 0.2.0.1
2+version: 0.3.0.0
33synopsis: ElasticSearch client library for Haskell
44description: ElasticSearch made awesome for Haskell hackers
55homepage: https://github.com/bitemyapp/bloodhound
tests/tests.hs+4−4
@@ -268,8 +268,8 @@ main = hspec $ do
268268 it "returns document for geo boundingbox filter" $ do
269269 _ <- insertData
270270 let box = GeoBoundingBox (LatLon 40.73 (-74.1)) (LatLon 40.10 (-71.12))
271− let bbConstraint = GeoBoundingBoxConstraint (FieldName "tweet.location") box False
272− let geoFilter = GeoBoundingBoxFilter bbConstraint GeoFilterMemory
271+ let bbConstraint = GeoBoundingBoxConstraint (FieldName "tweet.location") box False GeoFilterMemory
272+ let geoFilter = GeoBoundingBoxFilter bbConstraint
273273 let search = mkSearch Nothing (Just geoFilter)
274274 myTweet <- searchTweet search
275275 myTweet `shouldBe` Right exampleTweet
@@ -277,8 +277,8 @@ main = hspec $ do
277277 it "doesn't return document for nonsensical boundingbox filter" $ do
278278 _ <- insertData
279279 let box = GeoBoundingBox (LatLon 0.73 (-4.1)) (LatLon 0.10 (-1.12))
280− let bbConstraint = GeoBoundingBoxConstraint (FieldName "tweet.location") box False
281− let geoFilter = GeoBoundingBoxFilter bbConstraint GeoFilterMemory
280+ let bbConstraint = GeoBoundingBoxConstraint (FieldName "tweet.location") box False GeoFilterMemory
281+ let geoFilter = GeoBoundingBoxFilter bbConstraint
282282 let search = mkSearch Nothing (Just geoFilter)
283283 searchExpectNoResults search
284284