git.iko.soy/typeable/bloodhound
on master help sign in
Merge pull request #171 from bitemyapp/semigroups

Semigroups

commit819ee1416b4e483e471e8ec0c0ee0d6c5179f865 authorMichael Xavier <michael@michaelxavier.net> dateFri 10 Feb 2017, 11:33 (10 years ago) parent1ea188e0e0ed4a
2 files changed+209−196
src/Database/V1/Bloodhound/Types.hs+96−88 src/Database/V5/Bloodhound/Types.hs+113−108
src/Database/V1/Bloodhound/Types.hs+96−88
@@ -365,40 +365,45 @@ module Database.V1.Bloodhound.Types
365365 , EsPassword(..)
366366 ) where
367367
368−import Control.Applicative as A
369−import Control.Arrow (first)
368+import Control.Applicative as A
369+import Control.Arrow (first)
370370import Control.Monad.Catch
371371import Control.Monad.Except
372−import Control.Monad.Reader
373−import Control.Monad.State
374−import Control.Monad.Writer
372+import Control.Monad.Reader (MonadReader (..),
373+ ReaderT (..))
374+import Control.Monad.State (MonadState)
375+import Control.Monad.Writer (MonadWriter)
375376import Data.Aeson
376−import Data.Aeson.Types (Pair, Parser, emptyObject,
377− parseEither, parseMaybe)
378−import qualified Data.ByteString.Lazy.Char8 as L
377+import Data.Aeson.Types (Pair, Parser,
378+ emptyObject,
379+ parseEither, parseMaybe)
380+import qualified Data.ByteString.Lazy.Char8 as L
379381import Data.Char
380−import Data.Hashable (Hashable)
381−import qualified Data.HashMap.Strict as HM
382−import Data.List (foldl', intercalate, nub)
383−import Data.List.NonEmpty (NonEmpty (..), toList)
384−import qualified Data.Map.Strict as M
382+import Data.Hashable (Hashable)
383+import qualified Data.HashMap.Strict as HM
384+import Data.List (foldl', intercalate,
385+ nub)
386+import Data.List.NonEmpty (NonEmpty (..), toList)
387+import qualified Data.Map.Strict as M
385388import Data.Maybe
386−import Data.Scientific (Scientific)
387−import Data.Text (Text)
388−import qualified Data.Text as T
389+import Data.Scientific (Scientific)
390+import Data.Semigroup
391+import Data.Text (Text)
392+import qualified Data.Text as T
389393import Data.Time.Calendar
390−import Data.Time.Clock (NominalDiffTime, UTCTime)
394+import Data.Time.Clock (NominalDiffTime,
395+ UTCTime)
391396import Data.Time.Clock.POSIX
392−import qualified Data.Traversable as DT
393−import Data.Typeable (Typeable)
394−import qualified Data.Vector as V
395−import qualified Data.Version as Vers
397+import qualified Data.Traversable as DT
398+import Data.Typeable (Typeable)
399+import qualified Data.Vector as V
400+import qualified Data.Version as Vers
396401import GHC.Enum
397−import GHC.Generics (Generic)
402+import GHC.Generics (Generic)
398403import Network.HTTP.Client
399−import qualified Network.HTTP.Types.Method as NHTM
400−import qualified Text.ParserCombinators.ReadP as RP
401−import qualified Text.Read as TR
404+import qualified Network.HTTP.Types.Method as NHTM
405+import qualified Text.ParserCombinators.ReadP as RP
406+import qualified Text.Read as TR
402407
403408import Database.V1.Bloodhound.Types.Class
404409import Database.V1.Bloodhound.Types.Internal
@@ -1647,12 +1652,12 @@ data SearchHits a =
16471652 , maxScore :: Score
16481653 , hits :: [Hit a] } deriving (Eq, Read, Show, Generic, Typeable)
16491654
1655+instance Semigroup (SearchHits a) where
1656+ (SearchHits ta ma ha) <> (SearchHits tb mb hb) = SearchHits (ta + tb) (max ma mb) (ha <> hb)
16501657
16511658instance Monoid (SearchHits a) where
16521659 mempty = SearchHits 0 Nothing mempty
1653− mappend (SearchHits ta ma ha) (SearchHits tb mb hb) =
1654− SearchHits (ta + tb) (max ma mb) (ha <> hb)
1655−
1660+ mappend = (<>)
16561661
16571662data Hit a =
16581663 Hit { hitIndex :: IndexName
@@ -1675,7 +1680,7 @@ showText = T.pack . show
16751680readMay :: Read a => String -> Maybe a
16761681readMay s = case reads s of
16771682 (a, ""):_ -> Just a
1678− _ -> Nothing
1683+ _ -> Nothing
16791684
16801685parseReadText :: Read a => Text -> Parser a
16811686parseReadText = maybe mzero return . readMay . T.unpack
@@ -1725,8 +1730,8 @@ data Aggregation = TermsAgg TermsAggregation
17251730 | ValueCountAgg ValueCountAggregation
17261731 | FilterAgg FilterAggregation
17271732 | DateRangeAgg DateRangeAggregation
1728− | MissingAgg MissingAggregation
1729− | TopHitsAgg TopHitsAggregation
1733+ | MissingAgg MissingAggregation
1734+ | TopHitsAgg TopHitsAggregation
17301735 deriving (Eq, Read, Show, Generic, Typeable)
17311736
17321737data TopHitsAggregation = TopHitsAggregation
@@ -1874,11 +1879,11 @@ instance ToJSON Interval where
18741879 toJSON (FractionalInterval fraction interval) = toJSON $ show fraction ++ show interval
18751880
18761881instance Show TimeInterval where
1877− show Weeks = "w"
1878− show Days = "d"
1879− show Hours = "h"
1880− show Minutes = "m"
1881− show Seconds = "s"
1882+ show Weeks = "w"
1883+ show Days = "d"
1884+ show Hours = "h"
1885+ show Minutes = "m"
1886+ show Seconds = "s"
18821887
18831888instance Read TimeInterval where
18841889 readPrec = f =<< TR.get
@@ -1934,7 +1939,7 @@ instance ToJSON Aggregation where
19341939 toJSON (MissingAgg (MissingAggregation{..})) =
19351940 object ["missing" .= object ["field" .= maField]]
19361941
1937− toJSON (TopHitsAgg (TopHitsAggregation mfrom msize msort)) =
1942+ toJSON (TopHitsAgg (TopHitsAggregation mfrom msize msort)) =
19381943 omitNulls ["top_hits" .= omitNulls [ "size" .= msize
19391944 , "from" .= mfrom
19401945 , "sort" .= msort
@@ -1949,22 +1954,22 @@ instance ToJSON DateRangeAggregation where
19491954 ]
19501955
19511956instance ToJSON DateRangeAggRange where
1952− toJSON (DateRangeFrom e) = object [ "from" .= e ]
1953− toJSON (DateRangeTo e) = object [ "to" .= e ]
1957+ toJSON (DateRangeFrom e) = object [ "from" .= e ]
1958+ toJSON (DateRangeTo e) = object [ "to" .= e ]
19541959 toJSON (DateRangeFromAndTo f t) = object [ "from" .= f, "to" .= t ]
19551960
19561961instance ToJSON DateMathExpr where
19571962 toJSON (DateMathExpr a mods) = String (fmtA a <> mconcat (fmtMod <$> mods))
1958− where fmtA DMNow = "now"
1963+ where fmtA DMNow = "now"
19591964 fmtA (DMDate date) = (T.pack $ showGregorian date) <> "||"
1960− fmtMod (AddTime n u) = "+" <> showText n <> fmtU u
1965+ fmtMod (AddTime n u) = "+" <> showText n <> fmtU u
19611966 fmtMod (SubtractTime n u) = "-" <> showText n <> fmtU u
1962− fmtMod (RoundDownTo u) = "/" <> fmtU u
1963− fmtU DMYear = "y"
1964− fmtU DMMonth = "M"
1965− fmtU DMWeek = "w"
1966− fmtU DMDay = "d"
1967− fmtU DMHour = "h"
1967+ fmtMod (RoundDownTo u) = "/" <> fmtU u
1968+ fmtU DMYear = "y"
1969+ fmtU DMMonth = "M"
1970+ fmtU DMWeek = "w"
1971+ fmtU DMDay = "d"
1972+ fmtU DMHour = "h"
19681973 fmtU DMMinute = "m"
19691974 fmtU DMSecond = "s"
19701975
@@ -2044,8 +2049,8 @@ instance (FromJSON a) => FromJSON (Bucket a) where
20442049instance FromJSON BucketValue where
20452050 parseJSON (String t) = return $ TextValue t
20462051 parseJSON (Number s) = return $ ScientificValue s
2047− parseJSON (Bool b) = return $ BoolValue b
2048− parseJSON _ = mempty
2052+ parseJSON (Bool b) = return $ BoolValue b
2053+ parseJSON _ = mempty
20492054
20502055instance FromJSON MissingResult where
20512056 parseJSON = withObject "MissingResult" parse
@@ -2098,9 +2103,12 @@ instance (FromJSON a) => FromJSON (TopHitResult a) where
20982103 v .: "hits"
20992104 parseJSON _ = fail "Failure in FromJSON (TopHitResult a)"
21002105
2106+instance Semigroup Filter where
2107+ a <> b = AndFilter [a, b] defaultCache
2108+
21012109instance Monoid Filter where
21022110 mempty = IdentityFilter
2103− mappend a b = AndFilter [a, b] defaultCache
2111+ mappend = (<>)
21042112
21052113instance Seminearring Filter where
21062114 a <||> b = OrFilter [a, b] defaultCache
@@ -2291,11 +2299,11 @@ fieldTagged f o = case HM.toList o of
22912299 _ -> fail "Expected object with 1 field-named key"
22922300
22932301-- Try to get an AggregationResults when we don't know the
2294−-- field name. We filter out the known keys to try to minimize the noise.
2302+-- field name. We filter out the known keys to try to minimize the noise.
22952303getNamedSubAgg :: Object -> [Text] -> Maybe AggregationResults
22962304getNamedSubAgg o knownKeys = maggRes
22972305 where unknownKeys = HM.filterWithKey (\k _ -> k `notElem` knownKeys) o
2298− maggRes
2306+ maggRes
22992307 | HM.null unknownKeys = Nothing
23002308 | otherwise = Just . M.fromList $ HM.toList unknownKeys
23012309
@@ -2470,9 +2478,9 @@ instance FromJSON Query where
24702478
24712479omitNulls :: [(Text, Value)] -> Value
24722480omitNulls = object . filter notNull where
2473− notNull (_, Null) = False
2481+ notNull (_, Null) = False
24742482 notNull (_, Array a) = (not . V.null) a
2475− notNull _ = True
2483+ notNull _ = True
24762484
24772485
24782486instance ToJSON SimpleQueryStringQuery where
@@ -3025,10 +3033,10 @@ instance FromJSON MultiMatchQuery where
30253033 <*> o .:? "lenient"
30263034
30273035instance ToJSON MultiMatchQueryType where
3028− toJSON MultiMatchBestFields = "best_fields"
3029− toJSON MultiMatchMostFields = "most_fields"
3030− toJSON MultiMatchCrossFields = "cross_fields"
3031− toJSON MultiMatchPhrase = "phrase"
3036+ toJSON MultiMatchBestFields = "best_fields"
3037+ toJSON MultiMatchMostFields = "most_fields"
3038+ toJSON MultiMatchCrossFields = "cross_fields"
3039+ toJSON MultiMatchPhrase = "phrase"
30323040 toJSON MultiMatchPhrasePrefix = "phrase_prefix"
30333041
30343042instance FromJSON MultiMatchQueryType where
@@ -3042,7 +3050,7 @@ instance FromJSON MultiMatchQueryType where
30423050
30433051instance ToJSON BooleanOperator where
30443052 toJSON And = String "and"
3045− toJSON Or = String "or"
3053+ toJSON Or = String "or"
30463054
30473055instance FromJSON BooleanOperator where
30483056 parseJSON = withText "BooleanOperator" parse
@@ -3061,7 +3069,7 @@ instance FromJSON ZeroTermsQuery where
30613069 parse q = fail ("Unexpected ZeroTermsQuery: " <> show q)
30623070
30633071instance ToJSON MatchQueryType where
3064− toJSON MatchPhrase = "phrase"
3072+ toJSON MatchPhrase = "phrase"
30653073 toJSON MatchPhrasePrefix = "phrase_prefix"
30663074
30673075instance FromJSON MatchQueryType where
@@ -3195,7 +3203,7 @@ instance FromJSON IndexSettingsSummary where
31953203 <*> (fmap (filter (not . redundant)) . parseSettings =<< o' .: "settings")
31963204 _ -> fail "Expected single-key object with index name"
31973205 redundant (NumberOfReplicas _) = True
3198− redundant _ = False
3206+ redundant _ = False
31993207
32003208-- | For some reason in several settings APIs, all leaf values get returned
32013209-- as strings. This function attepmts to recover from this for all
@@ -3205,7 +3213,7 @@ unStringlyTypeJSON (String "true") = Bool True
32053213unStringlyTypeJSON (String "false") = Bool False
32063214unStringlyTypeJSON (String "null") = Null
32073215unStringlyTypeJSON v@(String t) = case readMay (T.unpack t) of
3208− Just n -> Number n
3216+ Just n -> Number n
32093217 Nothing -> v
32103218unStringlyTypeJSON v = v
32113219
@@ -3222,7 +3230,7 @@ parseSettings o = do
32223230 return (catMaybes parses)
32233231
32243232oPath :: ToJSON a => NonEmpty Text -> a -> Value
3225−oPath (k :| []) v = object [k .= v]
3233+oPath (k :| []) v = object [k .= v]
32263234oPath (k:| (h:t)) v = object [k .= oPath (h :| t) v]
32273235
32283236attrFilterJSON :: NonEmpty NodeAttrFilter -> Value
@@ -3232,12 +3240,12 @@ attrFilterJSON fs = object [ n .= T.intercalate "," (toList vs)
32323240parseAttrFilter :: Value -> Parser (NonEmpty NodeAttrFilter)
32333241parseAttrFilter = withObject "NonEmpty NodeAttrFilter" parse
32343242 where parse o = case HM.toList o of
3235− [] -> fail "Expected non-empty list of NodeAttrFilters"
3243+ [] -> fail "Expected non-empty list of NodeAttrFilters"
32363244 x:xs -> DT.mapM (uncurry parse') (x :| xs)
32373245 parse' n = withText "Text" $ \t ->
32383246 case T.splitOn "," t of
32393247 fv:fvs -> return (NodeAttrFilter (NodeAttrName n) (fv :| fvs))
3240− [] -> fail "Expected non-empty list of filter values"
3248+ [] -> fail "Expected non-empty list of filter values"
32413249
32423250instance ToJSON ReplicaBounds where
32433251 toJSON (ReplicasBounded a b) = String (showText a <> "-" <> showText b)
@@ -3291,12 +3299,12 @@ instance ToJSON FSType where
32913299
32923300instance FromJSON FSType where
32933301 parseJSON = withText "FSType" parse
3294− where parse "simple" = pure FSSimple
3302+ where parse "simple" = pure FSSimple
32953303 parse "buffered" = pure FSBuffered
3296− parse t = fail ("Invalid FSType: " <> show t)
3304+ parse t = fail ("Invalid FSType: " <> show t)
32973305
32983306instance ToJSON CompoundFormat where
3299− toJSON (CompoundFileFormat x) = Bool x
3307+ toJSON (CompoundFileFormat x) = Bool x
33003308 toJSON (MergeSegmentVsTotalIndex x) = toJSON x
33013309
33023310instance FromJSON CompoundFormat where
@@ -3553,8 +3561,8 @@ instance ToJSON SortMode where
35533561
35543562
35553563instance ToJSON Missing where
3556− toJSON LastMissing = String "_last"
3557− toJSON FirstMissing = String "_first"
3564+ toJSON LastMissing = String "_last"
3565+ toJSON FirstMissing = String "_first"
35583566 toJSON (CustomMissing txt) = String txt
35593567
35603568
@@ -3570,7 +3578,7 @@ instance FromJSON ScoreType where
35703578 parse "avg" = pure ScoreTypeAvg
35713579 parse "sum" = pure ScoreTypeSum
35723580 parse "none" = pure ScoreTypeNone
3573− parse t = fail ("Unexpected ScoreType: " <> show t)
3581+ parse t = fail ("Unexpected ScoreType: " <> show t)
35743582
35753583instance ToJSON Distance where
35763584 toJSON (Distance dCoefficient dUnit) =
@@ -3588,7 +3596,7 @@ instance FromJSON Distance where
35883596 validForNumber '-' = True
35893597 validForNumber '.' = True
35903598 validForNumber 'e' = True
3591− validForNumber c = isNumber c
3599+ validForNumber c = isNumber c
35923600 parseCoeff "" = fail "Empty string cannot be parsed as number"
35933601 parseCoeff s = return (read (T.unpack s))
35943602
@@ -3615,7 +3623,7 @@ instance FromJSON DistanceUnit where
36153623 parse "cm" = pure Centimeters
36163624 parse "mm" = pure Millimeters
36173625 parse "nmi" = pure NauticalMiles
3618− parse u = fail ("Unrecognized DistanceUnit: " <> show u)
3626+ parse u = fail ("Unrecognized DistanceUnit: " <> show u)
36193627
36203628instance ToJSON DistanceType where
36213629 toJSON Arc = String "arc"
@@ -3624,21 +3632,21 @@ instance ToJSON DistanceType where
36243632
36253633instance FromJSON DistanceType where
36263634 parseJSON = withText "DistanceType" parse
3627− where parse "arc" = pure Arc
3635+ where parse "arc" = pure Arc
36283636 parse "sloppy_arc" = pure SloppyArc
3629− parse "plane" = pure Plane
3630− parse t = fail ("Unrecognized DistanceType: " <> show t)
3637+ parse "plane" = pure Plane
3638+ parse t = fail ("Unrecognized DistanceType: " <> show t)
36313639
36323640
36333641instance ToJSON OptimizeBbox where
3634− toJSON NoOptimizeBbox = String "none"
3642+ toJSON NoOptimizeBbox = String "none"
36353643 toJSON (OptimizeGeoFilterType gft) = toJSON gft
36363644
36373645instance FromJSON OptimizeBbox where
36383646 parseJSON v = withText "NoOptimizeBbox" parseNoOptimize v
36393647 <|> parseOptimize v
36403648 where parseNoOptimize "none" = pure NoOptimizeBbox
3641− parseNoOptimize _ = mzero
3649+ parseNoOptimize _ = mzero
36423650 parseOptimize = fmap OptimizeGeoFilterType . parseJSON
36433651
36443652instance ToJSON GeoBoundingBoxConstraint where
@@ -4431,7 +4439,7 @@ instance SnapshotRepo FsSnapshotRepo where
44314439
44324440parseRepo :: Parser a -> Either SnapshotRepoConversionError a
44334441parseRepo parser = case parseEither (const parser) () of
4434− Left e -> Left (OtherRepoConversionError (T.pack e))
4442+ Left e -> Left (OtherRepoConversionError (T.pack e))
44354443 Right a -> Right a
44364444
44374445
@@ -4957,7 +4965,7 @@ instance FromJSON NodeIndicesStats where
49574965 where
49584966 parse o = do
49594967 let (.::) mv k = case mv of
4960− Just v -> Just <$> v .: k
4968+ Just v -> Just <$> v .: k
49614969 Nothing -> pure Nothing
49624970 mRecovery <- o .:? "recovery"
49634971 mQueryCache <- o .:? "query_cache"
@@ -5208,8 +5216,8 @@ parseStringInterval s = case span isNumber s of
52085216 ("", _) -> fail "Invalid interval"
52095217 (nS, unitS) -> case (readMay nS, readMay unitS) of
52105218 (Just n, Just unit) -> return (fromInteger (n * unitNDT unit))
5211− (Nothing, _) -> fail "Invalid interval number"
5212− (_, Nothing) -> fail "Invalid interval unit"
5219+ (Nothing, _) -> fail "Invalid interval number"
5220+ (_, Nothing) -> fail "Invalid interval unit"
52135221 where
52145222 unitNDT Seconds = 1
52155223 unitNDT Minutes = 60
@@ -5228,8 +5236,8 @@ instance FromJSON ThreadPoolSize where
52285236 parseAsString = withText "ThreadPoolSize" $ \t ->
52295237 case first (readMay . T.unpack) (T.span isNumber t) of
52305238 (Just n, "k") -> return (ThreadPoolBounded (n * 1000))
5231− (Just n, "") -> return (ThreadPoolBounded n)
5232− _ -> fail ("Invalid thread pool size " <> T.unpack t)
5239+ (Just n, "") -> return (ThreadPoolBounded n)
5240+ _ -> fail ("Invalid thread pool size " <> T.unpack t)
52335241
52345242instance FromJSON ThreadPoolType where
52355243 parseJSON = withText "ThreadPoolType" parse
@@ -5244,10 +5252,10 @@ instance FromJSON NodeTransportInfo where
52445252 where
52455253 parse o = NodeTransportInfo <$> (maybe (return mempty) parseProfiles =<< o .:? "profiles")
52465254 <*> parseJSON (Object o)
5247− parseProfiles (Object o) | HM.null o = return []
5255+ parseProfiles (Object o) | HM.null o = return []
52485256 parseProfiles v@(Array _) = parseJSON v
5249− parseProfiles Null = return []
5250− parseProfiles _ = fail "Could not parse profiles"
5257+ parseProfiles Null = return []
5258+ parseProfiles _ = fail "Could not parse profiles"
52515259
52525260instance FromJSON NodeNetworkInfo where
52535261 parseJSON = withObject "NodeNetworkInfo" parse
@@ -5268,4 +5276,4 @@ newtype MaybeNA a = MaybeNA { unMaybeNA :: Maybe a }
52685276
52695277instance FromJSON a => FromJSON (MaybeNA a) where
52705278 parseJSON (String "NA") = pure $ MaybeNA Nothing
5271− parseJSON o = MaybeNA . Just <$> parseJSON o
5279+ parseJSON o = MaybeNA . Just <$> parseJSON o
src/Database/V5/Bloodhound/Types.hs+113−108
@@ -364,40 +364,45 @@ module Database.V5.Bloodhound.Types
364364 , EsPassword(..)
365365 ) where
366366
367−import Control.Applicative as A
368−import Control.Arrow (first)
367+import Control.Applicative as A
368+import Control.Arrow (first)
369369import Control.Monad.Catch
370370import Control.Monad.Except
371−import Control.Monad.Reader
372−import Control.Monad.State
373−import Control.Monad.Writer
371+import Control.Monad.Reader (MonadReader (..),
372+ ReaderT (..))
373+import Control.Monad.State (MonadState)
374+import Control.Monad.Writer (MonadWriter)
374375import Data.Aeson
375−import Data.Aeson.Types (Pair, Parser, emptyObject,
376− parseEither, parseMaybe)
377−import qualified Data.ByteString.Lazy.Char8 as L
376+import Data.Aeson.Types (Pair, Parser,
377+ emptyObject,
378+ parseEither, parseMaybe)
379+import qualified Data.ByteString.Lazy.Char8 as L
378380import Data.Char
379−import Data.Hashable (Hashable)
380−import qualified Data.HashMap.Strict as HM
381−import Data.List (foldl', intercalate, nub)
382−import Data.List.NonEmpty (NonEmpty (..), toList)
383−import qualified Data.Map.Strict as M
381+import Data.Hashable (Hashable)
382+import qualified Data.HashMap.Strict as HM
383+import Data.List (foldl', intercalate,
384+ nub)
385+import Data.List.NonEmpty (NonEmpty (..), toList)
386+import qualified Data.Map.Strict as M
384387import Data.Maybe
385−import Data.Scientific (Scientific)
386−import Data.Text (Text)
387−import qualified Data.Text as T
388+import Data.Scientific (Scientific)
389+import Data.Semigroup
390+import Data.Text (Text)
391+import qualified Data.Text as T
388392import Data.Time.Calendar
389−import Data.Time.Clock (NominalDiffTime, UTCTime)
393+import Data.Time.Clock (NominalDiffTime,
394+ UTCTime)
390395import Data.Time.Clock.POSIX
391−import qualified Data.Traversable as DT
392−import Data.Typeable (Typeable)
393−import qualified Data.Vector as V
394−import qualified Data.Version as Vers
396+import qualified Data.Traversable as DT
397+import Data.Typeable (Typeable)
398+import qualified Data.Vector as V
399+import qualified Data.Version as Vers
395400import GHC.Enum
396−import GHC.Generics (Generic)
401+import GHC.Generics (Generic)
397402import Network.HTTP.Client
398−import qualified Network.HTTP.Types.Method as NHTM
399−import qualified Text.ParserCombinators.ReadP as RP
400−import qualified Text.Read as TR
403+import qualified Network.HTTP.Types.Method as NHTM
404+import qualified Text.ParserCombinators.ReadP as RP
405+import qualified Text.Read as TR
401406
402407import Database.V5.Bloodhound.Types.Class
403408import Database.V5.Bloodhound.Types.Internal
@@ -452,11 +457,11 @@ runBH :: BHEnv -> BH m a -> m a
452457runBH e f = runReaderT (unBH f) e
453458
454459{-| 'Version' is embedded in 'Status' -}
455−data Version = Version { number :: VersionNumber
456− , build_hash :: BuildHash
457− , build_date :: UTCTime
458− , build_snapshot :: Bool
459− , lucene_version :: VersionNumber } deriving (Eq, Read, Show, Generic, Typeable)
460+data Version = Version { number :: VersionNumber
461+ , build_hash :: BuildHash
462+ , build_date :: UTCTime
463+ , build_snapshot :: Bool
464+ , lucene_version :: VersionNumber } deriving (Eq, Read, Show, Generic, Typeable)
460465
461466-- | Traditional software versioning number
462467newtype VersionNumber = VersionNumber { versionNumber :: Vers.Version
@@ -494,7 +499,7 @@ defaultIndexSettings = IndexSettings (ShardCount 3) (ReplicaCount 2)
494499 for more info.
495500-}
496501data ForceMergeIndexSettings =
497− ForceMergeIndexSettings { maxNumSegments :: Maybe Int
502+ ForceMergeIndexSettings { maxNumSegments :: Maybe Int
498503 -- ^ Number of segments to optimize to. 1 will fully optimize the index. If omitted, the default behavior is to only optimize if the server deems it necessary.
499504 , onlyExpungeDeletes :: Bool
500505 -- ^ Should the optimize process only expunge segments with deletes in them? If the purpose of the optimization is to free disk space, this should be set to True.
@@ -847,8 +852,8 @@ data SortSpec = DefaultSortSpec DefaultSort
847852{-| 'DefaultSort' is usually the kind of 'SortSpec' you'll want. There's a
848853 'mkSort' convenience function for when you want to specify only the most
849854 common parameters.
850−
851− The `ignoreUnmapped`, when `Just` field is used to set the elastic 'unmapped_type'
855+
856+ The `ignoreUnmapped`, when `Just` field is used to set the elastic 'unmapped_type'
852857
853858<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#search-request-sort>
854859-}
@@ -1206,7 +1211,7 @@ data Query =
12061211 deriving (Eq, Read, Show, Generic, Typeable)
12071212
12081213-- | As of Elastic 2.0, 'Filters' are just 'Queries' housed in a Bool Query, and
1209−-- flagged in a different context.
1214+-- flagged in a different context.
12101215newtype Filter = Filter { unFilter :: Query }
12111216 deriving (Eq, Read, Show, Generic, Typeable)
12121217
@@ -1465,8 +1470,8 @@ data BoolQuery =
14651470 } deriving (Eq, Read, Show, Generic, Typeable)
14661471
14671472mkBoolQuery :: [Query] -> [Filter] -> [Query] -> [Query] -> BoolQuery
1468−mkBoolQuery must filter mustNot should =
1469− BoolQuery must filter mustNot should Nothing Nothing Nothing
1473+mkBoolQuery must filt mustNot should =
1474+ BoolQuery must filt mustNot should Nothing Nothing Nothing
14701475
14711476data BoostingQuery =
14721477 BoostingQuery { positiveQuery :: Query
@@ -1631,12 +1636,12 @@ data SearchHits a =
16311636 , maxScore :: Score
16321637 , hits :: [Hit a] } deriving (Eq, Read, Show, Generic, Typeable)
16331638
1639+instance Semigroup (SearchHits a) where
1640+ (SearchHits ta ma ha) <> (SearchHits tb mb hb) = SearchHits (ta + tb) (max ma mb) (ha <> hb)
16341641
16351642instance Monoid (SearchHits a) where
16361643 mempty = SearchHits 0 Nothing mempty
1637− mappend (SearchHits ta ma ha) (SearchHits tb mb hb) =
1638− SearchHits (ta + tb) (max ma mb) (ha <> hb)
1639−
1644+ mappend = (<>)
16401645
16411646data Hit a =
16421647 Hit { hitIndex :: IndexName
@@ -1659,7 +1664,7 @@ showText = T.pack . show
16591664readMay :: Read a => String -> Maybe a
16601665readMay s = case reads s of
16611666 (a, ""):_ -> Just a
1662− _ -> Nothing
1667+ _ -> Nothing
16631668
16641669parseReadText :: Read a => Text -> Parser a
16651670parseReadText = maybe mzero return . readMay . T.unpack
@@ -1708,8 +1713,8 @@ data Aggregation = TermsAgg TermsAggregation
17081713 | ValueCountAgg ValueCountAggregation
17091714 | FilterAgg FilterAggregation
17101715 | DateRangeAgg DateRangeAggregation
1711− | MissingAgg MissingAggregation
1712− | TopHitsAgg TopHitsAggregation
1716+ | MissingAgg MissingAggregation
1717+ | TopHitsAgg TopHitsAggregation
17131718 deriving (Eq, Read, Show, Generic, Typeable)
17141719
17151720data TopHitsAggregation = TopHitsAggregation
@@ -1846,21 +1851,21 @@ instance ToJSON ExecutionHint where
18461851 toJSON Map = "map"
18471852
18481853instance ToJSON Interval where
1849− toJSON Year = "year"
1854+ toJSON Year = "year"
18501855 toJSON Quarter = "quarter"
1851− toJSON Month = "month"
1852− toJSON Week = "week"
1853− toJSON Day = "day"
1854− toJSON Hour = "hour"
1855− toJSON Minute = "minute"
1856− toJSON Second = "second"
1856+ toJSON Month = "month"
1857+ toJSON Week = "week"
1858+ toJSON Day = "day"
1859+ toJSON Hour = "hour"
1860+ toJSON Minute = "minute"
1861+ toJSON Second = "second"
18571862
18581863instance Show TimeInterval where
1859− show Weeks = "w"
1860− show Days = "d"
1861− show Hours = "h"
1862− show Minutes = "m"
1863− show Seconds = "s"
1864+ show Weeks = "w"
1865+ show Days = "d"
1866+ show Hours = "h"
1867+ show Minutes = "m"
1868+ show Seconds = "s"
18641869
18651870instance Read TimeInterval where
18661871 readPrec = f =<< TR.get
@@ -1916,7 +1921,7 @@ instance ToJSON Aggregation where
19161921 toJSON (MissingAgg (MissingAggregation{..})) =
19171922 object ["missing" .= object ["field" .= maField]]
19181923
1919− toJSON (TopHitsAgg (TopHitsAggregation mfrom msize msort)) =
1924+ toJSON (TopHitsAgg (TopHitsAggregation mfrom msize msort)) =
19201925 omitNulls ["top_hits" .= omitNulls [ "size" .= msize
19211926 , "from" .= mfrom
19221927 , "sort" .= msort
@@ -1931,22 +1936,22 @@ instance ToJSON DateRangeAggregation where
19311936 ]
19321937
19331938instance ToJSON DateRangeAggRange where
1934− toJSON (DateRangeFrom e) = object [ "from" .= e ]
1935− toJSON (DateRangeTo e) = object [ "to" .= e ]
1939+ toJSON (DateRangeFrom e) = object [ "from" .= e ]
1940+ toJSON (DateRangeTo e) = object [ "to" .= e ]
19361941 toJSON (DateRangeFromAndTo f t) = object [ "from" .= f, "to" .= t ]
19371942
19381943instance ToJSON DateMathExpr where
19391944 toJSON (DateMathExpr a mods) = String (fmtA a <> mconcat (fmtMod <$> mods))
1940− where fmtA DMNow = "now"
1945+ where fmtA DMNow = "now"
19411946 fmtA (DMDate date) = (T.pack $ showGregorian date) <> "||"
1942− fmtMod (AddTime n u) = "+" <> showText n <> fmtU u
1947+ fmtMod (AddTime n u) = "+" <> showText n <> fmtU u
19431948 fmtMod (SubtractTime n u) = "-" <> showText n <> fmtU u
1944− fmtMod (RoundDownTo u) = "/" <> fmtU u
1945− fmtU DMYear = "y"
1946− fmtU DMMonth = "M"
1947− fmtU DMWeek = "w"
1948− fmtU DMDay = "d"
1949− fmtU DMHour = "h"
1949+ fmtMod (RoundDownTo u) = "/" <> fmtU u
1950+ fmtU DMYear = "y"
1951+ fmtU DMMonth = "M"
1952+ fmtU DMWeek = "w"
1953+ fmtU DMDay = "d"
1954+ fmtU DMHour = "h"
19501955 fmtU DMMinute = "m"
19511956 fmtU DMSecond = "s"
19521957
@@ -2026,8 +2031,8 @@ instance (FromJSON a, BucketAggregation a) => FromJSON (Bucket a) where
20262031instance FromJSON BucketValue where
20272032 parseJSON (String t) = return $ TextValue t
20282033 parseJSON (Number s) = return $ ScientificValue s
2029− parseJSON (Bool b) = return $ BoolValue b
2030− parseJSON _ = mempty
2034+ parseJSON (Bool b) = return $ BoolValue b
2035+ parseJSON _ = mempty
20312036
20322037instance FromJSON MissingResult where
20332038 parseJSON = withObject "MissingResult" parse
@@ -2086,11 +2091,11 @@ fieldTagged f o = case HM.toList o of
20862091 _ -> fail "Expected object with 1 field-named key"
20872092
20882093-- Try to get an AggregationResults when we don't know the
2089−-- field name. We filter out the known keys to try to minimize the noise.
2094+-- field name. We filter out the known keys to try to minimize the noise.
20902095getNamedSubAgg :: Object -> [Text] -> Maybe AggregationResults
20912096getNamedSubAgg o knownKeys = maggRes
20922097 where unknownKeys = HM.filterWithKey (\k _ -> k `notElem` knownKeys) o
2093− maggRes
2098+ maggRes
20942099 | HM.null unknownKeys = Nothing
20952100 | otherwise = Just . M.fromList $ HM.toList unknownKeys
20962101
@@ -2188,7 +2193,7 @@ instance ToJSON Query where
21882193 object ["exists" .= object
21892194 ["field" .= fieldName]
21902195 ]
2191− toJSON QueryMatchNoneQuery =
2196+ toJSON QueryMatchNoneQuery =
21922197 object ["match_none" .= object []]
21932198
21942199instance FromJSON Query where
@@ -2259,9 +2264,9 @@ instance FromJSON Query where
22592264
22602265omitNulls :: [(Text, Value)] -> Value
22612266omitNulls = object . filter notNull where
2262− notNull (_, Null) = False
2267+ notNull (_, Null) = False
22632268 notNull (_, Array a) = (not . V.null) a
2264− notNull _ = True
2269+ notNull _ = True
22652270
22662271instance ToJSON SimpleQueryStringQuery where
22672272 toJSON SimpleQueryStringQuery {..} =
@@ -2804,10 +2809,10 @@ instance FromJSON MultiMatchQuery where
28042809 <*> o .:? "lenient"
28052810
28062811instance ToJSON MultiMatchQueryType where
2807− toJSON MultiMatchBestFields = "best_fields"
2808− toJSON MultiMatchMostFields = "most_fields"
2809− toJSON MultiMatchCrossFields = "cross_fields"
2810− toJSON MultiMatchPhrase = "phrase"
2812+ toJSON MultiMatchBestFields = "best_fields"
2813+ toJSON MultiMatchMostFields = "most_fields"
2814+ toJSON MultiMatchCrossFields = "cross_fields"
2815+ toJSON MultiMatchPhrase = "phrase"
28112816 toJSON MultiMatchPhrasePrefix = "phrase_prefix"
28122817
28132818instance FromJSON MultiMatchQueryType where
@@ -2821,7 +2826,7 @@ instance FromJSON MultiMatchQueryType where
28212826
28222827instance ToJSON BooleanOperator where
28232828 toJSON And = String "and"
2824− toJSON Or = String "or"
2829+ toJSON Or = String "or"
28252830
28262831instance FromJSON BooleanOperator where
28272832 parseJSON = withText "BooleanOperator" parse
@@ -2840,7 +2845,7 @@ instance FromJSON ZeroTermsQuery where
28402845 parse q = fail ("Unexpected ZeroTermsQuery: " <> show q)
28412846
28422847instance ToJSON MatchQueryType where
2843− toJSON MatchPhrase = "phrase"
2848+ toJSON MatchPhrase = "phrase"
28442849 toJSON MatchPhrasePrefix = "phrase_prefix"
28452850
28462851instance FromJSON MatchQueryType where
@@ -2974,7 +2979,7 @@ instance FromJSON IndexSettingsSummary where
29742979 <*> (fmap (filter (not . redundant)) . parseSettings =<< o' .: "settings")
29752980 _ -> fail "Expected single-key object with index name"
29762981 redundant (NumberOfReplicas _) = True
2977− redundant _ = False
2982+ redundant _ = False
29782983
29792984-- | For some reason in several settings APIs, all leaf values get returned
29802985-- as strings. This function attepmts to recover from this for all
@@ -2984,7 +2989,7 @@ unStringlyTypeJSON (String "true") = Bool True
29842989unStringlyTypeJSON (String "false") = Bool False
29852990unStringlyTypeJSON (String "null") = Null
29862991unStringlyTypeJSON v@(String t) = case readMay (T.unpack t) of
2987− Just n -> Number n
2992+ Just n -> Number n
29882993 Nothing -> v
29892994unStringlyTypeJSON v = v
29902995
@@ -3001,7 +3006,7 @@ parseSettings o = do
30013006 return (catMaybes parses)
30023007
30033008oPath :: ToJSON a => NonEmpty Text -> a -> Value
3004−oPath (k :| []) v = object [k .= v]
3009+oPath (k :| []) v = object [k .= v]
30053010oPath (k:| (h:t)) v = object [k .= oPath (h :| t) v]
30063011
30073012attrFilterJSON :: NonEmpty NodeAttrFilter -> Value
@@ -3011,12 +3016,12 @@ attrFilterJSON fs = object [ n .= T.intercalate "," (toList vs)
30113016parseAttrFilter :: Value -> Parser (NonEmpty NodeAttrFilter)
30123017parseAttrFilter = withObject "NonEmpty NodeAttrFilter" parse
30133018 where parse o = case HM.toList o of
3014− [] -> fail "Expected non-empty list of NodeAttrFilters"
3019+ [] -> fail "Expected non-empty list of NodeAttrFilters"
30153020 x:xs -> DT.mapM (uncurry parse') (x :| xs)
30163021 parse' n = withText "Text" $ \t ->
30173022 case T.splitOn "," t of
30183023 fv:fvs -> return (NodeAttrFilter (NodeAttrName n) (fv :| fvs))
3019− [] -> fail "Expected non-empty list of filter values"
3024+ [] -> fail "Expected non-empty list of filter values"
30203025
30213026instance ToJSON ReplicaBounds where
30223027 toJSON (ReplicasBounded a b) = String (showText a <> "-" <> showText b)
@@ -3070,12 +3075,12 @@ instance ToJSON FSType where
30703075
30713076instance FromJSON FSType where
30723077 parseJSON = withText "FSType" parse
3073− where parse "simple" = pure FSSimple
3078+ where parse "simple" = pure FSSimple
30743079 parse "buffered" = pure FSBuffered
3075− parse t = fail ("Invalid FSType: " <> show t)
3080+ parse t = fail ("Invalid FSType: " <> show t)
30763081
30773082instance ToJSON CompoundFormat where
3078− toJSON (CompoundFileFormat x) = Bool x
3083+ toJSON (CompoundFileFormat x) = Bool x
30793084 toJSON (MergeSegmentVsTotalIndex x) = toJSON x
30803085
30813086instance FromJSON CompoundFormat where
@@ -3193,7 +3198,7 @@ instance ToJSON Search where
31933198 , "track_scores" .= sTrackSortScores
31943199 , "fields" .= sFields
31953200 , "_source" .= sSource]
3196−
3201+
31973202 where query' = case sFilter of
31983203 Nothing -> mquery
31993204 Just x -> Just . QueryBoolQuery $ mkBoolQuery (maybeToList mquery) [x] [] []
@@ -3334,8 +3339,8 @@ instance ToJSON SortMode where
33343339
33353340
33363341instance ToJSON Missing where
3337− toJSON LastMissing = String "_last"
3338− toJSON FirstMissing = String "_first"
3342+ toJSON LastMissing = String "_last"
3343+ toJSON FirstMissing = String "_first"
33393344 toJSON (CustomMissing txt) = String txt
33403345
33413346
@@ -3351,7 +3356,7 @@ instance FromJSON ScoreType where
33513356 parse "avg" = pure ScoreTypeAvg
33523357 parse "sum" = pure ScoreTypeSum
33533358 parse "none" = pure ScoreTypeNone
3354− parse t = fail ("Unexpected ScoreType: " <> show t)
3359+ parse t = fail ("Unexpected ScoreType: " <> show t)
33553360
33563361instance ToJSON Distance where
33573362 toJSON (Distance dCoefficient dUnit) =
@@ -3369,7 +3374,7 @@ instance FromJSON Distance where
33693374 validForNumber '-' = True
33703375 validForNumber '.' = True
33713376 validForNumber 'e' = True
3372− validForNumber c = isNumber c
3377+ validForNumber c = isNumber c
33733378 parseCoeff "" = fail "Empty string cannot be parsed as number"
33743379 parseCoeff s = return (read (T.unpack s))
33753380
@@ -3396,7 +3401,7 @@ instance FromJSON DistanceUnit where
33963401 parse "cm" = pure Centimeters
33973402 parse "mm" = pure Millimeters
33983403 parse "nmi" = pure NauticalMiles
3399− parse u = fail ("Unrecognized DistanceUnit: " <> show u)
3404+ parse u = fail ("Unrecognized DistanceUnit: " <> show u)
34003405
34013406instance ToJSON DistanceType where
34023407 toJSON Arc = String "arc"
@@ -3405,21 +3410,21 @@ instance ToJSON DistanceType where
34053410
34063411instance FromJSON DistanceType where
34073412 parseJSON = withText "DistanceType" parse
3408− where parse "arc" = pure Arc
3413+ where parse "arc" = pure Arc
34093414 parse "sloppy_arc" = pure SloppyArc
3410− parse "plane" = pure Plane
3411− parse t = fail ("Unrecognized DistanceType: " <> show t)
3415+ parse "plane" = pure Plane
3416+ parse t = fail ("Unrecognized DistanceType: " <> show t)
34123417
34133418
34143419instance ToJSON OptimizeBbox where
3415− toJSON NoOptimizeBbox = String "none"
3420+ toJSON NoOptimizeBbox = String "none"
34163421 toJSON (OptimizeGeoFilterType gft) = toJSON gft
34173422
34183423instance FromJSON OptimizeBbox where
34193424 parseJSON v = withText "NoOptimizeBbox" parseNoOptimize v
34203425 <|> parseOptimize v
34213426 where parseNoOptimize "none" = pure NoOptimizeBbox
3422− parseNoOptimize _ = mzero
3427+ parseNoOptimize _ = mzero
34233428 parseOptimize = fmap OptimizeGeoFilterType . parseJSON
34243429
34253430instance ToJSON GeoBoundingBoxConstraint where
@@ -4202,7 +4207,7 @@ instance SnapshotRepo FsSnapshotRepo where
42024207
42034208parseRepo :: Parser a -> Either SnapshotRepoConversionError a
42044209parseRepo parser = case parseEither (const parser) () of
4205− Left e -> Left (OtherRepoConversionError (T.pack e))
4210+ Left e -> Left (OtherRepoConversionError (T.pack e))
42064211 Right a -> Right a
42074212
42084213
@@ -4683,7 +4688,7 @@ instance FromJSON NodeProcessStats where
46834688 <*> o .: "open_file_descriptors"
46844689 <*> o .: "max_file_descriptors"
46854690 <*> cpu .: "percent"
4686− <*> (unMS <$> cpu .: "total_in_millis")
4691+ <*> (unMS <$> cpu .: "total_in_millis")
46874692 <*> mem .: "total_virtual_in_bytes"
46884693
46894694instance FromJSON NodeOSStats where
@@ -4720,7 +4725,7 @@ instance FromJSON NodeIndicesStats where
47204725 where
47214726 parse o = do
47224727 let (.::) mv k = case mv of
4723− Just v -> Just <$> v .: k
4728+ Just v -> Just <$> v .: k
47244729 Nothing -> pure Nothing
47254730 mRecovery <- o .:? "recovery"
47264731 mQueryCache <- o .:? "query_cache"
@@ -4965,8 +4970,8 @@ parseStringInterval s = case span isNumber s of
49654970 ("", _) -> fail "Invalid interval"
49664971 (nS, unitS) -> case (readMay nS, readMay unitS) of
49674972 (Just n, Just unit) -> return (fromInteger (n * unitNDT unit))
4968− (Nothing, _) -> fail "Invalid interval number"
4969− (_, Nothing) -> fail "Invalid interval unit"
4973+ (Nothing, _) -> fail "Invalid interval number"
4974+ (_, Nothing) -> fail "Invalid interval unit"
49704975 where
49714976 unitNDT Seconds = 1
49724977 unitNDT Minutes = 60
@@ -4985,8 +4990,8 @@ instance FromJSON ThreadPoolSize where
49854990 parseAsString = withText "ThreadPoolSize" $ \t ->
49864991 case first (readMay . T.unpack) (T.span isNumber t) of
49874992 (Just n, "k") -> return (ThreadPoolBounded (n * 1000))
4988− (Just n, "") -> return (ThreadPoolBounded n)
4989− _ -> fail ("Invalid thread pool size " <> T.unpack t)
4993+ (Just n, "") -> return (ThreadPoolBounded n)
4994+ _ -> fail ("Invalid thread pool size " <> T.unpack t)
49904995
49914996instance FromJSON ThreadPoolType where
49924997 parseJSON = withText "ThreadPoolType" parse
@@ -5001,10 +5006,10 @@ instance FromJSON NodeTransportInfo where
50015006 where
50025007 parse o = NodeTransportInfo <$> (maybe (return mempty) parseProfiles =<< o .:? "profiles")
50035008 <*> parseJSON (Object o)
5004− parseProfiles (Object o) | HM.null o = return []
5009+ parseProfiles (Object o) | HM.null o = return []
50055010 parseProfiles v@(Array _) = parseJSON v
5006− parseProfiles Null = return []
5007− parseProfiles _ = fail "Could not parse profiles"
5011+ parseProfiles Null = return []
5012+ parseProfiles _ = fail "Could not parse profiles"
50085013
50095014instance FromJSON NodeNetworkInfo where
50105015 parseJSON = withObject "NodeNetworkInfo" parse
@@ -5025,4 +5030,4 @@ newtype MaybeNA a = MaybeNA { unMaybeNA :: Maybe a }
50255030
50265031instance FromJSON a => FromJSON (MaybeNA a) where
50275032 parseJSON (String "NA") = pure $ MaybeNA Nothing
5028− parseJSON o = MaybeNA . Just <$> parseJSON o
5033+ parseJSON o = MaybeNA . Just <$> parseJSON o