mirror of
https://github.com/typeable/bloodhound.git
synced 2025-01-07 15:22:21 +03:00
query documentation
This commit is contained in:
parent
1aea945f12
commit
102c04b09c
@ -376,6 +376,7 @@ data Search = Search { queryBody :: Maybe Query
|
||||
, from :: Int
|
||||
, size :: Int} deriving (Eq, Show)
|
||||
|
||||
mkSearch :: Maybe Query -> Maybe Filter -> Search
|
||||
mkSearch query filter = Search query filter Nothing False 0 10
|
||||
|
||||
pageSearch :: Int -> Int -> Search -> Search
|
||||
|
29
README.org
29
README.org
@ -23,7 +23,7 @@ Bloodhound is alpha at the moment. The library works fine, but I don't want to m
|
||||
|
||||
-- Formatted for use in ghci, so there are "let"s in front of the decls.
|
||||
|
||||
-- :set -XDeriveGeneric
|
||||
:set -XDeriveGeneric
|
||||
import Database.Bloodhound.Client
|
||||
import Data.Aeson
|
||||
import Data.Either (Either(..))
|
||||
@ -193,12 +193,39 @@ Right (EsResult {_index = "twitter", _type = "tweet", _id = "1", _version = 2, f
|
||||
|
||||
-- _source in EsResult is parametric, we dispatch the type by passing in what we expect (Tweet) as a parameter to EsResult.
|
||||
|
||||
-- use the _source record accessor to get at your document
|
||||
λ> fmap _source result
|
||||
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}})
|
||||
|
||||
#+END_SRC
|
||||
|
||||
** Search
|
||||
|
||||
*** Querying
|
||||
|
||||
**** Term Query
|
||||
|
||||
#+BEGIN_SRC haskell
|
||||
|
||||
-- exported by the Client module, just defaults some stuff.
|
||||
-- mkSearch :: Maybe Query -> Maybe Filter -> Search
|
||||
-- mkSearch query filter = Search query filter Nothing False 0 10
|
||||
|
||||
let query = TermQuery (Term "user" "bitemyapp") Nothing
|
||||
|
||||
-- AND'ing identity filter with itself and then tacking it onto a query
|
||||
-- search should be a null-operation. I include it for the sake of example.
|
||||
-- <||> (or/plus) should make it into a search that returns everything.
|
||||
|
||||
let filter = IdentityFilter <&&> IdentityFilter
|
||||
let search = mkSearch (Just query) (Just filter)
|
||||
reply <- searchByIndex testServer testIndex search
|
||||
let result = eitherDecode (responseBody reply) :: Either String (SearchResult Tweet)
|
||||
|
||||
λ> fmap (hits . searchHits) result
|
||||
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}}}]
|
||||
|
||||
#+END_SRC
|
||||
|
||||
*** Filtering
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user