git.iko.soy/typeable/bloodhound
on master help sign in
squashing errors
3bfd6c0Chris Allen
Database/Bloodhound.hs+2
@@ -1,7 +1,9 @@
1module Database.Bloodhound
1module Database.Bloodhound
2 ( module Database.Bloodhound.Client
2 ( module Database.Bloodhound.Client
3 , module Database.Bloodhound.Types
3 , module Database.Bloodhound.Types
4+ , module Database.Bloodhound.Types.Instances
4 ) where
5 ) where
5
6
6import Database.Bloodhound.Client
7import Database.Bloodhound.Client
7import Database.Bloodhound.Types
8import Database.Bloodhound.Types
9+import Database.Bloodhound.Types.Instances
Database/Bloodhound/Client.hs+15−7
@@ -25,10 +25,9 @@ import Data.Text (Text)
25import Network.HTTP.Conduit
25import Network.HTTP.Conduit
26import qualified Network.HTTP.Types.Method as NHTM
26import qualified Network.HTTP.Types.Method as NHTM
27import qualified Network.HTTP.Types.Status as NHTS
27import qualified Network.HTTP.Types.Status as NHTS
28−import Prelude hiding (head)
28+import Prelude hiding (head, filter)
29
29
30import Database.Bloodhound.Types
30import Database.Bloodhound.Types
31−import Database.Bloodhound.Types.Class
32import Database.Bloodhound.Types.Instances
31import Database.Bloodhound.Types.Instances
33
32
34-- find way to avoid destructuring Servers and Indexes?
33-- find way to avoid destructuring Servers and Indexes?
@@ -51,14 +50,15 @@ mkReplicaCount n
51responseIsError :: Reply -> Bool
50responseIsError :: Reply -> Bool
52responseIsError resp = NHTS.statusCode (responseStatus resp) > 299
51responseIsError resp = NHTS.statusCode (responseStatus resp) > 299
53
52
53+emptyBody :: L.ByteString
54emptyBody = L.pack ""
54emptyBody = L.pack ""
55
55
56dispatch :: Method -> String -> Maybe L.ByteString
56dispatch :: Method -> String -> Maybe L.ByteString
57 -> IO Reply
57 -> IO Reply
58−dispatch method url body = do
58+dispatch dMethod url body = do
59 initReq <- parseUrl url
59 initReq <- parseUrl url
60 let reqBody = RequestBodyLBS $ fromMaybe emptyBody body
60 let reqBody = RequestBodyLBS $ fromMaybe emptyBody body
61− let req = initReq { method = method
61+ let req = initReq { method = dMethod
62 , requestBody = reqBody
62 , requestBody = reqBody
63 , checkStatus = \_ _ _ -> Nothing}
63 , checkStatus = \_ _ _ -> Nothing}
64 withManager $ httpLbs req
64 withManager $ httpLbs req
@@ -66,10 +66,16 @@ dispatch method url body = do
66joinPath :: [String] -> String
66joinPath :: [String] -> String
67joinPath = intercalate "/"
67joinPath = intercalate "/"
68
68
69+-- Shortcut functions for HTTP methods
70+delete :: String -> IO Reply
69delete = flip (dispatch NHTM.methodDelete) $ Nothing
71delete = flip (dispatch NHTM.methodDelete) $ Nothing
72+get :: String -> IO Reply
70get = flip (dispatch NHTM.methodGet) $ Nothing
73get = flip (dispatch NHTM.methodGet) $ Nothing
74+head :: String -> IO Reply
71head = flip (dispatch NHTM.methodHead) $ Nothing
75head = flip (dispatch NHTM.methodHead) $ Nothing
76+put :: String -> Maybe L.ByteString -> IO Reply
72put = dispatch NHTM.methodPost
77put = dispatch NHTM.methodPost
78+post :: String -> Maybe L.ByteString -> IO Reply
73post = dispatch NHTM.methodPost
79post = dispatch NHTM.methodPost
74
80
75-- indexDocument s ix name doc = put (root </> s </> ix </> name </> doc) (Just encode doc)
81-- indexDocument s ix name doc = put (root </> s </> ix </> name </> doc) (Just encode doc)
@@ -95,13 +101,14 @@ deleteIndex (Server server) (IndexName indexName) =
95respIsTwoHunna :: Reply -> Bool
101respIsTwoHunna :: Reply -> Bool
96respIsTwoHunna resp = NHTS.statusCode (responseStatus resp) == 200
102respIsTwoHunna resp = NHTS.statusCode (responseStatus resp) == 200
97
103
104+existentialQuery :: String -> IO (Reply, Bool)
98existentialQuery url = do
105existentialQuery url = do
99 reply <- head url
106 reply <- head url
100 return (reply, respIsTwoHunna reply)
107 return (reply, respIsTwoHunna reply)
101
108
102indexExists :: Server -> IndexName -> IO Bool
109indexExists :: Server -> IndexName -> IO Bool
103indexExists (Server server) (IndexName indexName) = do
110indexExists (Server server) (IndexName indexName) = do
104− (reply, exists) <- existentialQuery url
111+ (_, exists) <- existentialQuery url
105 return exists
112 return exists
106 where url = joinPath [server, indexName]
113 where url = joinPath [server, indexName]
107
114
@@ -110,6 +117,7 @@ refreshIndex (Server server) (IndexName indexName) =
110 post url Nothing
117 post url Nothing
111 where url = joinPath [server, indexName, "_refresh"]
118 where url = joinPath [server, indexName, "_refresh"]
112
119
120+stringifyOCIndex :: OpenCloseIndex -> String
113stringifyOCIndex oci = case oci of
121stringifyOCIndex oci = case oci of
114 OpenIndex -> "_open"
122 OpenIndex -> "_open"
115 CloseIndex -> "_close"
123 CloseIndex -> "_close"
@@ -207,7 +215,7 @@ documentExists :: Server -> IndexName -> MappingName
207 -> DocId -> IO Bool
215 -> DocId -> IO Bool
208documentExists (Server server) (IndexName indexName)
216documentExists (Server server) (IndexName indexName)
209 (MappingName mappingName) (DocId docId) = do
217 (MappingName mappingName) (DocId docId) = do
210− (reply, exists) <- existentialQuery url
218+ (_, exists) <- existentialQuery url
211 return exists where
219 return exists where
212 url = joinPath [server, indexName, mappingName, docId]
220 url = joinPath [server, indexName, mappingName, docId]
213
221
@@ -231,4 +239,4 @@ mkSearch :: Maybe Query -> Maybe Filter -> Search
231mkSearch query filter = Search query filter Nothing False 0 10
239mkSearch query filter = Search query filter Nothing False 0 10
232
240
233pageSearch :: Int -> Int -> Search -> Search
241pageSearch :: Int -> Int -> Search -> Search
234−pageSearch from size search = search { from = from, size = size }
242+pageSearch pageFrom pageSize search = search { from = pageFrom, size = pageSize }
Database/Bloodhound/Types.hs+14−12
@@ -19,7 +19,7 @@ module Database.Bloodhound.Types
19 , NullValue(..)
19 , NullValue(..)
20 , IndexSettings(..)
20 , IndexSettings(..)
21 , Server(..)
21 , Server(..)
22− , Reply(..)
22+ , Reply
23 , EsResult(..)
23 , EsResult(..)
24 , Query(..)
24 , Query(..)
25 , Search(..)
25 , Search(..)
@@ -59,14 +59,14 @@ module Database.Bloodhound.Types
59 , BulkOperation(..)
59 , BulkOperation(..)
60 , ReplicaCount(..)
60 , ReplicaCount(..)
61 , ShardCount(..)
61 , ShardCount(..)
62− , Sort(..)
62+ , Sort
63 , SortMode(..)
63 , SortMode(..)
64 , SortOrder(..)
64 , SortOrder(..)
65 , SortSpec(..)
65 , SortSpec(..)
66 , DefaultSort(..)
66 , DefaultSort(..)
67 , Missing(..)
67 , Missing(..)
68 , OpenCloseIndex(..)
68 , OpenCloseIndex(..)
69− , Method(..)
69+ , Method
70 , Boost(..)
70 , Boost(..)
71 , MatchQuery(..)
71 , MatchQuery(..)
72 , MultiMatchQuery(..)
72 , MultiMatchQuery(..)
@@ -147,6 +147,7 @@ data IndexSettings =
147 IndexSettings { indexShards :: ShardCount
147 IndexSettings { indexShards :: ShardCount
148 , indexReplicas :: ReplicaCount } deriving (Eq, Show)
148 , indexReplicas :: ReplicaCount } deriving (Eq, Show)
149
149
150+defaultIndexSettings :: IndexSettings
150defaultIndexSettings = IndexSettings (ShardCount 3) (ReplicaCount 2)
151defaultIndexSettings = IndexSettings (ShardCount 3) (ReplicaCount 2)
151
152
152data Strategy = RoundRobinStrat | RandomStrat | HeadStrat deriving (Eq, Show)
153data Strategy = RoundRobinStrat | RandomStrat | HeadStrat deriving (Eq, Show)
@@ -172,8 +173,8 @@ data MappingField =
172 MappingField { mappingFieldName :: FieldName
173 MappingField { mappingFieldName :: FieldName
173 , fieldDefinition :: FieldDefinition } deriving (Eq, Show)
174 , fieldDefinition :: FieldDefinition } deriving (Eq, Show)
174
175
175−data Mapping = Mapping { typeName :: TypeName
176+data Mapping = Mapping { typeName :: TypeName
176− , fields :: [MappingField] } deriving (Eq, Show)
177+ , mappingFields :: [MappingField] } deriving (Eq, Show)
177
178
178data BulkOperation =
179data BulkOperation =
179 BulkIndex IndexName MappingName DocId Value
180 BulkIndex IndexName MappingName DocId Value
@@ -215,10 +216,11 @@ data SortMode = SortMin
215 | SortAvg deriving (Eq, Show)
216 | SortAvg deriving (Eq, Show)
216
217
217mkSort :: FieldName -> SortOrder -> DefaultSort
218mkSort :: FieldName -> SortOrder -> DefaultSort
218−mkSort fieldName sortOrder = DefaultSort fieldName sortOrder False Nothing Nothing Nothing
219+mkSort fieldName sOrder = DefaultSort fieldName sOrder False Nothing Nothing Nothing
219
220
220−type Cache = Bool -- caching on/off
221+type Cache = Bool -- caching on/off
221−defaultCache = False
222+defaultCache :: Cache
223+defaultCache = False
222
224
223type PrefixValue = Text
225type PrefixValue = Text
224
226
@@ -507,8 +509,8 @@ data MultiMatchQuery =
507 , multiMatchQueryLenient :: Maybe Lenient } deriving (Eq, Show)
509 , multiMatchQueryLenient :: Maybe Lenient } deriving (Eq, Show)
508
510
509mkMultiMatchQuery :: [FieldName] -> QueryString -> MultiMatchQuery
511mkMultiMatchQuery :: [FieldName] -> QueryString -> MultiMatchQuery
510−mkMultiMatchQuery fields query =
512+mkMultiMatchQuery matchFields query =
511− MultiMatchQuery fields query Or ZeroTermsNone Nothing Nothing Nothing Nothing Nothing Nothing
513+ MultiMatchQuery matchFields query Or ZeroTermsNone Nothing Nothing Nothing Nothing Nothing Nothing
512
514
513data MultiMatchQueryType = MultiMatchBestFields
515data MultiMatchQueryType = MultiMatchBestFields
514 | MultiMatchMostFields
516 | MultiMatchMostFields
@@ -689,8 +691,8 @@ maybeJson :: ToJSON a => Text -> Maybe a -> [(Text, Value)]
689maybeJson field (Just value) = [field .= toJSON value]
691maybeJson field (Just value) = [field .= toJSON value]
690maybeJson _ _ = []
692maybeJson _ _ = []
691
693
692−-- maybeJsonF :: (ToJSON (f Value), ToJSON a, Functor f) =>
694+maybeJsonF :: (ToJSON (f Value), ToJSON a, Functor f) =>
693−-- Text -> Maybe (f a) -> [(Text, Value)]
695+ Text -> Maybe (f a) -> [(Text, Value)]
694maybeJsonF field (Just value) = [field .= fmap toJSON value]
696maybeJsonF field (Just value) = [field .= fmap toJSON value]
695maybeJsonF _ _ = []
697maybeJsonF _ _ = []
696
698
Database/Bloodhound/Types/Class.hs−1
@@ -2,7 +2,6 @@ module Database.Bloodhound.Types.Class
2 ( Seminearring(..) )
2 ( Seminearring(..) )
3 where
3 where
4
4
5−import Data.Aeson
6import Data.Monoid
5import Data.Monoid
7
6
8class Monoid a => Seminearring a where
7class Monoid a => Seminearring a where
Database/Bloodhound/Types/Instances.hs+10−10
@@ -12,8 +12,8 @@ import Data.Maybe (catMaybes)
12import Data.Monoid
12import Data.Monoid
13import qualified Data.Text as T
13import qualified Data.Text as T
14import Database.Bloodhound.Types
14import Database.Bloodhound.Types
15−import Database.Bloodhound.Types.Class
15+import Database.Bloodhound.Types.Class ()
16−import Data.Scientific
16+import Prelude hiding (filter)
17
17
18instance Monoid Filter where
18instance Monoid Filter where
19 mempty = IdentityFilter
19 mempty = IdentityFilter
@@ -50,21 +50,21 @@ instance ToJSON Filter where
50 object ["geo_bounding_box" .= toJSON bbConstraint
50 object ["geo_bounding_box" .= toJSON bbConstraint
51 , "type" .= toJSON filterType]
51 , "type" .= toJSON filterType]
52
52
53− toJSON (GeoDistanceFilter (GeoPoint (FieldName geoField) latLon)
53+ toJSON (GeoDistanceFilter (GeoPoint (FieldName distanceGeoField) latLon)
54 distance distanceType optimizeBbox cache) =
54 distance distanceType optimizeBbox cache) =
55 object ["geo_distance" .=
55 object ["geo_distance" .=
56 object ["distance" .= toJSON distance
56 object ["distance" .= toJSON distance
57 , "distance_type" .= toJSON distanceType
57 , "distance_type" .= toJSON distanceType
58 , "optimize_bbox" .= optimizeBbox
58 , "optimize_bbox" .= optimizeBbox
59− , geoField .= toJSON latLon
59+ , distanceGeoField .= toJSON latLon
60 , "_cache" .= cache]]
60 , "_cache" .= cache]]
61
61
62− toJSON (GeoDistanceRangeFilter (GeoPoint (FieldName geoField) latLon)
62+ toJSON (GeoDistanceRangeFilter (GeoPoint (FieldName geoField) drLatLon)
63 (DistanceRange distanceFrom distanceTo)) =
63 (DistanceRange distanceFrom distanceTo)) =
64 object ["geo_distance_range" .=
64 object ["geo_distance_range" .=
65 object ["from" .= toJSON distanceFrom
65 object ["from" .= toJSON distanceFrom
66 , "to" .= toJSON distanceTo
66 , "to" .= toJSON distanceTo
67− , geoField .= toJSON latLon]]
67+ , geoField .= toJSON drLatLon]]
68
68
69 toJSON (GeoPolygonFilter (FieldName geoField) latLons) =
69 toJSON (GeoPolygonFilter (FieldName geoField) latLons) =
70 object ["geo_polygon" .=
70 object ["geo_polygon" .=
@@ -159,8 +159,8 @@ instance ToJSON Query where
159 toJSON (QueryDisMaxQuery disMaxQuery) =
159 toJSON (QueryDisMaxQuery disMaxQuery) =
160 object [ "dis_max" .= toJSON disMaxQuery ]
160 object [ "dis_max" .= toJSON disMaxQuery ]
161
161
162− toJSON (QueryFilteredQuery filteredQuery) =
162+ toJSON (QueryFilteredQuery qFilteredQuery) =
163− object [ "filtered" .= toJSON filteredQuery ]
163+ object [ "filtered" .= toJSON qFilteredQuery ]
164
164
165 toJSON (QueryFuzzyLikeThisQuery fuzzyQuery) =
165 toJSON (QueryFuzzyLikeThisQuery fuzzyQuery) =
166 object [ "fuzzy_like_this" .= toJSON fuzzyQuery ]
166 object [ "fuzzy_like_this" .= toJSON fuzzyQuery ]
@@ -177,8 +177,8 @@ instance ToJSON Query where
177 toJSON (QueryHasParentQuery parentQuery) =
177 toJSON (QueryHasParentQuery parentQuery) =
178 object [ "has_parent" .= toJSON parentQuery ]
178 object [ "has_parent" .= toJSON parentQuery ]
179
179
180− toJSON (QueryIndicesQuery indicesQuery) =
180+ toJSON (QueryIndicesQuery qIndicesQuery) =
181− object [ "indices" .= toJSON indicesQuery ]
181+ object [ "indices" .= toJSON qIndicesQuery ]
182
182
183 toJSON (MatchAllQuery boost) =
183 toJSON (MatchAllQuery boost) =
184 object [ "match_all" .= object maybeAdd ]
184 object [ "match_all" .= object maybeAdd ]
bloodhound.cabal+1−1
@@ -20,7 +20,7 @@ source-repository head
20 location: https://github.com/bitemyapp/bloodhound.git
20 location: https://github.com/bitemyapp/bloodhound.git
21
21
22library
22library
23− ghc-options: -Wall
23+ ghc-options: -Wall -fno-warn-unused-binds -fno-warn-orphans
24 default-extensions: OverloadedStrings
24 default-extensions: OverloadedStrings
25 exposed-modules: Database.Bloodhound
25 exposed-modules: Database.Bloodhound
26 Database.Bloodhound.Client
26 Database.Bloodhound.Client