module Network.AWS.CloudSearchDomains.Types
(
CloudSearchDomains
, JSONError
, SearchStatus
, searchStatus
, ssRid
, ssTimems
, QueryParser (..)
, Hit
, hit
, hitFields
, hitHighlights
, hitId
, SuggestStatus
, suggestStatus
, ss1Rid
, ss1Timems
, Bucket
, bucket
, bCount
, bValue
, SuggestionMatch
, suggestionMatch
, smId
, smScore
, smSuggestion
, BucketInfo
, bucketInfo
, biBuckets
, DocumentServiceWarning
, documentServiceWarning
, dswMessage
, SuggestModel
, suggestModel
, smFound
, smQuery
, smSuggestions
, Hits
, hits
, hCursor
, hFound
, hHit
, hStart
, ContentType (..)
) where
import Network.AWS.Prelude
import Network.AWS.Signing
import qualified GHC.Exts
data CloudSearchDomains
instance AWSService CloudSearchDomains where
type Sg CloudSearchDomains = V4
type Er CloudSearchDomains = JSONError
service = service'
where
service' :: Service CloudSearchDomains
service' = Service
{ _svcAbbrev = "CloudSearchDomains"
, _svcPrefix = "cloudsearchdomain"
, _svcVersion = "2013-01-01"
, _svcTargetPrefix = Nothing
, _svcJSONVersion = Just "1.1"
, _svcHandle = handle
, _svcRetry = retry
}
handle :: Status
-> Maybe (LazyByteString -> ServiceError JSONError)
handle = jsonError statusSuccess service'
retry :: Retry CloudSearchDomains
retry = Exponential
{ _retryBase = 0.05
, _retryGrowth = 2
, _retryAttempts = 5
, _retryCheck = check
}
check :: Status
-> JSONError
-> Bool
check (statusCode -> s) (awsErrorCode -> e)
| s == 500 = True
| s == 509 = True
| s == 503 = True
| otherwise = False
data SearchStatus = SearchStatus
{ _ssRid :: Maybe Text
, _ssTimems :: Maybe Integer
} deriving (Eq, Ord, Read, Show)
searchStatus :: SearchStatus
searchStatus = SearchStatus
{ _ssTimems = Nothing
, _ssRid = Nothing
}
ssRid :: Lens' SearchStatus (Maybe Text)
ssRid = lens _ssRid (\s a -> s { _ssRid = a })
ssTimems :: Lens' SearchStatus (Maybe Integer)
ssTimems = lens _ssTimems (\s a -> s { _ssTimems = a })
instance FromJSON SearchStatus where
parseJSON = withObject "SearchStatus" $ \o -> SearchStatus
<$> o .:? "rid"
<*> o .:? "timems"
instance ToJSON SearchStatus where
toJSON SearchStatus{..} = object
[ "timems" .= _ssTimems
, "rid" .= _ssRid
]
data QueryParser
= Dismax
| Lucene
| Simple
| Structured
deriving (Eq, Ord, Read, Show, Generic, Enum)
instance Hashable QueryParser
instance FromText QueryParser where
parser = takeLowerText >>= \case
"dismax" -> pure Dismax
"lucene" -> pure Lucene
"simple" -> pure Simple
"structured" -> pure Structured
e -> fail $
"Failure parsing QueryParser from " ++ show e
instance ToText QueryParser where
toText = \case
Dismax -> "dismax"
Lucene -> "lucene"
Simple -> "simple"
Structured -> "structured"
instance ToByteString QueryParser
instance ToHeader QueryParser
instance ToQuery QueryParser
instance FromJSON QueryParser where
parseJSON = parseJSONText "QueryParser"
instance ToJSON QueryParser where
toJSON = toJSONText
data Hit = Hit
{ _hitFields :: Map Text (List "fields" Text)
, _hitHighlights :: Map Text Text
, _hitId :: Maybe Text
} deriving (Eq, Read, Show)
hit :: Hit
hit = Hit
{ _hitId = Nothing
, _hitFields = mempty
, _hitHighlights = mempty
}
hitFields :: Lens' Hit (HashMap Text [Text])
hitFields = lens _hitFields (\s a -> s { _hitFields = a }) . _Map
hitHighlights :: Lens' Hit (HashMap Text Text)
hitHighlights = lens _hitHighlights (\s a -> s { _hitHighlights = a }) . _Map
hitId :: Lens' Hit (Maybe Text)
hitId = lens _hitId (\s a -> s { _hitId = a })
instance FromJSON Hit where
parseJSON = withObject "Hit" $ \o -> Hit
<$> o .:? "fields" .!= mempty
<*> o .:? "highlights" .!= mempty
<*> o .:? "id"
instance ToJSON Hit where
toJSON Hit{..} = object
[ "id" .= _hitId
, "fields" .= _hitFields
, "highlights" .= _hitHighlights
]
data SuggestStatus = SuggestStatus
{ _ss1Rid :: Maybe Text
, _ss1Timems :: Maybe Integer
} deriving (Eq, Ord, Read, Show)
suggestStatus :: SuggestStatus
suggestStatus = SuggestStatus
{ _ss1Timems = Nothing
, _ss1Rid = Nothing
}
ss1Rid :: Lens' SuggestStatus (Maybe Text)
ss1Rid = lens _ss1Rid (\s a -> s { _ss1Rid = a })
ss1Timems :: Lens' SuggestStatus (Maybe Integer)
ss1Timems = lens _ss1Timems (\s a -> s { _ss1Timems = a })
instance FromJSON SuggestStatus where
parseJSON = withObject "SuggestStatus" $ \o -> SuggestStatus
<$> o .:? "rid"
<*> o .:? "timems"
instance ToJSON SuggestStatus where
toJSON SuggestStatus{..} = object
[ "timems" .= _ss1Timems
, "rid" .= _ss1Rid
]
data Bucket = Bucket
{ _bCount :: Maybe Integer
, _bValue :: Maybe Text
} deriving (Eq, Ord, Read, Show)
bucket :: Bucket
bucket = Bucket
{ _bValue = Nothing
, _bCount = Nothing
}
bCount :: Lens' Bucket (Maybe Integer)
bCount = lens _bCount (\s a -> s { _bCount = a })
bValue :: Lens' Bucket (Maybe Text)
bValue = lens _bValue (\s a -> s { _bValue = a })
instance FromJSON Bucket where
parseJSON = withObject "Bucket" $ \o -> Bucket
<$> o .:? "count"
<*> o .:? "value"
instance ToJSON Bucket where
toJSON Bucket{..} = object
[ "value" .= _bValue
, "count" .= _bCount
]
data SuggestionMatch = SuggestionMatch
{ _smId :: Maybe Text
, _smScore :: Maybe Integer
, _smSuggestion :: Maybe Text
} deriving (Eq, Ord, Read, Show)
suggestionMatch :: SuggestionMatch
suggestionMatch = SuggestionMatch
{ _smSuggestion = Nothing
, _smScore = Nothing
, _smId = Nothing
}
smId :: Lens' SuggestionMatch (Maybe Text)
smId = lens _smId (\s a -> s { _smId = a })
smScore :: Lens' SuggestionMatch (Maybe Integer)
smScore = lens _smScore (\s a -> s { _smScore = a })
smSuggestion :: Lens' SuggestionMatch (Maybe Text)
smSuggestion = lens _smSuggestion (\s a -> s { _smSuggestion = a })
instance FromJSON SuggestionMatch where
parseJSON = withObject "SuggestionMatch" $ \o -> SuggestionMatch
<$> o .:? "id"
<*> o .:? "score"
<*> o .:? "suggestion"
instance ToJSON SuggestionMatch where
toJSON SuggestionMatch{..} = object
[ "suggestion" .= _smSuggestion
, "score" .= _smScore
, "id" .= _smId
]
newtype BucketInfo = BucketInfo
{ _biBuckets :: List "buckets" Bucket
} deriving (Eq, Read, Show, Monoid, Semigroup)
instance GHC.Exts.IsList BucketInfo where
type Item BucketInfo = Bucket
fromList = BucketInfo . GHC.Exts.fromList
toList = GHC.Exts.toList . _biBuckets
bucketInfo :: BucketInfo
bucketInfo = BucketInfo
{ _biBuckets = mempty
}
biBuckets :: Lens' BucketInfo [Bucket]
biBuckets = lens _biBuckets (\s a -> s { _biBuckets = a }) . _List
instance FromJSON BucketInfo where
parseJSON = withObject "BucketInfo" $ \o -> BucketInfo
<$> o .:? "buckets" .!= mempty
instance ToJSON BucketInfo where
toJSON BucketInfo{..} = object
[ "buckets" .= _biBuckets
]
newtype DocumentServiceWarning = DocumentServiceWarning
{ _dswMessage :: Maybe Text
} deriving (Eq, Ord, Read, Show, Monoid)
documentServiceWarning :: DocumentServiceWarning
documentServiceWarning = DocumentServiceWarning
{ _dswMessage = Nothing
}
dswMessage :: Lens' DocumentServiceWarning (Maybe Text)
dswMessage = lens _dswMessage (\s a -> s { _dswMessage = a })
instance FromJSON DocumentServiceWarning where
parseJSON = withObject "DocumentServiceWarning" $ \o -> DocumentServiceWarning
<$> o .:? "message"
instance ToJSON DocumentServiceWarning where
toJSON DocumentServiceWarning{..} = object
[ "message" .= _dswMessage
]
data SuggestModel = SuggestModel
{ _smFound :: Maybe Integer
, _smQuery :: Maybe Text
, _smSuggestions :: List "suggestions" SuggestionMatch
} deriving (Eq, Read, Show)
suggestModel :: SuggestModel
suggestModel = SuggestModel
{ _smQuery = Nothing
, _smFound = Nothing
, _smSuggestions = mempty
}
smFound :: Lens' SuggestModel (Maybe Integer)
smFound = lens _smFound (\s a -> s { _smFound = a })
smQuery :: Lens' SuggestModel (Maybe Text)
smQuery = lens _smQuery (\s a -> s { _smQuery = a })
smSuggestions :: Lens' SuggestModel [SuggestionMatch]
smSuggestions = lens _smSuggestions (\s a -> s { _smSuggestions = a }) . _List
instance FromJSON SuggestModel where
parseJSON = withObject "SuggestModel" $ \o -> SuggestModel
<$> o .:? "found"
<*> o .:? "query"
<*> o .:? "suggestions" .!= mempty
instance ToJSON SuggestModel where
toJSON SuggestModel{..} = object
[ "query" .= _smQuery
, "found" .= _smFound
, "suggestions" .= _smSuggestions
]
data Hits = Hits
{ _hCursor :: Maybe Text
, _hFound :: Maybe Integer
, _hHit :: List "hit" Hit
, _hStart :: Maybe Integer
} deriving (Eq, Read, Show)
hits :: Hits
hits = Hits
{ _hFound = Nothing
, _hStart = Nothing
, _hCursor = Nothing
, _hHit = mempty
}
hCursor :: Lens' Hits (Maybe Text)
hCursor = lens _hCursor (\s a -> s { _hCursor = a })
hFound :: Lens' Hits (Maybe Integer)
hFound = lens _hFound (\s a -> s { _hFound = a })
hHit :: Lens' Hits [Hit]
hHit = lens _hHit (\s a -> s { _hHit = a }) . _List
hStart :: Lens' Hits (Maybe Integer)
hStart = lens _hStart (\s a -> s { _hStart = a })
instance FromJSON Hits where
parseJSON = withObject "Hits" $ \o -> Hits
<$> o .:? "cursor"
<*> o .:? "found"
<*> o .:? "hit" .!= mempty
<*> o .:? "start"
instance ToJSON Hits where
toJSON Hits{..} = object
[ "found" .= _hFound
, "start" .= _hStart
, "cursor" .= _hCursor
, "hit" .= _hHit
]
data ContentType
= ApplicationJson
| ApplicationXml
deriving (Eq, Ord, Read, Show, Generic, Enum)
instance Hashable ContentType
instance FromText ContentType where
parser = takeLowerText >>= \case
"application/json" -> pure ApplicationJson
"application/xml" -> pure ApplicationXml
e -> fail $
"Failure parsing ContentType from " ++ show e
instance ToText ContentType where
toText = \case
ApplicationJson -> "application/json"
ApplicationXml -> "application/xml"
instance ToByteString ContentType
instance ToHeader ContentType
instance ToQuery ContentType
instance FromJSON ContentType where
parseJSON = parseJSONText "ContentType"
instance ToJSON ContentType where
toJSON = toJSONText