git.iko.soy/typeable/bloodhound
on master help sign in
docs, formatting, renamed createMapping
2fffe35Chris Allen
.gitignore+2
@@ -6,3 +6,5 @@ dist/
6.DS_Store
6.DS_Store
7*.hi
7*.hi
8*.o
8*.o
9+bloodhound-*-docs/
10+bloodhound-*-docs.tar.gz
Database/Bloodhound/Client.hs+6−2
@@ -138,9 +138,12 @@ openIndex = openOrCloseIndexes OpenIndex
138closeIndex :: Server -> IndexName -> IO Reply
138closeIndex :: Server -> IndexName -> IO Reply
139closeIndex = openOrCloseIndexes CloseIndex
139closeIndex = openOrCloseIndexes CloseIndex
140
140
141+{-| putMapping is an HTTP PUT and has upsert semantics. Mappings are schemas
142+ for documents in indexes.
143+-}
141−createMapping :: ToJSON a => Server -> IndexName
144+putMapping :: ToJSON a => Server -> IndexName
142 -> MappingName -> a -> IO Reply
145 -> MappingName -> a -> IO Reply
143−createMapping (Server server) (IndexName indexName) (MappingName mappingName) mapping =
146+putMapping (Server server) (IndexName indexName) (MappingName mappingName) mapping =
144 put url body
147 put url body
145 where url = joinPath [server, indexName, mappingName, "_mapping"]
148 where url = joinPath [server, indexName, mappingName, "_mapping"]
146 body = Just $ encode mapping
149 body = Just $ encode mapping
@@ -149,6 +152,7 @@ deleteMapping :: Server -> IndexName -> MappingName -> IO Reply
149deleteMapping (Server server) (IndexName indexName)
152deleteMapping (Server server) (IndexName indexName)
150 (MappingName mappingName) =
153 (MappingName mappingName) =
151 delete $ joinPath [server, indexName, mappingName, "_mapping"]
154 delete $ joinPath [server, indexName, mappingName, "_mapping"]
155+
152indexDocument :: ToJSON doc => Server -> IndexName -> MappingName
156indexDocument :: ToJSON doc => Server -> IndexName -> MappingName
153 -> doc -> DocId -> IO Reply
157 -> doc -> DocId -> IO Reply
154indexDocument (Server server) (IndexName indexName)
158indexDocument (Server server) (IndexName indexName)
Database/Bloodhound/Types.hs+5−1
@@ -186,7 +186,7 @@ data IndexSettings =
186defaultIndexSettings :: IndexSettings
186defaultIndexSettings :: IndexSettings
187defaultIndexSettings = IndexSettings (ShardCount 3) (ReplicaCount 2)
187defaultIndexSettings = IndexSettings (ShardCount 3) (ReplicaCount 2)
188
188
189−{-| 'Reply' and 'Method' are type synonyms from 'Network.HTTP.Types.Method' -}
189+{-| 'Reply' and 'Method' are type synonyms from 'Network.HTTP.Types.Method.Method' -}
190type Reply = Network.HTTP.Client.Response L.ByteString
190type Reply = Network.HTTP.Client.Response L.ByteString
191type Method = NHTM.Method
191type Method = NHTM.Method
192
192
@@ -213,6 +213,10 @@ data MappingField =
213
213
214{-| Support for type reification of 'Mapping's is currently incomplete, for
214{-| Support for type reification of 'Mapping's is currently incomplete, for
215 now the mapping API verbiage expects a 'ToJSON'able blob.
215 now the mapping API verbiage expects a 'ToJSON'able blob.
216+
217+ Indexes have mappings, mappings are schemas for the documents contained in the
218+ index. I'd recommend having only one mapping per index, always having a mapping,
219+ and keeping different kinds of documents separated if possible.
216-}
220-}
217data Mapping = Mapping { typeName :: TypeName
221data Mapping = Mapping { typeName :: TypeName
218 , mappingFields :: [MappingField] } deriving (Eq, Show)
222 , mappingFields :: [MappingField] } deriving (Eq, Show)
Makefile+1−2
@@ -25,11 +25,10 @@ haddock:
25 cabal haddock --hoogle --hyperlink-source --html-location='http://hackage.haskell.org/package/bloodhound/docs' --contents-location='http://hackage.haskell.org/package/bloodhound'
25 cabal haddock --hoogle --hyperlink-source --html-location='http://hackage.haskell.org/package/bloodhound/docs' --contents-location='http://hackage.haskell.org/package/bloodhound'
26
26
27dist:
27dist:
28− cabal sdist
28+ cabal sdist
29
29
30# upload:
30# upload:
31# cabal upload dist/bloodhound-0.1.0.2.tar.gz
31# cabal upload dist/bloodhound-0.1.0.2.tar.gz
32−
33# cp -R ./dist/doc/html/bloodhound/ bloodhound-0.1.0.2-docs
32# cp -R ./dist/doc/html/bloodhound/ bloodhound-0.1.0.2-docs
34# tar cvzf --format=ustar -f bloodhound-0.1.0.1-docs.tar.gz bloodhound-0.1.0.1-docs
33# tar cvzf --format=ustar -f bloodhound-0.1.0.1-docs.tar.gz bloodhound-0.1.0.1-docs
35# curl -X PUT -H 'Content-Type: application/x-tar' -H 'Content-Encoding: gzip' --data-binary '@bloodhound-0.1.0.1-docs.tar.gz' 'https://bitemyapp:$PASSWORD@hackage.haskell.org/package/bloodhound-0.1.0.1/docs'
34# curl -X PUT -H 'Content-Type: application/x-tar' -H 'Content-Encoding: gzip' --data-binary '@bloodhound-0.1.0.1-docs.tar.gz' 'https://bitemyapp:$PASSWORD@hackage.haskell.org/package/bloodhound-0.1.0.1/docs'
README.org+1−1
@@ -144,7 +144,7 @@ instance ToJSON TweetMapping where
144 object ["type" .= ("geo_point" :: Text)]]]]
144 object ["type" .= ("geo_point" :: Text)]]]]
145:}
145:}
146
146
147−resp <- createMapping testServer testIndex testMapping TweetMapping
147+resp <- putMapping testServer testIndex testMapping TweetMapping
148
148
149#+END_SRC
149#+END_SRC
150
150
tests/tests.hs+1−1
@@ -75,7 +75,7 @@ insertData :: IO ()
75insertData = do
75insertData = do
76 _ <- deleteExampleIndex
76 _ <- deleteExampleIndex
77 _ <- createExampleIndex
77 _ <- createExampleIndex
78− _ <- createMapping testServer testIndex testMapping TweetMapping
78+ _ <- putMapping testServer testIndex testMapping TweetMapping
79 _ <- indexDocument testServer testIndex testMapping exampleTweet (DocId "1")
79 _ <- indexDocument testServer testIndex testMapping exampleTweet (DocId "1")
80 _ <- refreshIndex testServer testIndex
80 _ <- refreshIndex testServer testIndex
81 return ()
81 return ()