git.iko.soy/typeable/bloodhound
on master help sign in
squashing errors
commit3bfd6c0f65ae3bdb2bd1442b260a88e3ce7ded58 authorChris Allen <cma@bitemyapp.com> dateSun 4 May 2014, 23:48 (12 years ago) parent0cc0d3f
6 files changed+42−31
Database/Bloodhound.hs+2 Database/Bloodhound/Client.hs+15−7 Database/Bloodhound/Types.hs+14−12 Database/Bloodhound/Types/Class.hs−1 Database/Bloodhound/Types/Instances.hs+10−10 bloodhound.cabal+1−1
Database/Bloodhound.hs+2
@@ -1,7 +1,9 @@
11module Database.Bloodhound
22 ( module Database.Bloodhound.Client
33 , module Database.Bloodhound.Types
4+ , module Database.Bloodhound.Types.Instances
45 ) where
56
67import Database.Bloodhound.Client
78import Database.Bloodhound.Types
9+import Database.Bloodhound.Types.Instances
Database/Bloodhound/Client.hs+15−7
@@ -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 }
Database/Bloodhound/Types.hs+14−12
@@ -19,7 +19,7 @@ module Database.Bloodhound.Types
1919 , NullValue(..)
2020 , IndexSettings(..)
2121 , Server(..)
22− , Reply(..)
22+ , Reply
2323 , EsResult(..)
2424 , Query(..)
2525 , Search(..)
@@ -59,14 +59,14 @@ module Database.Bloodhound.Types
5959 , BulkOperation(..)
6060 , ReplicaCount(..)
6161 , ShardCount(..)
62− , Sort(..)
62+ , Sort
6363 , SortMode(..)
6464 , SortOrder(..)
6565 , SortSpec(..)
6666 , DefaultSort(..)
6767 , Missing(..)
6868 , OpenCloseIndex(..)
69− , Method(..)
69+ , Method
7070 , Boost(..)
7171 , MatchQuery(..)
7272 , MultiMatchQuery(..)
@@ -147,6 +147,7 @@ data IndexSettings =
147147 IndexSettings { indexShards :: ShardCount
148148 , indexReplicas :: ReplicaCount } deriving (Eq, Show)
149149
150+defaultIndexSettings :: IndexSettings
150151defaultIndexSettings = IndexSettings (ShardCount 3) (ReplicaCount 2)
151152
152153data Strategy = RoundRobinStrat | RandomStrat | HeadStrat deriving (Eq, Show)
@@ -172,8 +173,8 @@ data MappingField =
172173 MappingField { mappingFieldName :: FieldName
173174 , fieldDefinition :: FieldDefinition } deriving (Eq, Show)
174175
175−data Mapping = Mapping { typeName :: TypeName
176− , fields :: [MappingField] } deriving (Eq, Show)
176+data Mapping = Mapping { typeName :: TypeName
177+ , mappingFields :: [MappingField] } deriving (Eq, Show)
177178
178179data BulkOperation =
179180 BulkIndex IndexName MappingName DocId Value
@@ -215,10 +216,11 @@ data SortMode = SortMin
215216 | SortAvg deriving (Eq, Show)
216217
217218mkSort :: 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
219220
220−type Cache = Bool -- caching on/off
221−defaultCache = False
221+type Cache = Bool -- caching on/off
222+defaultCache :: Cache
223+defaultCache = False
222224
223225type PrefixValue = Text
224226
@@ -507,8 +509,8 @@ data MultiMatchQuery =
507509 , multiMatchQueryLenient :: Maybe Lenient } deriving (Eq, Show)
508510
509511mkMultiMatchQuery :: [FieldName] -> QueryString -> MultiMatchQuery
510−mkMultiMatchQuery fields query =
511− MultiMatchQuery fields query Or ZeroTermsNone Nothing Nothing Nothing Nothing Nothing Nothing
512+mkMultiMatchQuery matchFields query =
513+ MultiMatchQuery matchFields query Or ZeroTermsNone Nothing Nothing Nothing Nothing Nothing Nothing
512514
513515data MultiMatchQueryType = MultiMatchBestFields
514516 | MultiMatchMostFields
@@ -689,8 +691,8 @@ maybeJson :: ToJSON a => Text -> Maybe a -> [(Text, Value)]
689691maybeJson field (Just value) = [field .= toJSON value]
690692maybeJson _ _ = []
691693
692−-- maybeJsonF :: (ToJSON (f Value), ToJSON a, Functor f) =>
693−-- Text -> Maybe (f a) -> [(Text, Value)]
694+maybeJsonF :: (ToJSON (f Value), ToJSON a, Functor f) =>
695+ Text -> Maybe (f a) -> [(Text, Value)]
694696maybeJsonF field (Just value) = [field .= fmap toJSON value]
695697maybeJsonF _ _ = []
696698
Database/Bloodhound/Types/Class.hs−1
@@ -2,7 +2,6 @@ module Database.Bloodhound.Types.Class
22 ( Seminearring(..) )
33 where
44
5−import Data.Aeson
65import Data.Monoid
76
87class Monoid a => Seminearring a where
Database/Bloodhound/Types/Instances.hs+10−10
@@ -12,8 +12,8 @@ import Data.Maybe (catMaybes)
1212import Data.Monoid
1313import qualified Data.Text as T
1414import Database.Bloodhound.Types
15−import Database.Bloodhound.Types.Class
16−import Data.Scientific
15+import Database.Bloodhound.Types.Class ()
16+import Prelude hiding (filter)
1717
1818instance Monoid Filter where
1919 mempty = IdentityFilter
@@ -50,21 +50,21 @@ instance ToJSON Filter where
5050 object ["geo_bounding_box" .= toJSON bbConstraint
5151 , "type" .= toJSON filterType]
5252
53− toJSON (GeoDistanceFilter (GeoPoint (FieldName geoField) latLon)
53+ toJSON (GeoDistanceFilter (GeoPoint (FieldName distanceGeoField) latLon)
5454 distance distanceType optimizeBbox cache) =
5555 object ["geo_distance" .=
5656 object ["distance" .= toJSON distance
5757 , "distance_type" .= toJSON distanceType
5858 , "optimize_bbox" .= optimizeBbox
59− , geoField .= toJSON latLon
59+ , distanceGeoField .= toJSON latLon
6060 , "_cache" .= cache]]
6161
62− toJSON (GeoDistanceRangeFilter (GeoPoint (FieldName geoField) latLon)
62+ toJSON (GeoDistanceRangeFilter (GeoPoint (FieldName geoField) drLatLon)
6363 (DistanceRange distanceFrom distanceTo)) =
6464 object ["geo_distance_range" .=
6565 object ["from" .= toJSON distanceFrom
6666 , "to" .= toJSON distanceTo
67− , geoField .= toJSON latLon]]
67+ , geoField .= toJSON drLatLon]]
6868
6969 toJSON (GeoPolygonFilter (FieldName geoField) latLons) =
7070 object ["geo_polygon" .=
@@ -159,8 +159,8 @@ instance ToJSON Query where
159159 toJSON (QueryDisMaxQuery disMaxQuery) =
160160 object [ "dis_max" .= toJSON disMaxQuery ]
161161
162− toJSON (QueryFilteredQuery filteredQuery) =
163− object [ "filtered" .= toJSON filteredQuery ]
162+ toJSON (QueryFilteredQuery qFilteredQuery) =
163+ object [ "filtered" .= toJSON qFilteredQuery ]
164164
165165 toJSON (QueryFuzzyLikeThisQuery fuzzyQuery) =
166166 object [ "fuzzy_like_this" .= toJSON fuzzyQuery ]
@@ -177,8 +177,8 @@ instance ToJSON Query where
177177 toJSON (QueryHasParentQuery parentQuery) =
178178 object [ "has_parent" .= toJSON parentQuery ]
179179
180− toJSON (QueryIndicesQuery indicesQuery) =
181− object [ "indices" .= toJSON indicesQuery ]
180+ toJSON (QueryIndicesQuery qIndicesQuery) =
181+ object [ "indices" .= toJSON qIndicesQuery ]
182182
183183 toJSON (MatchAllQuery boost) =
184184 object [ "match_all" .= object maybeAdd ]
bloodhound.cabal+1−1
@@ -20,7 +20,7 @@ source-repository head
2020 location: https://github.com/bitemyapp/bloodhound.git
2121
2222library
23− ghc-options: -Wall
23+ ghc-options: -Wall -fno-warn-unused-binds -fno-warn-orphans
2424 default-extensions: OverloadedStrings
2525 exposed-modules: Database.Bloodhound
2626 Database.Bloodhound.Client