git.iko.soy/typeable/bloodhound
on master help sign in
trying to get named documentation chunk to render in the module description
commit3d2cb86cb4576f46bc4349996a345bd84f95c950 authorChris Allen <cma@bitemyapp.com> dateWed 10 Dec 2014, 17:09 (12 years ago) parentd87f734
4 files changed+58−30
Setup.hs+1−1 bloodhound.cabal−14 src/Database/Bloodhound/Client.hs+56−15 tests/tests.hs+1
Setup.hs+1−1
@@ -20,7 +20,7 @@ main = defaultMainWithHooks simpleUserHooks
2020 generateBuildModule (fromFlag (buildVerbosity flags)) pkg lbi
2121 buildHook simpleUserHooks pkg lbi hooks flags
2222 , postHaddock = \args flags pkg lbi -> do
23− copyFiles normal (haddockOutputDir flags pkg) [("images","Hierarchy.png")]
23+ -- copyFiles normal (haddockOutputDir flags pkg) [("images","Hierarchy.png")]
2424 postHaddock simpleUserHooks args flags pkg lbi
2525 }
2626
bloodhound.cabal−14
@@ -18,7 +18,6 @@ source-repository head
1818
1919library
2020 ghc-options: -Wall
21− default-extensions: OverloadedStrings
2221 exposed-modules: Database.Bloodhound
2322 Database.Bloodhound.Client
2423 Database.Bloodhound.Types
@@ -39,7 +38,6 @@ library
3938
4039test-suite tests
4140 ghc-options: -Wall
42− default-extensions: OverloadedStrings
4341 type: exitcode-stdio-1.0
4442 main-is: tests.hs
4543 hs-source-dirs: tests
@@ -60,7 +58,6 @@ test-suite tests
6058
6159test-suite doctests
6260 default-language: Haskell2010
63− default-extensions: OverloadedStrings
6461 type: exitcode-stdio-1.0
6562 main-is: doctests.hs
6663 hs-source-dirs: tests
@@ -69,14 +66,3 @@ test-suite doctests
6966 doctest-prop,
7067 directory,
7168 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 @@
22
33-------------------------------------------------------------------------------
44-- |
5−-- Module : Database.Bloodhound.Types
5+-- Module : Database.Bloodhound.Client
66-- Copyright : (C) 2014 Chris Allen
77-- License : BSD-style (see the file LICENSE)
88-- Maintainer : Chris Allen <cma@bitemyapp.com
99-- Stability : provisional
10−-- Portability : DeriveGeneric, RecordWildCards
10+-- Portability : OverloadedStrings
11+--
12+-- Client side functions for talking to Elasticsearch servers.
13+--
14+-- $setup
1115--
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.
1816-------------------------------------------------------------------------------
1917
2018module Database.Bloodhound.Client
21− ( createIndex
19+ (
20+ -- module Database.Bloodhound.Client
21+ createIndex
2222 , deleteIndex
2323 , indexExists
2424 , openIndex
@@ -68,10 +68,18 @@ import Database.Bloodhound.Types
6868-- >>> let testIndex = IndexName "twitter"
6969-- >>> let testMapping = MappingName "tweet"
7070-- >>> let defaultIndexSettings = IndexSettings (ShardCount 3) (ReplicaCount 2)
71+-- >>> data TweetMapping = TweetMapping deriving (Eq, Show)
7172-- >>> _ <- 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+-- :}
7282
73−-- no trailing slashes in servers, library handles building the path.
74−-- defaultIndexSettings is exported by Database.Bloodhound as well
7583
7684mkShardCount :: Int -> Maybe ShardCount
7785mkShardCount n
@@ -125,15 +133,27 @@ getStatus (Server server) = do
125133
126134-- | createIndex will create an index given a 'Server',
127135-- 'IndexSettings', and an 'IndexName'
128−-- >>> response <- createIndex testServer defaultIndexSettings testIndex
136+--
137+-- >>> response <- createIndex testServer defaultIndexSettings (IndexName "didimakeanindex")
129138-- >>> respIsTwoHunna response
130139-- True
140+-- >>> indexExists testServer (IndexName "didimakeanindex")
141+-- True
131142createIndex :: Server -> IndexSettings -> IndexName -> IO Reply
132143createIndex (Server server) indexSettings (IndexName indexName) =
133144 put url body
134145 where url = joinPath [server, indexName]
135146 body = Just $ encode indexSettings
136147
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
137157deleteIndex :: Server -> IndexName -> IO Reply
138158deleteIndex (Server server) (IndexName indexName) =
139159 delete $ joinPath [server, indexName]
@@ -152,6 +172,13 @@ indexExists (Server server) (IndexName indexName) = do
152172 return exists
153173 where url = joinPath [server, indexName]
154174
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
155182refreshIndex :: Server -> IndexName -> IO Reply
156183refreshIndex (Server server) (IndexName indexName) =
157184 post url Nothing
@@ -174,9 +201,13 @@ openIndex = openOrCloseIndexes OpenIndex
174201closeIndex :: Server -> IndexName -> IO Reply
175202closeIndex = openOrCloseIndexes CloseIndex
176203
177−{-| putMapping is an HTTP PUT and has upsert semantics. Mappings are schemas
178− for documents in indexes.
179−-}
204+-- | 'putMapping' is an HTTP PUT and has upsert semantics. Mappings are schemas
205+-- for documents in indexes.
206+--
207+-- >>> response <- createIndex testServer defaultIndexSettings testIndex
208+-- >>> resp <- putMapping testServer testIndex testMapping TweetMapping
209+-- >>> respIsTwoHunna resp
210+-- True
180211putMapping :: ToJSON a => Server -> IndexName
181212 -> MappingName -> a -> IO Reply
182213putMapping (Server server) (IndexName indexName) (MappingName mappingName) mapping =
@@ -184,6 +215,16 @@ putMapping (Server server) (IndexName indexName) (MappingName mappingName) mappi
184215 where url = joinPath [server, indexName, mappingName, "_mapping"]
185216 body = Just $ encode mapping
186217
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
187228deleteMapping :: Server -> IndexName -> MappingName -> IO Reply
188229deleteMapping (Server server) (IndexName indexName)
189230 (MappingName mappingName) =
tests/tests.hs+1
@@ -1,4 +1,5 @@
11{-# LANGUAGE DeriveGeneric #-}
2+{-# LANGUAGE OverloadedStrings #-}
23{-# LANGUAGE ScopedTypeVariables #-}
34
45module Main where