git.iko.soy/typeable/bloodhound
on master help sign in
Merge remote-tracking branch 'upstream/master' into source-in-search
dfa897dThomas van Noort
.travis.yml+13−24
@@ -7,14 +7,14 @@
7# release of a major GHC version. Setting HPVER implictly sets
7# release of a major GHC version. Setting HPVER implictly sets
8# GHCVER. Omit lines with versions you don't need/want testing for.
8# GHCVER. Omit lines with versions you don't need/want testing for.
9env:
9env:
10− - GHCVER=7.6.3 ESVER=1.6.0
10+ # - GHCVER=7.6.3 ESVER=1.6.0 # Deprecated
11 # - GHCVER=7.8.3 ESVER=1.0.3 # Deprecated
11 # - GHCVER=7.8.3 ESVER=1.0.3 # Deprecated
12 # - GHCVER=7.8.3 ESVER=1.1.2 # Deprecated
12 # - GHCVER=7.8.3 ESVER=1.1.2 # Deprecated
13− - GHCVER=7.8.3 ESVER=1.2.4
13+ - GHCVER=7.8 ESVER=1.2.4
14− - GHCVER=7.8.3 ESVER=1.3.6
14+ - GHCVER=7.8 ESVER=1.3.6
15− - GHCVER=7.8.3 ESVER=1.4.1
15+ - GHCVER=7.8 ESVER=1.4.1
16− - GHCVER=7.10.1 ESVER=1.5.2
16+ - GHCVER=7.10 ESVER=1.5.2
17− - GHCVER=7.10.1 ESVER=1.6.0
17+ - GHCVER=7.10 ESVER=1.6.0
18
18
19# services:
19# services:
20# - elasticsearch
20# - elasticsearch
@@ -22,34 +22,23 @@ env:
22# Note: the distinction between `before_install` and `install` is not
22# Note: the distinction between `before_install` and `install` is not
23# important.
23# important.
24before_install:
24before_install:
25− - sudo add-apt-repository -y ppa:hvr/ghc
25+ - export STACK_YAML=stack-$GHCVER.yaml
26+ - wget -q -O- https://s3.amazonaws.com/download.fpcomplete.com/ubuntu/fpco.key | sudo apt-key add -
27+ - echo 'deb http://download.fpcomplete.com/ubuntu/precise stable main' | sudo tee /etc/apt/sources.list.d/fpco.list
26 - sudo apt-get update
28 - sudo apt-get update
27− - sudo apt-get install cabal-install-1.20 ghc-$GHCVER
29+ - sudo apt-get install stack -y
28− - sudo apt-get install happy-1.19.3
30+ - stack setup
29− - export PATH=/opt/ghc/$GHCVER/bin:/opt/happy/1.19.3/bin:$PATH
30 - wget --no-check-certificate https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-$ESVER.deb
31 - wget --no-check-certificate https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-$ESVER.deb
31 - sudo dpkg --force-all -i elasticsearch-$ESVER.deb
32 - sudo dpkg --force-all -i elasticsearch-$ESVER.deb
32 - sudo service elasticsearch start
33 - sudo service elasticsearch start
33
34
34install:
35install:
35− - cabal-1.20 update
36+ - stack build
36− - cabal-1.20 install --only-dependencies --enable-tests --enable-benchmarks --force-reinstalls
37
37
38# Here starts the actual work to be performed for the package under
38# Here starts the actual work to be performed for the package under
39# test; any command which exits with a non-zero exit code causes the
39# test; any command which exits with a non-zero exit code causes the
40# build to fail.
40# build to fail.
41script:
41script:
42− # -v2 provides useful information for debugging
42+ - stack test
43− - cabal-1.20 configure --enable-tests --enable-benchmarks -v2
44−
45− # this builds all libraries and executables
46− # (including tests/benchmarks)
47− - cabal-1.20 build
48−
49− - cabal-1.20 test
50− - cabal-1.20 check
51−
52− # tests that a source-distribution can be generated
53− - cabal-1.20 sdist
54
43
55# EOF
44# EOF
bloodhound.cabal+1−1
@@ -1,5 +1,5 @@
1name: bloodhound
1name: bloodhound
2−version: 0.7.1.0
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+17−15
@@ -173,16 +173,16 @@ joinPath ps = do
173 return $ joinPath' (s:ps)
173 return $ joinPath' (s:ps)
174
174
175appendSearchTypeParam :: Text -> SearchType -> Text
175appendSearchTypeParam :: Text -> SearchType -> Text
176−appendSearchTypeParam originalUrl st = addQuery [(keyEq, Just stParams)] originalUrl
176+appendSearchTypeParam originalUrl st = addQuery params originalUrl
177− where keyEq = "search_type="
177+ where stText = "search_type"
178− stParams
178+ params
179− | st == SearchTypeDfsQueryThenFetch = "dfs_query_then_fetch"
179+ | st == SearchTypeDfsQueryThenFetch = [(stText, Just "dfs_query_then_fetch")]
180− | st == SearchTypeCount = "count"
180+ | st == SearchTypeCount = [(stText, Just "count")]
181− | st == SearchTypeScan = "scan&scroll=1m"
181+ | st == SearchTypeScan = [(stText, Just "scan"), ("scroll", Just "1m")]
182− | st == SearchTypeQueryAndFetch = "query_and_fetch"
182+ | st == SearchTypeQueryAndFetch = [(stText, Just "query_and_fetch")]
183− | st == SearchTypeDfsQueryAndFetch = "dfs_query_and_fetch"
183+ | st == SearchTypeDfsQueryAndFetch = [(stText, Just "dfs_query_and_fetch")]
184 -- used to catch 'SearchTypeQueryThenFetch', which is also the default
184 -- used to catch 'SearchTypeQueryThenFetch', which is also the default
185− | otherwise = "query_then_fetch"
185+ | otherwise = [(stText, Just "query_then_fetch")]
186
186
187-- | Severely dumbed down query renderer. Assumes your data doesn't
187-- | Severely dumbed down query renderer. Assumes your data doesn't
188-- need any encoding
188-- need any encoding
@@ -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
src/Database/Bloodhound/Types.hs+1−1
@@ -47,7 +47,7 @@ module Database.Bloodhound.Types
47 , toTerms
47 , toTerms
48 , toDateHistogram
48 , toDateHistogram
49 , omitNulls
49 , omitNulls
50− , BH
50+ , BH(..)
51 , runBH
51 , runBH
52 , BHEnv(..)
52 , BHEnv(..)
53 , MonadBH(..)
53 , MonadBH(..)
stack-7.10.yamlnew file+9
@@ -0,0 +1,9 @@
1+flags: {}
2+packages:
3+- '.'
4+extra-deps:
5+- doctest-0.10.1
6+- doctest-prop-0.2.0.1
7+- quickcheck-properties-0.1
8+- uri-bytestring-0.1.2
9+resolver: lts-3.1
stack-7.8.yamlnew file+1
@@ -0,0 +1 @@
1+stack.yaml
tests/tests.hs+13
@@ -798,3 +798,16 @@ main = hspec $ do
798 enumFrom (pred maxBound :: DocVersion) `shouldBe` [pred maxBound, maxBound]
798 enumFrom (pred maxBound :: DocVersion) `shouldBe` [pred maxBound, maxBound]
799 enumFrom (pred maxBound :: DocVersion) `shouldBe` [pred maxBound, maxBound]
799 enumFrom (pred maxBound :: DocVersion) `shouldBe` [pred maxBound, maxBound]
800 enumFromThen minBound (pred maxBound :: DocVersion) `shouldBe` [minBound, pred maxBound]
800 enumFromThen minBound (pred maxBound :: DocVersion) `shouldBe` [minBound, pred maxBound]
801+
802+ describe "scan&scroll API" $ do
803+ it "returns documents using the scan&scroll API" $ withTestEnv $ do
804+ _ <- insertData
805+ _ <- insertOther
806+ let search = (mkSearch (Just $ MatchAllQuery Nothing) Nothing) { size = (Size 1) }
807+ regular_search <- searchTweet search
808+ scan_search' <- scanSearch testIndex testMapping search :: BH IO [Hit Tweet]
809+ let scan_search = map hitSource scan_search'
810+ liftIO $
811+ regular_search `shouldBe` Right exampleTweet -- Check that the size restrtiction is being honored
812+ liftIO $
813+ scan_search `shouldMatchList` [exampleTweet, otherTweet]