mirror of
https://github.com/typeable/bloodhound.git
synced 2024-12-03 23:15:14 +03:00
limit change scanSearch to given index and mapping to better match existing search functionality; add tests
This commit is contained in:
parent
a4a15751a9
commit
fa9cff1ce8
@ -1,5 +1,5 @@
|
||||
name: bloodhound
|
||||
version: 0.7.1.1
|
||||
version: 0.7.2.0
|
||||
synopsis: ElasticSearch client library for Haskell
|
||||
description: ElasticSearch made awesome for Haskell hackers
|
||||
homepage: https://github.com/bitemyapp/bloodhound
|
||||
|
@ -543,9 +543,9 @@ searchByType (IndexName indexName)
|
||||
(MappingName mappingName) = bindM2 dispatchSearch url . return
|
||||
where url = joinPath [indexName, mappingName, "_search"]
|
||||
|
||||
scanSearch' :: MonadBH m => Search -> m (Maybe ScrollId)
|
||||
scanSearch' search = do
|
||||
let url = joinPath ["_search"]
|
||||
scanSearch' :: MonadBH m => IndexName -> MappingName -> Search -> m (Maybe ScrollId)
|
||||
scanSearch' (IndexName indexName) (MappingName mappingName) search = do
|
||||
let url = joinPath [indexName, mappingName, "_search"]
|
||||
search' = search { searchType = SearchTypeScan }
|
||||
resp' <- bindM2 dispatchSearch url (return search')
|
||||
let msr = decode' $ responseBody resp' :: Maybe (SearchResult ())
|
||||
@ -570,9 +570,11 @@ simpleAccumilator oldHits (newHits, msid) = do
|
||||
(newHits', msid') <- scroll' msid
|
||||
simpleAccumilator (oldHits ++ newHits) (newHits', msid')
|
||||
|
||||
scanSearch :: (FromJSON a, MonadBH m) => Search -> m [Hit a]
|
||||
scanSearch search = do
|
||||
msid <- scanSearch' search
|
||||
-- | 'scanSearch' uses the 'scan&scroll' API of elastic,
|
||||
-- for a given 'IndexName' and 'MappingName',
|
||||
scanSearch :: (FromJSON a, MonadBH m) => IndexName -> MappingName -> Search -> m [Hit a]
|
||||
scanSearch indexName mappingName search = do
|
||||
msid <- scanSearch' indexName mappingName search
|
||||
(hits, msid') <- scroll' msid
|
||||
(totalHits, _) <- simpleAccumilator [] (hits, msid')
|
||||
return totalHits
|
||||
|
@ -762,3 +762,16 @@ main = hspec $ do
|
||||
enumFrom (pred maxBound :: DocVersion) `shouldBe` [pred maxBound, maxBound]
|
||||
enumFrom (pred maxBound :: DocVersion) `shouldBe` [pred maxBound, maxBound]
|
||||
enumFromThen minBound (pred maxBound :: DocVersion) `shouldBe` [minBound, pred maxBound]
|
||||
|
||||
describe "scan&scroll API" $ do
|
||||
it "returns documents using the scan&scroll API" $ withTestEnv $ do
|
||||
_ <- insertData
|
||||
_ <- insertOther
|
||||
let search = (mkSearch (Just $ MatchAllQuery Nothing) Nothing) { size = (Size 1) }
|
||||
regular_search <- searchTweet search
|
||||
scan_search' <- scanSearch testIndex testMapping search :: BH IO [Hit Tweet]
|
||||
let scan_search = map hitSource scan_search'
|
||||
liftIO $
|
||||
regular_search `shouldBe` Right exampleTweet -- Check that the size restrtiction is being honored
|
||||
liftIO $
|
||||
scan_search `shouldMatchList` [exampleTweet, otherTweet]
|
||||
|
Loading…
Reference in New Issue
Block a user