git.iko.soy/typeable/bloodhound
on master help sign in
minor cleanup
d03228dChris Allen
Database/Bloodhound/Client.hs+11−10
@@ -68,11 +68,11 @@ joinPath = intercalate "/"
68
68
69-- Shortcut functions for HTTP methods
69-- Shortcut functions for HTTP methods
70delete :: String -> IO Reply
70delete :: String -> IO Reply
71−delete = flip (dispatch NHTM.methodDelete) $ Nothing
71+delete = flip (dispatch NHTM.methodDelete) Nothing
72get :: String -> IO Reply
72get :: String -> IO Reply
73−get = flip (dispatch NHTM.methodGet) $ Nothing
73+get = flip (dispatch NHTM.methodGet) Nothing
74head :: String -> IO Reply
74head :: String -> IO Reply
75−head = flip (dispatch NHTM.methodHead) $ Nothing
75+head = flip (dispatch NHTM.methodHead) Nothing
76put :: String -> Maybe L.ByteString -> IO Reply
76put :: String -> Maybe L.ByteString -> IO Reply
77put = dispatch NHTM.methodPost
77put = dispatch NHTM.methodPost
78post :: String -> Maybe L.ByteString -> IO Reply
78post :: String -> Maybe L.ByteString -> IO Reply
@@ -142,9 +142,9 @@ createMapping (Server server) (IndexName indexName) (MappingName mappingName) ma
142 body = Just $ encode mapping
142 body = Just $ encode mapping
143
143
144deleteMapping :: Server -> IndexName -> MappingName -> IO Reply
144deleteMapping :: Server -> IndexName -> MappingName -> IO Reply
145−deleteMapping (Server server) (IndexName indexName) (MappingName mappingName) =
145+deleteMapping (Server server) (IndexName indexName)
146+ (MappingName mappingName) =
146 delete $ joinPath [server, indexName, mappingName, "_mapping"]
147 delete $ joinPath [server, indexName, mappingName, "_mapping"]
147−
148indexDocument :: ToJSON doc => Server -> IndexName -> MappingName
148indexDocument :: ToJSON doc => Server -> IndexName -> MappingName
149 -> doc -> DocId -> IO Reply
149 -> doc -> DocId -> IO Reply
150indexDocument (Server server) (IndexName indexName)
150indexDocument (Server server) (IndexName indexName)
@@ -171,7 +171,7 @@ collapseStream stream = collapsed where
171 collapsed = toLazyByteString $ mappend mashedTaters (byteString "\n")
171 collapsed = toLazyByteString $ mappend mashedTaters (byteString "\n")
172
172
173mash :: Builder -> [L.ByteString] -> Builder
173mash :: 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))
175
175
176mkMetadataValue :: Text -> String -> String -> String -> Value
176mkMetadataValue :: Text -> String -> String -> String -> Value
177mkMetadataValue operation indexName mappingName docId =
177mkMetadataValue operation indexName mappingName docId =
@@ -208,7 +208,8 @@ getStreamChunk (BulkUpdate (IndexName indexName)
208
208
209getDocument :: Server -> IndexName -> MappingName
209getDocument :: Server -> IndexName -> MappingName
210 -> DocId -> IO Reply
210 -> DocId -> IO Reply
211−getDocument (Server server) (IndexName indexName) (MappingName mappingName) (DocId docId) =
211+getDocument (Server server) (IndexName indexName)
212+ (MappingName mappingName) (DocId docId) =
212 get $ joinPath [server, indexName, mappingName, docId]
213 get $ joinPath [server, indexName, mappingName, docId]
213
214
214documentExists :: Server -> IndexName -> MappingName
215documentExists :: Server -> IndexName -> MappingName
@@ -223,16 +224,16 @@ dispatchSearch :: String -> Search -> IO Reply
223dispatchSearch url search = post url (Just (encode search))
224dispatchSearch url search = post url (Just (encode search))
224
225
225searchAll :: Server -> Search -> IO Reply
226searchAll :: Server -> Search -> IO Reply
226−searchAll (Server server) search = dispatchSearch url search where
227+searchAll (Server server) = dispatchSearch url where
227 url = joinPath [server, "_search"]
228 url = joinPath [server, "_search"]
228
229
229searchByIndex :: Server -> IndexName -> Search -> IO Reply
230searchByIndex :: 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
231 url = joinPath [server, indexName, "_search"]
232 url = joinPath [server, indexName, "_search"]
232
233
233searchByType :: Server -> IndexName -> MappingName -> Search -> IO Reply
234searchByType :: Server -> IndexName -> MappingName -> Search -> IO Reply
234searchByType (Server server) (IndexName indexName)
235searchByType (Server server) (IndexName indexName)
235− (MappingName mappingName) search = dispatchSearch url search where
236+ (MappingName mappingName) = dispatchSearch url where
236 url = joinPath [server, indexName, mappingName, "_search"]
237 url = joinPath [server, indexName, mappingName, "_search"]
237
238
238mkSearch :: Maybe Query -> Maybe Filter -> Search
239mkSearch :: Maybe Query -> Maybe Filter -> Search
Database/Bloodhound/Types.hs+3−6
@@ -1,10 +1,6 @@
1{-# LANGUAGE DeriveGeneric #-}
1{-# LANGUAGE DeriveGeneric #-}
2
2
3−{-| Data types for describing actions and data structures performed to interact with
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.
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.
8-}
4-}
9
5
10module Database.Bloodhound.Types
6module Database.Bloodhound.Types
@@ -659,7 +655,8 @@ data Filter = AndFilter [Filter] Cache
659 | RegexpFilter FieldName Regexp RegexpFlags CacheName Cache CacheKey
655 | RegexpFilter FieldName Regexp RegexpFlags CacheName Cache CacheKey
660 deriving (Eq, Show)
656 deriving (Eq, Show)
661
657
662−data ZeroTermsQuery = ZeroTermsNone | ZeroTermsAll deriving (Eq, Show)
658+data ZeroTermsQuery = ZeroTermsNone
659+ | ZeroTermsAll deriving (Eq, Show)
663
660
664-- lt, lte | gt, gte
661-- lt, lte | gt, gte
665newtype LessThan = LessThan Double deriving (Eq, Show)
662newtype LessThan = LessThan Double deriving (Eq, Show)
Database/Bloodhound/Types/Instances.hs+37−36
@@ -59,12 +59,12 @@ instance ToJSON Filter where
59 , distanceGeoField .= toJSON latLon
59 , distanceGeoField .= toJSON latLon
60 , "_cache" .= cache]]
60 , "_cache" .= cache]]
61
61
62− toJSON (GeoDistanceRangeFilter (GeoPoint (FieldName geoField) drLatLon)
62+ toJSON (GeoDistanceRangeFilter (GeoPoint (FieldName gddrField) drLatLon)
63− (DistanceRange distanceFrom distanceTo)) =
63+ (DistanceRange distanceFrom drDistanceTo)) =
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 drDistanceTo
67− , geoField .= toJSON drLatLon]]
67+ , gddrField .= toJSON drLatLon]]
68
68
69 toJSON (GeoPolygonFilter (FieldName geoField) latLons) =
69 toJSON (GeoPolygonFilter (FieldName geoField) latLons) =
70 object ["geo_polygon" .=
70 object ["geo_polygon" .=
@@ -358,20 +358,20 @@ instance ToJSON CommonMinimumMatch where
358 , "high_freq" .= toJSON highF ]
358 , "high_freq" .= toJSON highF ]
359
359
360instance ToJSON BoostingQuery where
360instance ToJSON BoostingQuery where
361− toJSON (BoostingQuery positiveQuery negativeQuery negativeBoost) =
361+ toJSON (BoostingQuery bqPositiveQuery bqNegativeQuery bqNegativeBoost) =
362− object [ "positive" .= toJSON positiveQuery
362+ object [ "positive" .= toJSON bqPositiveQuery
363− , "negative" .= toJSON negativeQuery
363+ , "negative" .= toJSON bqNegativeQuery
364− , "negative_boost" .= toJSON negativeBoost ]
364+ , "negative_boost" .= toJSON bqNegativeBoost ]
365
365
366
366
367instance ToJSON BoolQuery where
367instance ToJSON BoolQuery where
368− toJSON (BoolQuery mustM notM shouldM min boost disableCoord) =
368+ toJSON (BoolQuery mustM notM shouldM bqMin boost disableCoord) =
369 object filtered
369 object filtered
370 where filtered = catMaybes
370 where filtered = catMaybes
371 [ mField "must" mustM
371 [ mField "must" mustM
372 , mField "must_not" notM
372 , mField "must_not" notM
373 , mField "should" shouldM
373 , mField "should" shouldM
374− , mField "minimum_should_match" min
374+ , mField "minimum_should_match" bqMin
375 , mField "boost" boost
375 , mField "boost" boost
376 , mField "disable_coord" disableCoord ]
376 , mField "disable_coord" disableCoord ]
377
377
@@ -491,14 +491,14 @@ instance (FromJSON a) => FromJSON (EsResult a) where
491
491
492
492
493instance ToJSON Search where
493instance ToJSON Search where
494− toJSON (Search query filter sort trackSortScores from size) =
494+ toJSON (Search query filter sort sTrackSortScores sFrom sSize) =
495 object merged where
495 object merged where
496 lQuery = maybeJson "query" query
496 lQuery = maybeJson "query" query
497 lFilter = maybeJson "filter" filter
497 lFilter = maybeJson "filter" filter
498 lSort = maybeJsonF "sort" sort
498 lSort = maybeJsonF "sort" sort
499− merged = mconcat [[ "from" .= from
499+ merged = mconcat [[ "from" .= sFrom
500− , "size" .= size
500+ , "size" .= sSize
501− , "track_scores" .= trackSortScores]
501+ , "track_scores" .= sTrackSortScores]
502 , lQuery
502 , lQuery
503 , lFilter
503 , lFilter
504 , lSort]
504 , lSort]
@@ -506,20 +506,20 @@ instance ToJSON Search where
506
506
507instance ToJSON SortSpec where
507instance ToJSON SortSpec where
508 toJSON (DefaultSortSpec
508 toJSON (DefaultSortSpec
509− (DefaultSort (FieldName sortFieldName) sortOrder ignoreUnmapped
509+ (DefaultSort (FieldName dsSortFieldName) dsSortOrder dsIgnoreUnmapped
510− sortMode missingSort nestedFilter)) =
510+ dsSortMode dsMissingSort dsNestedFilter)) =
511− object [sortFieldName .= object merged] where
511+ object [dsSortFieldName .= object merged] where
512− base = ["order" .= toJSON sortOrder
512+ base = ["order" .= toJSON dsSortOrder
513− , "ignore_unmapped" .= ignoreUnmapped]
513+ , "ignore_unmapped" .= dsIgnoreUnmapped]
514− lSortMode = maybeJson "mode" sortMode
514+ lSortMode = maybeJson "mode" dsSortMode
515− lMissingSort = maybeJson "missing" missingSort
515+ lMissingSort = maybeJson "missing" dsMissingSort
516− lNestedFilter = maybeJson "nested_filter" nestedFilter
516+ lNestedFilter = maybeJson "nested_filter" dsNestedFilter
517 merged = mconcat [base, lSortMode, lMissingSort, lNestedFilter]
517 merged = mconcat [base, lSortMode, lMissingSort, lNestedFilter]
518
518
519− toJSON (GeoDistanceSortSpec sortOrder (GeoPoint (FieldName field) latLon) units) =
519+ toJSON (GeoDistanceSortSpec gdsSortOrder (GeoPoint (FieldName field) gdsLatLon) units) =
520 object [ "unit" .= toJSON units
520 object [ "unit" .= toJSON units
521− , field .= toJSON latLon
521+ , field .= toJSON gdsLatLon
522− , "order" .= toJSON sortOrder ]
522+ , "order" .= toJSON gdsSortOrder ]
523
523
524
524
525instance ToJSON SortOrder where
525instance ToJSON SortOrder where
@@ -548,10 +548,10 @@ instance ToJSON ScoreType where
548
548
549
549
550instance ToJSON Distance where
550instance ToJSON Distance where
551− toJSON (Distance coefficient unit) =
551+ toJSON (Distance dCoefficient dUnit) =
552 String boltedTogether where
552 String boltedTogether where
553− coefText = showText coefficient
553+ coefText = showText dCoefficient
554− (String unitText) = (toJSON unit)
554+ (String unitText) = toJSON dUnit
555 boltedTogether = mappend coefText unitText
555 boltedTogether = mappend coefText unitText
556
556
557
557
@@ -579,8 +579,9 @@ instance ToJSON OptimizeBbox where
579
579
580
580
581instance ToJSON GeoBoundingBoxConstraint where
581instance ToJSON GeoBoundingBoxConstraint where
582− toJSON (GeoBoundingBoxConstraint (FieldName geoBBField) constraintBox cache) =
582+ toJSON (GeoBoundingBoxConstraint
583− object [geoBBField .= toJSON constraintBox
583+ (FieldName gbbcGeoBBField) gbbcConstraintBox cache) =
584+ object [gbbcGeoBBField .= toJSON gbbcConstraintBox
584 , "_cache" .= cache]
585 , "_cache" .= cache]
585
586
586
587
@@ -590,15 +591,15 @@ instance ToJSON GeoFilterType where
590
591
591
592
592instance ToJSON GeoBoundingBox where
593instance ToJSON GeoBoundingBox where
593− toJSON (GeoBoundingBox topLeft bottomRight) =
594+ toJSON (GeoBoundingBox gbbTopLeft gbbBottomRight) =
594− object ["top_left" .= toJSON topLeft
595+ object ["top_left" .= toJSON gbbTopLeft
595− , "bottom_right" .= toJSON bottomRight]
596+ , "bottom_right" .= toJSON gbbBottomRight]
596
597
597
598
598instance ToJSON LatLon where
599instance ToJSON LatLon where
599− toJSON (LatLon lat lon) =
600+ toJSON (LatLon lLat lLon) =
600− object ["lat" .= lat
601+ object ["lat" .= lLat
601− , "lon" .= lon]
602+ , "lon" .= lLon]
602
603
603
604
604-- index for smaller ranges, fielddata for longer ranges
605-- index for smaller ranges, fielddata for longer ranges