@@ -23,7 +23,7 @@ Bloodhound is alpha at the moment. The library works fine, but I don't want to m
2323
2424-- Formatted for use in ghci, so there are "let"s in front of the decls.
2525
26−-- :set -XDeriveGeneric
26+:set -XDeriveGeneric
2727import Database.Bloodhound.Client
2828import Data.Aeson
2929import Data.Either (Either(..))
@@ -193,12 +193,39 @@ Right (EsResult {_index = "twitter", _type = "tweet", _id = "1", _version = 2, f
193193
194194-- _source in EsResult is parametric, we dispatch the type by passing in what we expect (Tweet) as a parameter to EsResult.
195195
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}})
199+
196200#+END_SRC
197201
198202** Search
199203
200204*** Querying
201205
206+**** Term Query
207+
208+#+BEGIN_SRC haskell
209+
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
213+
214+let query = TermQuery (Term "user" "bitemyapp") Nothing
215+
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.
219+
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)
224+
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}}}]
227+
228+#+END_SRC
202229
203230*** Filtering
204231