{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
module Database.V5.Bloodhound.Internal.Newtypes where
import Bloodhound.Import
import qualified Data.Map.Strict as M
newtype From = From Int deriving (Eq, Show, ToJSON)
newtype Size = Size Int deriving (Eq, Show, ToJSON, FromJSON)
newtype HitFields =
HitFields (M.Map Text [Value])
deriving (Eq, Show)
instance FromJSON HitFields where
parseJSON x
= HitFields <$> parseJSON x
type Score = Maybe Double
newtype MappingName =
MappingName Text
deriving (Eq, Show, ToJSON, FromJSON)
newtype ShardId = ShardId { shardId :: Int }
deriving (Eq, Show, FromJSON)
newtype DocId =
DocId Text
deriving (Eq, Show, ToJSON, FromJSON)
newtype FieldName =
FieldName Text
deriving (Eq, Read, Show, ToJSON, FromJSON)
newtype TypeName =
TypeName Text
deriving (Eq, Show, ToJSON, FromJSON)
newtype QueryString =
QueryString Text
deriving (Eq, Show, ToJSON, FromJSON)
newtype CacheName =
CacheName Text
deriving (Eq, Show, FromJSON, ToJSON)
newtype CacheKey =
CacheKey Text deriving (Eq, Show, FromJSON, ToJSON)
newtype Existence =
Existence Bool deriving (Eq, Show, FromJSON, ToJSON)
newtype NullValue =
NullValue Bool deriving (Eq, Show, FromJSON, ToJSON)
newtype CutoffFrequency =
CutoffFrequency Double deriving (Eq, Show, FromJSON, ToJSON)
newtype Analyzer =
Analyzer Text deriving (Eq, Show, FromJSON, ToJSON)
newtype MaxExpansions =
MaxExpansions Int deriving (Eq, Show, FromJSON, ToJSON)
newtype Lenient =
Lenient Bool deriving (Eq, Show, FromJSON, ToJSON)
newtype Tiebreaker =
Tiebreaker Double deriving (Eq, Show, FromJSON, ToJSON)
newtype MinimumMatch =
MinimumMatch Int deriving (Eq, Show, FromJSON, ToJSON)
newtype DisableCoord =
DisableCoord Bool deriving (Eq, Show, FromJSON, ToJSON)
newtype IgnoreTermFrequency =
IgnoreTermFrequency Bool deriving (Eq, Show, FromJSON, ToJSON)
newtype MinimumTermFrequency =
MinimumTermFrequency Int deriving (Eq, Show, FromJSON, ToJSON)
newtype MaxQueryTerms =
MaxQueryTerms Int deriving (Eq, Show, FromJSON, ToJSON)
newtype Fuzziness =
Fuzziness Double deriving (Eq, Show, FromJSON, ToJSON)
newtype PrefixLength =
PrefixLength Int deriving (Eq, Show, FromJSON, ToJSON)
newtype PercentMatch =
PercentMatch Double deriving (Eq, Show, FromJSON, ToJSON)
newtype StopWord =
StopWord Text deriving (Eq, Show, FromJSON, ToJSON)
newtype QueryPath =
QueryPath Text deriving (Eq, Show, FromJSON, ToJSON)
newtype AllowLeadingWildcard =
AllowLeadingWildcard Bool deriving (Eq, Show, FromJSON, ToJSON)
newtype LowercaseExpanded =
LowercaseExpanded Bool deriving (Eq, Show, FromJSON, ToJSON)
newtype EnablePositionIncrements =
EnablePositionIncrements Bool deriving (Eq, Show, FromJSON, ToJSON)
newtype AnalyzeWildcard = AnalyzeWildcard Bool deriving (Eq, Show, FromJSON, ToJSON)
newtype GeneratePhraseQueries =
GeneratePhraseQueries Bool deriving (Eq, Show, FromJSON, ToJSON)
newtype Locale = Locale Text deriving (Eq, Show, FromJSON, ToJSON)
newtype MaxWordLength = MaxWordLength Int deriving (Eq, Show, FromJSON, ToJSON)
newtype MinWordLength = MinWordLength Int deriving (Eq, Show, FromJSON, ToJSON)
newtype PhraseSlop = PhraseSlop Int deriving (Eq, Show, FromJSON, ToJSON)
newtype MinDocFrequency = MinDocFrequency Int deriving (Eq, Show, FromJSON, ToJSON)
newtype MaxDocFrequency = MaxDocFrequency Int deriving (Eq, Show, FromJSON, ToJSON)
newtype POSIXMS = POSIXMS { posixMS :: UTCTime }
instance FromJSON POSIXMS where
parseJSON = withScientific "POSIXMS" (return . parse)
where parse n =
let n' = truncate n :: Integer
in POSIXMS (posixSecondsToUTCTime (fromInteger (n' `div` 1000)))
newtype Boost =
Boost Double
deriving (Eq, Show, ToJSON, FromJSON)
newtype BoostTerms =
BoostTerms Double
deriving (Eq, Show, ToJSON, FromJSON)
newtype ReplicaCount =
ReplicaCount Int
deriving (Eq, Show, ToJSON)
newtype ShardCount =
ShardCount Int
deriving (Eq, Show, ToJSON)
instance FromJSON ReplicaCount where
parseJSON v = parseAsInt v
<|> parseAsString v
where parseAsInt = fmap ReplicaCount . parseJSON
parseAsString = withText "ReplicaCount" (fmap ReplicaCount . parseReadText)
instance FromJSON ShardCount where
parseJSON v = parseAsInt v
<|> parseAsString v
where parseAsInt = fmap ShardCount . parseJSON
parseAsString = withText "ShardCount" (fmap ShardCount . parseReadText)
newtype IndexName =
IndexName Text
deriving (Eq, Show, ToJSON, FromJSON)
newtype IndexAliasName =
IndexAliasName { indexAliasName :: IndexName }
deriving (Eq, Show, ToJSON)
newtype MaybeNA a = MaybeNA { unMaybeNA :: Maybe a }
deriving (Show, Eq)
instance FromJSON a => FromJSON (MaybeNA a) where
parseJSON (String "NA") = pure $ MaybeNA Nothing
parseJSON o = MaybeNA . Just <$> parseJSON o
newtype SnapshotName =
SnapshotName { snapshotName :: Text }
deriving (Eq, Show, ToJSON, FromJSON)
newtype MS = MS NominalDiffTime
unMS :: MS -> NominalDiffTime
unMS (MS t) = t
instance FromJSON MS where
parseJSON = withScientific "MS" (return . MS . parse)
where
parse n = fromInteger (truncate n * 1000)
newtype TokenFilter =
TokenFilter Text
deriving (Eq, Show, FromJSON, ToJSON)
newtype CharFilter =
CharFilter Text
deriving (Eq, Show, FromJSON, ToJSON)