git.iko.soy/typeable/bloodhound
on master help sign in
query documentation
102c04bChris Allen
Database/Bloodhound/Client.hs+1
@@ -376,6 +376,7 @@ data Search = Search { queryBody :: Maybe Query
376 , from :: Int
376 , from :: Int
377 , size :: Int} deriving (Eq, Show)
377 , size :: Int} deriving (Eq, Show)
378
378
379+mkSearch :: Maybe Query -> Maybe Filter -> Search
379mkSearch query filter = Search query filter Nothing False 0 10
380mkSearch query filter = Search query filter Nothing False 0 10
380
381
381pageSearch :: Int -> Int -> Search -> Search
382pageSearch :: Int -> Int -> Search -> Search
README.org+28−1
@@ -23,7 +23,7 @@ Bloodhound is alpha at the moment. The library works fine, but I don't want to m
23
23
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.
25
25
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
193
193
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.
195
195
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+
196#+END_SRC
200#+END_SRC
197
201
198** Search
202** Search
199
203
200*** Querying
204*** Querying
201
205
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
202
229
203*** Filtering
230*** Filtering
204
231