git.iko.soy/typeable/bloodhound
on master help sign in
limit change scanSearch to given index and mapping to better match existing search functionality; add tests
fa9cff1Josh Berman
bloodhound.cabal+1−1
@@ -1,5 +1,5 @@
1name: bloodhound
1name: bloodhound
2−version: 0.7.1.1
2+version: 0.7.2.0
3synopsis: ElasticSearch client library for Haskell
3synopsis: ElasticSearch client library for Haskell
4description: ElasticSearch made awesome for Haskell hackers
4description: ElasticSearch made awesome for Haskell hackers
5homepage: https://github.com/bitemyapp/bloodhound
5homepage: https://github.com/bitemyapp/bloodhound
src/Database/Bloodhound/Client.hs+8−6
@@ -543,9 +543,9 @@ searchByType (IndexName indexName)
543 (MappingName mappingName) = bindM2 dispatchSearch url . return
543 (MappingName mappingName) = bindM2 dispatchSearch url . return
544 where url = joinPath [indexName, mappingName, "_search"]
544 where url = joinPath [indexName, mappingName, "_search"]
545
545
546−scanSearch' :: MonadBH m => Search -> m (Maybe ScrollId)
546+scanSearch' :: MonadBH m => IndexName -> MappingName -> Search -> m (Maybe ScrollId)
547−scanSearch' search = do
547+scanSearch' (IndexName indexName) (MappingName mappingName) search = do
548− let url = joinPath ["_search"]
548+ let url = joinPath [indexName, mappingName, "_search"]
549 search' = search { searchType = SearchTypeScan }
549 search' = search { searchType = SearchTypeScan }
550 resp' <- bindM2 dispatchSearch url (return search')
550 resp' <- bindM2 dispatchSearch url (return search')
551 let msr = decode' $ responseBody resp' :: Maybe (SearchResult ())
551 let msr = decode' $ responseBody resp' :: Maybe (SearchResult ())
@@ -570,9 +570,11 @@ simpleAccumilator oldHits (newHits, msid) = do
570 (newHits', msid') <- scroll' msid
570 (newHits', msid') <- scroll' msid
571 simpleAccumilator (oldHits ++ newHits) (newHits', msid')
571 simpleAccumilator (oldHits ++ newHits) (newHits', msid')
572
572
573+-- | 'scanSearch' uses the 'scan&scroll' API of elastic,
574+-- for a given 'IndexName' and 'MappingName',
573−scanSearch :: (FromJSON a, MonadBH m) => Search -> m [Hit a]
575+scanSearch :: (FromJSON a, MonadBH m) => IndexName -> MappingName -> Search -> m [Hit a]
574−scanSearch search = do
576+scanSearch indexName mappingName search = do
575− msid <- scanSearch' search
577+ msid <- scanSearch' indexName mappingName search
576 (hits, msid') <- scroll' msid
578 (hits, msid') <- scroll' msid
577 (totalHits, _) <- simpleAccumilator [] (hits, msid')
579 (totalHits, _) <- simpleAccumilator [] (hits, msid')
578 return totalHits
580 return totalHits
tests/tests.hs+13
@@ -762,3 +762,16 @@ main = hspec $ do
762 enumFrom (pred maxBound :: DocVersion) `shouldBe` [pred maxBound, maxBound]
762 enumFrom (pred maxBound :: DocVersion) `shouldBe` [pred maxBound, maxBound]
763 enumFrom (pred maxBound :: DocVersion) `shouldBe` [pred maxBound, maxBound]
763 enumFrom (pred maxBound :: DocVersion) `shouldBe` [pred maxBound, maxBound]
764 enumFromThen minBound (pred maxBound :: DocVersion) `shouldBe` [minBound, pred maxBound]
764 enumFromThen minBound (pred maxBound :: DocVersion) `shouldBe` [minBound, pred maxBound]
765+
766+ describe "scan&scroll API" $ do
767+ it "returns documents using the scan&scroll API" $ withTestEnv $ do
768+ _ <- insertData
769+ _ <- insertOther
770+ let search = (mkSearch (Just $ MatchAllQuery Nothing) Nothing) { size = (Size 1) }
771+ regular_search <- searchTweet search
772+ scan_search' <- scanSearch testIndex testMapping search :: BH IO [Hit Tweet]
773+ let scan_search = map hitSource scan_search'
774+ liftIO $
775+ regular_search `shouldBe` Right exampleTweet -- Check that the size restrtiction is being honored
776+ liftIO $
777+ scan_search `shouldMatchList` [exampleTweet, otherTweet]