git.iko.soy/typeable/bloodhound
on master help sign in
trying to get named documentation chunk to render in the module description
3d2cb86Chris Allen
Setup.hs+1−1
@@ -20,7 +20,7 @@ main = defaultMainWithHooks simpleUserHooks
20 generateBuildModule (fromFlag (buildVerbosity flags)) pkg lbi
20 generateBuildModule (fromFlag (buildVerbosity flags)) pkg lbi
21 buildHook simpleUserHooks pkg lbi hooks flags
21 buildHook simpleUserHooks pkg lbi hooks flags
22 , postHaddock = \args flags pkg lbi -> do
22 , postHaddock = \args flags pkg lbi -> do
23− copyFiles normal (haddockOutputDir flags pkg) [("images","Hierarchy.png")]
23+ -- copyFiles normal (haddockOutputDir flags pkg) [("images","Hierarchy.png")]
24 postHaddock simpleUserHooks args flags pkg lbi
24 postHaddock simpleUserHooks args flags pkg lbi
25 }
25 }
26
26
bloodhound.cabal−14
@@ -18,7 +18,6 @@ source-repository head
18
18
19library
19library
20 ghc-options: -Wall
20 ghc-options: -Wall
21− default-extensions: OverloadedStrings
22 exposed-modules: Database.Bloodhound
21 exposed-modules: Database.Bloodhound
23 Database.Bloodhound.Client
22 Database.Bloodhound.Client
24 Database.Bloodhound.Types
23 Database.Bloodhound.Types
@@ -39,7 +38,6 @@ library
39
38
40test-suite tests
39test-suite tests
41 ghc-options: -Wall
40 ghc-options: -Wall
42− default-extensions: OverloadedStrings
43 type: exitcode-stdio-1.0
41 type: exitcode-stdio-1.0
44 main-is: tests.hs
42 main-is: tests.hs
45 hs-source-dirs: tests
43 hs-source-dirs: tests
@@ -60,7 +58,6 @@ test-suite tests
60
58
61test-suite doctests
59test-suite doctests
62 default-language: Haskell2010
60 default-language: Haskell2010
63− default-extensions: OverloadedStrings
64 type: exitcode-stdio-1.0
61 type: exitcode-stdio-1.0
65 main-is: doctests.hs
62 main-is: doctests.hs
66 hs-source-dirs: tests
63 hs-source-dirs: tests
@@ -69,14 +66,3 @@ test-suite doctests
69 doctest-prop,
66 doctest-prop,
70 directory,
67 directory,
71 filepath
68 filepath
72−
73−-- test-suite doctests
74−-- type: exitcode-stdio-1.0
75−-- ghc-options: -threaded
76−-- main-is: doctest-driver.hs
77−-- hs-source-dirs: tests
78−-- build-depends: base >4 && <5
79−-- , doctest
80−-- , doctest-discover
81−-- , doctest-prop
82−-- default-language: Haskell2010
src/Database/Bloodhound/Client.hs+56−15
@@ -2,23 +2,23 @@
2
2
3-------------------------------------------------------------------------------
3-------------------------------------------------------------------------------
4-- |
4-- |
5−-- Module : Database.Bloodhound.Types
5+-- Module : Database.Bloodhound.Client
6-- Copyright : (C) 2014 Chris Allen
6-- Copyright : (C) 2014 Chris Allen
7-- License : BSD-style (see the file LICENSE)
7-- License : BSD-style (see the file LICENSE)
8-- Maintainer : Chris Allen <cma@bitemyapp.com
8-- Maintainer : Chris Allen <cma@bitemyapp.com
9-- Stability : provisional
9-- Stability : provisional
10−-- Portability : DeriveGeneric, RecordWildCards
10+-- Portability : OverloadedStrings
11+--
12+-- Client side functions for talking to Elasticsearch servers.
13+--
14+-- $setup
11--
15--
12−-- Data types for describing actions and data structures performed to interact
13−-- with Elasticsearch. The two main buckets your queries against Elasticsearch
14−-- will fall into are 'Query's and 'Filter's. 'Filter's are more like
15−-- traditional database constraints and often have preferable performance
16−-- properties. 'Query's support human-written textual queries, such as fuzzy
17−-- queries.
18-------------------------------------------------------------------------------
16-------------------------------------------------------------------------------
19
17
20module Database.Bloodhound.Client
18module Database.Bloodhound.Client
19+ (
20+ -- module Database.Bloodhound.Client
21− ( createIndex
21+ createIndex
22 , deleteIndex
22 , deleteIndex
23 , indexExists
23 , indexExists
24 , openIndex
24 , openIndex
@@ -68,10 +68,18 @@ import Database.Bloodhound.Types
68-- >>> let testIndex = IndexName "twitter"
68-- >>> let testIndex = IndexName "twitter"
69-- >>> let testMapping = MappingName "tweet"
69-- >>> let testMapping = MappingName "tweet"
70-- >>> let defaultIndexSettings = IndexSettings (ShardCount 3) (ReplicaCount 2)
70-- >>> let defaultIndexSettings = IndexSettings (ShardCount 3) (ReplicaCount 2)
71+-- >>> data TweetMapping = TweetMapping deriving (Eq, Show)
71-- >>> _ <- deleteIndex testServer testIndex
72-- >>> _ <- deleteIndex testServer testIndex
73+-- >>> _ <- deleteMapping testServer testIndex testMapping
74+-- >>> :{
75+--instance ToJSON TweetMapping where
76+-- toJSON TweetMapping =
77+-- object ["tweet" .=
78+-- object ["properties" .=
79+-- object ["location" .=
80+-- object ["type" .= ("geo_point" :: Text)]]]]
81+-- :}
72
82
73−-- no trailing slashes in servers, library handles building the path.
74−-- defaultIndexSettings is exported by Database.Bloodhound as well
75
83
76mkShardCount :: Int -> Maybe ShardCount
84mkShardCount :: Int -> Maybe ShardCount
77mkShardCount n
85mkShardCount n
@@ -125,15 +133,27 @@ getStatus (Server server) = do
125
133
126-- | createIndex will create an index given a 'Server',
134-- | createIndex will create an index given a 'Server',
127-- 'IndexSettings', and an 'IndexName'
135-- 'IndexSettings', and an 'IndexName'
136+--
128−-- >>> response <- createIndex testServer defaultIndexSettings testIndex
137+-- >>> response <- createIndex testServer defaultIndexSettings (IndexName "didimakeanindex")
129-- >>> respIsTwoHunna response
138-- >>> respIsTwoHunna response
130-- True
139-- True
140+-- >>> indexExists testServer (IndexName "didimakeanindex")
141+-- True
131createIndex :: Server -> IndexSettings -> IndexName -> IO Reply
142createIndex :: Server -> IndexSettings -> IndexName -> IO Reply
132createIndex (Server server) indexSettings (IndexName indexName) =
143createIndex (Server server) indexSettings (IndexName indexName) =
133 put url body
144 put url body
134 where url = joinPath [server, indexName]
145 where url = joinPath [server, indexName]
135 body = Just $ encode indexSettings
146 body = Just $ encode indexSettings
136
147
148+-- | deleteIndex will delete an index given a 'Server',
149+-- and an 'IndexName'
150+--
151+-- >>> response <- createIndex testServer defaultIndexSettings (IndexName "didimakeanindex")
152+-- >>> response <- deleteIndex testServer (IndexName "didimakeanindex")
153+-- >>> respIsTwoHunna response
154+-- True
155+-- >>> indexExists testServer testIndex
156+-- False
137deleteIndex :: Server -> IndexName -> IO Reply
157deleteIndex :: Server -> IndexName -> IO Reply
138deleteIndex (Server server) (IndexName indexName) =
158deleteIndex (Server server) (IndexName indexName) =
139 delete $ joinPath [server, indexName]
159 delete $ joinPath [server, indexName]
@@ -152,6 +172,13 @@ indexExists (Server server) (IndexName indexName) = do
152 return exists
172 return exists
153 where url = joinPath [server, indexName]
173 where url = joinPath [server, indexName]
154
174
175+-- | 'refreshIndex' will force a refresh on an index. You must
176+-- do this if you want to read what you wrote.
177+--
178+-- >>> response <- createIndex testServer defaultIndexSettings testIndex
179+-- >>> response <- refreshIndex testServer testIndex
180+-- >>> respIsTwoHunna response
181+-- True
155refreshIndex :: Server -> IndexName -> IO Reply
182refreshIndex :: Server -> IndexName -> IO Reply
156refreshIndex (Server server) (IndexName indexName) =
183refreshIndex (Server server) (IndexName indexName) =
157 post url Nothing
184 post url Nothing
@@ -174,9 +201,13 @@ openIndex = openOrCloseIndexes OpenIndex
174closeIndex :: Server -> IndexName -> IO Reply
201closeIndex :: Server -> IndexName -> IO Reply
175closeIndex = openOrCloseIndexes CloseIndex
202closeIndex = openOrCloseIndexes CloseIndex
176
203
177−{-| putMapping is an HTTP PUT and has upsert semantics. Mappings are schemas
204+-- | 'putMapping' is an HTTP PUT and has upsert semantics. Mappings are schemas
178− for documents in indexes.
205+-- for documents in indexes.
179−-}
206+--
207+-- >>> response <- createIndex testServer defaultIndexSettings testIndex
208+-- >>> resp <- putMapping testServer testIndex testMapping TweetMapping
209+-- >>> respIsTwoHunna resp
210+-- True
180putMapping :: ToJSON a => Server -> IndexName
211putMapping :: ToJSON a => Server -> IndexName
181 -> MappingName -> a -> IO Reply
212 -> MappingName -> a -> IO Reply
182putMapping (Server server) (IndexName indexName) (MappingName mappingName) mapping =
213putMapping (Server server) (IndexName indexName) (MappingName mappingName) mapping =
@@ -184,6 +215,16 @@ putMapping (Server server) (IndexName indexName) (MappingName mappingName) mappi
184 where url = joinPath [server, indexName, mappingName, "_mapping"]
215 where url = joinPath [server, indexName, mappingName, "_mapping"]
185 body = Just $ encode mapping
216 body = Just $ encode mapping
186
217
218+-- | 'deleteMapping' is an HTTP DELETE and deletes a mapping for a given index.
219+-- Mappings are schemas for documents in indexes.
220+--
221+-- >>> response <- createIndex testServer defaultIndexSettings testIndex
222+-- >>> resp <- putMapping testServer testIndex testMapping TweetMapping
223+-- >>> respIsTwoHunna resp
224+-- True
225+-- >>> resp <- deleteMapping testServer testIndex testMapping
226+-- >>> respIsTwoHunna resp
227+-- True
187deleteMapping :: Server -> IndexName -> MappingName -> IO Reply
228deleteMapping :: Server -> IndexName -> MappingName -> IO Reply
188deleteMapping (Server server) (IndexName indexName)
229deleteMapping (Server server) (IndexName indexName)
189 (MappingName mappingName) =
230 (MappingName mappingName) =
tests/tests.hs+1
@@ -1,4 +1,5 @@
1{-# LANGUAGE DeriveGeneric #-}
1{-# LANGUAGE DeriveGeneric #-}
2+{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE ScopedTypeVariables #-}
3
4
4module Main where
5module Main where