git.iko.soy/typeable/bloodhound
on master help sign in
minor cleanup
commitd03228d1a9cd16a43dff2c6a70bb154aec75e392 authorChris Allen <cma@bitemyapp.com> dateSun 18 May 2014, 17:51 (12 years ago) parentdad0dac
3 files changed+51−52
Database/Bloodhound/Client.hs+11−10 Database/Bloodhound/Types.hs+3−6 Database/Bloodhound/Types/Instances.hs+37−36
Database/Bloodhound/Client.hs+11−10
@@ -68,11 +68,11 @@ joinPath = intercalate "/"
6868
6969-- Shortcut functions for HTTP methods
7070delete :: String -> IO Reply
71−delete = flip (dispatch NHTM.methodDelete) $ Nothing
71+delete = flip (dispatch NHTM.methodDelete) Nothing
7272get :: String -> IO Reply
73−get = flip (dispatch NHTM.methodGet) $ Nothing
73+get = flip (dispatch NHTM.methodGet) Nothing
7474head :: String -> IO Reply
75−head = flip (dispatch NHTM.methodHead) $ Nothing
75+head = flip (dispatch NHTM.methodHead) Nothing
7676put :: String -> Maybe L.ByteString -> IO Reply
7777put = dispatch NHTM.methodPost
7878post :: String -> Maybe L.ByteString -> IO Reply
@@ -142,9 +142,9 @@ createMapping (Server server) (IndexName indexName) (MappingName mappingName) ma
142142 body = Just $ encode mapping
143143
144144deleteMapping :: Server -> IndexName -> MappingName -> IO Reply
145−deleteMapping (Server server) (IndexName indexName) (MappingName mappingName) =
145+deleteMapping (Server server) (IndexName indexName)
146+ (MappingName mappingName) =
146147 delete $ joinPath [server, indexName, mappingName, "_mapping"]
147−
148148indexDocument :: ToJSON doc => Server -> IndexName -> MappingName
149149 -> doc -> DocId -> IO Reply
150150indexDocument (Server server) (IndexName indexName)
@@ -171,7 +171,7 @@ collapseStream stream = collapsed where
171171 collapsed = toLazyByteString $ mappend mashedTaters (byteString "\n")
172172
173173mash :: Builder -> [L.ByteString] -> Builder
174−mash builder xs = foldl' (\b x -> mappend b (lazyByteString x)) builder xs
174+mash = foldl' (\b x -> mappend b (lazyByteString x))
175175
176176mkMetadataValue :: Text -> String -> String -> String -> Value
177177mkMetadataValue operation indexName mappingName docId =
@@ -208,7 +208,8 @@ getStreamChunk (BulkUpdate (IndexName indexName)
208208
209209getDocument :: Server -> IndexName -> MappingName
210210 -> DocId -> IO Reply
211−getDocument (Server server) (IndexName indexName) (MappingName mappingName) (DocId docId) =
211+getDocument (Server server) (IndexName indexName)
212+ (MappingName mappingName) (DocId docId) =
212213 get $ joinPath [server, indexName, mappingName, docId]
213214
214215documentExists :: Server -> IndexName -> MappingName
@@ -223,16 +224,16 @@ dispatchSearch :: String -> Search -> IO Reply
223224dispatchSearch url search = post url (Just (encode search))
224225
225226searchAll :: Server -> Search -> IO Reply
226−searchAll (Server server) search = dispatchSearch url search where
227+searchAll (Server server) = dispatchSearch url where
227228 url = joinPath [server, "_search"]
228229
229230searchByIndex :: Server -> IndexName -> Search -> IO Reply
230−searchByIndex (Server server) (IndexName indexName) search = dispatchSearch url search where
231+searchByIndex (Server server) (IndexName indexName) = dispatchSearch url where
231232 url = joinPath [server, indexName, "_search"]
232233
233234searchByType :: Server -> IndexName -> MappingName -> Search -> IO Reply
234235searchByType (Server server) (IndexName indexName)
235− (MappingName mappingName) search = dispatchSearch url search where
236+ (MappingName mappingName) = dispatchSearch url where
236237 url = joinPath [server, indexName, mappingName, "_search"]
237238
238239mkSearch :: Maybe Query -> Maybe Filter -> Search
Database/Bloodhound/Types.hs+3−6
@@ -1,10 +1,6 @@
11{-# LANGUAGE DeriveGeneric #-}
22
3−{-| Data types for describing actions and data structures performed to interact with
4− Elasticsearch. The two main buckets your queries against Elasticsearch will fall
5− into are 'Query's and 'Filter's. 'Filter's are more like traditional database
6− constraints and often have preferable performance properties. 'Query's support
7− human-written textual queries, such as fuzzy queries.
3+{-| Data types for describing actions and data structures performed to interact with Elasticsearch. The two main buckets your queries against Elasticsearch will fall into are 'Query's and 'Filter's. 'Filter's are more like traditional database constraints and often have preferable performance properties. 'Query's support human-written textual queries, such as fuzzy queries.
84-}
95
106module Database.Bloodhound.Types
@@ -659,7 +655,8 @@ data Filter = AndFilter [Filter] Cache
659655 | RegexpFilter FieldName Regexp RegexpFlags CacheName Cache CacheKey
660656 deriving (Eq, Show)
661657
662−data ZeroTermsQuery = ZeroTermsNone | ZeroTermsAll deriving (Eq, Show)
658+data ZeroTermsQuery = ZeroTermsNone
659+ | ZeroTermsAll deriving (Eq, Show)
663660
664661-- lt, lte | gt, gte
665662newtype LessThan = LessThan Double deriving (Eq, Show)
Database/Bloodhound/Types/Instances.hs+37−36
@@ -59,12 +59,12 @@ instance ToJSON Filter where
5959 , distanceGeoField .= toJSON latLon
6060 , "_cache" .= cache]]
6161
62− toJSON (GeoDistanceRangeFilter (GeoPoint (FieldName geoField) drLatLon)
63− (DistanceRange distanceFrom distanceTo)) =
62+ toJSON (GeoDistanceRangeFilter (GeoPoint (FieldName gddrField) drLatLon)
63+ (DistanceRange distanceFrom drDistanceTo)) =
6464 object ["geo_distance_range" .=
6565 object ["from" .= toJSON distanceFrom
66− , "to" .= toJSON distanceTo
67− , geoField .= toJSON drLatLon]]
66+ , "to" .= toJSON drDistanceTo
67+ , gddrField .= toJSON drLatLon]]
6868
6969 toJSON (GeoPolygonFilter (FieldName geoField) latLons) =
7070 object ["geo_polygon" .=
@@ -358,20 +358,20 @@ instance ToJSON CommonMinimumMatch where
358358 , "high_freq" .= toJSON highF ]
359359
360360instance ToJSON BoostingQuery where
361− toJSON (BoostingQuery positiveQuery negativeQuery negativeBoost) =
362− object [ "positive" .= toJSON positiveQuery
363− , "negative" .= toJSON negativeQuery
364− , "negative_boost" .= toJSON negativeBoost ]
361+ toJSON (BoostingQuery bqPositiveQuery bqNegativeQuery bqNegativeBoost) =
362+ object [ "positive" .= toJSON bqPositiveQuery
363+ , "negative" .= toJSON bqNegativeQuery
364+ , "negative_boost" .= toJSON bqNegativeBoost ]
365365
366366
367367instance ToJSON BoolQuery where
368− toJSON (BoolQuery mustM notM shouldM min boost disableCoord) =
368+ toJSON (BoolQuery mustM notM shouldM bqMin boost disableCoord) =
369369 object filtered
370370 where filtered = catMaybes
371371 [ mField "must" mustM
372372 , mField "must_not" notM
373373 , mField "should" shouldM
374− , mField "minimum_should_match" min
374+ , mField "minimum_should_match" bqMin
375375 , mField "boost" boost
376376 , mField "disable_coord" disableCoord ]
377377
@@ -491,14 +491,14 @@ instance (FromJSON a) => FromJSON (EsResult a) where
491491
492492
493493instance ToJSON Search where
494− toJSON (Search query filter sort trackSortScores from size) =
494+ toJSON (Search query filter sort sTrackSortScores sFrom sSize) =
495495 object merged where
496496 lQuery = maybeJson "query" query
497497 lFilter = maybeJson "filter" filter
498498 lSort = maybeJsonF "sort" sort
499− merged = mconcat [[ "from" .= from
500− , "size" .= size
501− , "track_scores" .= trackSortScores]
499+ merged = mconcat [[ "from" .= sFrom
500+ , "size" .= sSize
501+ , "track_scores" .= sTrackSortScores]
502502 , lQuery
503503 , lFilter
504504 , lSort]
@@ -506,20 +506,20 @@ instance ToJSON Search where
506506
507507instance ToJSON SortSpec where
508508 toJSON (DefaultSortSpec
509− (DefaultSort (FieldName sortFieldName) sortOrder ignoreUnmapped
510− sortMode missingSort nestedFilter)) =
511− object [sortFieldName .= object merged] where
512− base = ["order" .= toJSON sortOrder
513− , "ignore_unmapped" .= ignoreUnmapped]
514− lSortMode = maybeJson "mode" sortMode
515− lMissingSort = maybeJson "missing" missingSort
516− lNestedFilter = maybeJson "nested_filter" nestedFilter
509+ (DefaultSort (FieldName dsSortFieldName) dsSortOrder dsIgnoreUnmapped
510+ dsSortMode dsMissingSort dsNestedFilter)) =
511+ object [dsSortFieldName .= object merged] where
512+ base = ["order" .= toJSON dsSortOrder
513+ , "ignore_unmapped" .= dsIgnoreUnmapped]
514+ lSortMode = maybeJson "mode" dsSortMode
515+ lMissingSort = maybeJson "missing" dsMissingSort
516+ lNestedFilter = maybeJson "nested_filter" dsNestedFilter
517517 merged = mconcat [base, lSortMode, lMissingSort, lNestedFilter]
518518
519− toJSON (GeoDistanceSortSpec sortOrder (GeoPoint (FieldName field) latLon) units) =
519+ toJSON (GeoDistanceSortSpec gdsSortOrder (GeoPoint (FieldName field) gdsLatLon) units) =
520520 object [ "unit" .= toJSON units
521− , field .= toJSON latLon
522− , "order" .= toJSON sortOrder ]
521+ , field .= toJSON gdsLatLon
522+ , "order" .= toJSON gdsSortOrder ]
523523
524524
525525instance ToJSON SortOrder where
@@ -548,10 +548,10 @@ instance ToJSON ScoreType where
548548
549549
550550instance ToJSON Distance where
551− toJSON (Distance coefficient unit) =
551+ toJSON (Distance dCoefficient dUnit) =
552552 String boltedTogether where
553− coefText = showText coefficient
554− (String unitText) = (toJSON unit)
553+ coefText = showText dCoefficient
554+ (String unitText) = toJSON dUnit
555555 boltedTogether = mappend coefText unitText
556556
557557
@@ -579,8 +579,9 @@ instance ToJSON OptimizeBbox where
579579
580580
581581instance ToJSON GeoBoundingBoxConstraint where
582− toJSON (GeoBoundingBoxConstraint (FieldName geoBBField) constraintBox cache) =
583− object [geoBBField .= toJSON constraintBox
582+ toJSON (GeoBoundingBoxConstraint
583+ (FieldName gbbcGeoBBField) gbbcConstraintBox cache) =
584+ object [gbbcGeoBBField .= toJSON gbbcConstraintBox
584585 , "_cache" .= cache]
585586
586587
@@ -590,15 +591,15 @@ instance ToJSON GeoFilterType where
590591
591592
592593instance ToJSON GeoBoundingBox where
593− toJSON (GeoBoundingBox topLeft bottomRight) =
594− object ["top_left" .= toJSON topLeft
595− , "bottom_right" .= toJSON bottomRight]
594+ toJSON (GeoBoundingBox gbbTopLeft gbbBottomRight) =
595+ object ["top_left" .= toJSON gbbTopLeft
596+ , "bottom_right" .= toJSON gbbBottomRight]
596597
597598
598599instance ToJSON LatLon where
599− toJSON (LatLon lat lon) =
600− object ["lat" .= lat
601− , "lon" .= lon]
600+ toJSON (LatLon lLat lLon) =
601+ object ["lat" .= lLat
602+ , "lon" .= lLon]
602603
603604
604605-- index for smaller ranges, fielddata for longer ranges