@@ -25,10 +25,9 @@ import Data.Text (Text)
2525import Network.HTTP.Conduit
2626import qualified Network.HTTP.Types.Method as NHTM
2727import qualified Network.HTTP.Types.Status as NHTS
28−import Prelude hiding (head)
28+import Prelude hiding (head, filter)
2929
3030import Database.Bloodhound.Types
31−import Database.Bloodhound.Types.Class
3231import Database.Bloodhound.Types.Instances
3332
3433-- find way to avoid destructuring Servers and Indexes?
@@ -51,14 +50,15 @@ mkReplicaCount n
5150responseIsError :: Reply -> Bool
5251responseIsError resp = NHTS.statusCode (responseStatus resp) > 299
5352
53+emptyBody :: L.ByteString
5454emptyBody = L.pack ""
5555
5656dispatch :: Method -> String -> Maybe L.ByteString
5757 -> IO Reply
58−dispatch method url body = do
58+dispatch dMethod url body = do
5959 initReq <- parseUrl url
6060 let reqBody = RequestBodyLBS $ fromMaybe emptyBody body
61− let req = initReq { method = method
61+ let req = initReq { method = dMethod
6262 , requestBody = reqBody
6363 , checkStatus = \_ _ _ -> Nothing}
6464 withManager $ httpLbs req
@@ -66,10 +66,16 @@ dispatch method url body = do
6666joinPath :: [String] -> String
6767joinPath = intercalate "/"
6868
69+-- Shortcut functions for HTTP methods
70+delete :: String -> IO Reply
6971delete = flip (dispatch NHTM.methodDelete) $ Nothing
72+get :: String -> IO Reply
7073get = flip (dispatch NHTM.methodGet) $ Nothing
74+head :: String -> IO Reply
7175head = flip (dispatch NHTM.methodHead) $ Nothing
76+put :: String -> Maybe L.ByteString -> IO Reply
7277put = dispatch NHTM.methodPost
78+post :: String -> Maybe L.ByteString -> IO Reply
7379post = dispatch NHTM.methodPost
7480
7581-- indexDocument s ix name doc = put (root </> s </> ix </> name </> doc) (Just encode doc)
@@ -95,13 +101,14 @@ deleteIndex (Server server) (IndexName indexName) =
95101respIsTwoHunna :: Reply -> Bool
96102respIsTwoHunna resp = NHTS.statusCode (responseStatus resp) == 200
97103
104+existentialQuery :: String -> IO (Reply, Bool)
98105existentialQuery url = do
99106 reply <- head url
100107 return (reply, respIsTwoHunna reply)
101108
102109indexExists :: Server -> IndexName -> IO Bool
103110indexExists (Server server) (IndexName indexName) = do
104− (reply, exists) <- existentialQuery url
111+ (_, exists) <- existentialQuery url
105112 return exists
106113 where url = joinPath [server, indexName]
107114
@@ -110,6 +117,7 @@ refreshIndex (Server server) (IndexName indexName) =
110117 post url Nothing
111118 where url = joinPath [server, indexName, "_refresh"]
112119
120+stringifyOCIndex :: OpenCloseIndex -> String
113121stringifyOCIndex oci = case oci of
114122 OpenIndex -> "_open"
115123 CloseIndex -> "_close"
@@ -207,7 +215,7 @@ documentExists :: Server -> IndexName -> MappingName
207215 -> DocId -> IO Bool
208216documentExists (Server server) (IndexName indexName)
209217 (MappingName mappingName) (DocId docId) = do
210− (reply, exists) <- existentialQuery url
218+ (_, exists) <- existentialQuery url
211219 return exists where
212220 url = joinPath [server, indexName, mappingName, docId]
213221
@@ -231,4 +239,4 @@ mkSearch :: Maybe Query -> Maybe Filter -> Search
231239mkSearch query filter = Search query filter Nothing False 0 10
232240
233241pageSearch :: Int -> Int -> Search -> Search
234−pageSearch from size search = search { from = from, size = size }
242+pageSearch pageFrom pageSize search = search { from = pageFrom, size = pageSize }