@@ -23,7 +23,7 @@ Bloodhound is alpha at the moment. The library works fine, but I don't want to m
24-- Formatted for use in ghci, so there are "let"s in front of the decls.
24-- Formatted for use in ghci, so there are "let"s in front of the decls.
26−-- :set -XDeriveGeneric
26+:set -XDeriveGeneric
27import Database.Bloodhound.Client
27import Database.Bloodhound.Client
28import Data.Aeson
28import Data.Aeson
29import Data.Either (Either(..))
29import Data.Either (Either(..))
@@ -193,12 +193,39 @@ Right (EsResult {_index = "twitter", _type = "tweet", _id = "1", _version = 2, f
194-- _source in EsResult is parametric, we dispatch the type by passing in what we expect (Tweet) as a parameter to EsResult.
194-- _source in EsResult is parametric, we dispatch the type by passing in what we expect (Tweet) as a parameter to EsResult.
196+-- use the _source record accessor to get at your document
197+λ> fmap _source result
198+Right (Tweet {user = "bitemyapp", postDate = 2009-06-18 00:00:10 UTC, message = "Use haskell!", age = 10000, location = Location {lat = 40.12, lon = -71.34}})
200*** Querying
204*** Querying
210+-- exported by the Client module, just defaults some stuff.
211+-- mkSearch :: Maybe Query -> Maybe Filter -> Search
212+-- mkSearch query filter = Search query filter Nothing False 0 10
214+let query = TermQuery (Term "user" "bitemyapp") Nothing
216+-- AND'ing identity filter with itself and then tacking it onto a query
217+-- search should be a null-operation. I include it for the sake of example.
218+-- <||> (or/plus) should make it into a search that returns everything.
220+let filter = IdentityFilter <&&> IdentityFilter
221+let search = mkSearch (Just query) (Just filter)
222+reply <- searchByIndex testServer testIndex search
223+let result = eitherDecode (responseBody reply) :: Either String (SearchResult Tweet)
225+λ> fmap (hits . searchHits) result
226+Right [Hit {hitIndex = IndexName "twitter", hitType = MappingName "tweet", hitDocId = DocId "1", hitScore = 0.30685282, hitSource = Tweet {user = "bitemyapp", postDate = 2009-06-18 00:00:10 UTC, message = "Use haskell!", age = 10000, location = Location {lat = 40.12, lon = -71.34}}}]
203*** Filtering
230*** Filtering