{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.CloudSearchDomains.Suggest
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Retrieves autocomplete suggestions for a partial query string. You can
-- use suggestions enable you to display likely matches before users finish
-- typing. In Amazon CloudSearch, suggestions are based on the contents of
-- a particular text field. When you request suggestions, Amazon
-- CloudSearch finds all of the documents whose values in the suggester
-- field start with the specified query string. The beginning of the field
-- must match the query string to be considered a match.
--
-- For more information about configuring suggesters and retrieving
-- suggestions, see
-- <http://docs.aws.amazon.com/cloudsearch/latest/developerguide/getting-suggestions.html Getting Suggestions>
-- in the /Amazon CloudSearch Developer Guide/.
--
-- The endpoint for submitting @Suggest@ requests is domain-specific. You
-- submit suggest requests to a domain\'s search endpoint. To get the
-- search endpoint for your domain, use the Amazon CloudSearch
-- configuration service @DescribeDomains@ action. A domain\'s endpoints
-- are also displayed on the domain dashboard in the Amazon CloudSearch
-- console.
module Amazonka.CloudSearchDomains.Suggest
  ( -- * Creating a Request
    Suggest (..),
    newSuggest,

    -- * Request Lenses
    suggest_size,
    suggest_query,
    suggest_suggester,

    -- * Destructuring the Response
    SuggestResponse (..),
    newSuggestResponse,

    -- * Response Lenses
    suggestResponse_suggest,
    suggestResponse_status,
    suggestResponse_httpStatus,
  )
where

import Amazonka.CloudSearchDomains.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | Container for the parameters to the @Suggest@ request.
--
-- /See:/ 'newSuggest' smart constructor.
data Suggest = Suggest'
  { -- | Specifies the maximum number of suggestions to return.
    Suggest -> Maybe Integer
size :: Prelude.Maybe Prelude.Integer,
    -- | Specifies the string for which you want to get suggestions.
    Suggest -> Text
query :: Prelude.Text,
    -- | Specifies the name of the suggester to use to find suggested matches.
    Suggest -> Text
suggester :: Prelude.Text
  }
  deriving (Suggest -> Suggest -> Bool
(Suggest -> Suggest -> Bool)
-> (Suggest -> Suggest -> Bool) -> Eq Suggest
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Suggest -> Suggest -> Bool
$c/= :: Suggest -> Suggest -> Bool
== :: Suggest -> Suggest -> Bool
$c== :: Suggest -> Suggest -> Bool
Prelude.Eq, ReadPrec [Suggest]
ReadPrec Suggest
Int -> ReadS Suggest
ReadS [Suggest]
(Int -> ReadS Suggest)
-> ReadS [Suggest]
-> ReadPrec Suggest
-> ReadPrec [Suggest]
-> Read Suggest
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Suggest]
$creadListPrec :: ReadPrec [Suggest]
readPrec :: ReadPrec Suggest
$creadPrec :: ReadPrec Suggest
readList :: ReadS [Suggest]
$creadList :: ReadS [Suggest]
readsPrec :: Int -> ReadS Suggest
$creadsPrec :: Int -> ReadS Suggest
Prelude.Read, Int -> Suggest -> ShowS
[Suggest] -> ShowS
Suggest -> String
(Int -> Suggest -> ShowS)
-> (Suggest -> String) -> ([Suggest] -> ShowS) -> Show Suggest
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Suggest] -> ShowS
$cshowList :: [Suggest] -> ShowS
show :: Suggest -> String
$cshow :: Suggest -> String
showsPrec :: Int -> Suggest -> ShowS
$cshowsPrec :: Int -> Suggest -> ShowS
Prelude.Show, (forall x. Suggest -> Rep Suggest x)
-> (forall x. Rep Suggest x -> Suggest) -> Generic Suggest
forall x. Rep Suggest x -> Suggest
forall x. Suggest -> Rep Suggest x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Suggest x -> Suggest
$cfrom :: forall x. Suggest -> Rep Suggest x
Prelude.Generic)

-- |
-- Create a value of 'Suggest' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'size', 'suggest_size' - Specifies the maximum number of suggestions to return.
--
-- 'query', 'suggest_query' - Specifies the string for which you want to get suggestions.
--
-- 'suggester', 'suggest_suggester' - Specifies the name of the suggester to use to find suggested matches.
newSuggest ::
  -- | 'query'
  Prelude.Text ->
  -- | 'suggester'
  Prelude.Text ->
  Suggest
newSuggest :: Text -> Text -> Suggest
newSuggest Text
pQuery_ Text
pSuggester_ =
  Suggest' :: Maybe Integer -> Text -> Text -> Suggest
Suggest'
    { $sel:size:Suggest' :: Maybe Integer
size = Maybe Integer
forall a. Maybe a
Prelude.Nothing,
      $sel:query:Suggest' :: Text
query = Text
pQuery_,
      $sel:suggester:Suggest' :: Text
suggester = Text
pSuggester_
    }

-- | Specifies the maximum number of suggestions to return.
suggest_size :: Lens.Lens' Suggest (Prelude.Maybe Prelude.Integer)
suggest_size :: (Maybe Integer -> f (Maybe Integer)) -> Suggest -> f Suggest
suggest_size = (Suggest -> Maybe Integer)
-> (Suggest -> Maybe Integer -> Suggest)
-> Lens Suggest Suggest (Maybe Integer) (Maybe Integer)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Suggest' {Maybe Integer
size :: Maybe Integer
$sel:size:Suggest' :: Suggest -> Maybe Integer
size} -> Maybe Integer
size) (\s :: Suggest
s@Suggest' {} Maybe Integer
a -> Suggest
s {$sel:size:Suggest' :: Maybe Integer
size = Maybe Integer
a} :: Suggest)

-- | Specifies the string for which you want to get suggestions.
suggest_query :: Lens.Lens' Suggest Prelude.Text
suggest_query :: (Text -> f Text) -> Suggest -> f Suggest
suggest_query = (Suggest -> Text)
-> (Suggest -> Text -> Suggest) -> Lens Suggest Suggest Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Suggest' {Text
query :: Text
$sel:query:Suggest' :: Suggest -> Text
query} -> Text
query) (\s :: Suggest
s@Suggest' {} Text
a -> Suggest
s {$sel:query:Suggest' :: Text
query = Text
a} :: Suggest)

-- | Specifies the name of the suggester to use to find suggested matches.
suggest_suggester :: Lens.Lens' Suggest Prelude.Text
suggest_suggester :: (Text -> f Text) -> Suggest -> f Suggest
suggest_suggester = (Suggest -> Text)
-> (Suggest -> Text -> Suggest) -> Lens Suggest Suggest Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Suggest' {Text
suggester :: Text
$sel:suggester:Suggest' :: Suggest -> Text
suggester} -> Text
suggester) (\s :: Suggest
s@Suggest' {} Text
a -> Suggest
s {$sel:suggester:Suggest' :: Text
suggester = Text
a} :: Suggest)

instance Core.AWSRequest Suggest where
  type AWSResponse Suggest = SuggestResponse
  request :: Suggest -> Request Suggest
request = Service -> Suggest -> Request Suggest
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy Suggest
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse Suggest)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse Suggest))
-> Logger
-> Service
-> Proxy Suggest
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse Suggest)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe SuggestModel -> Maybe SuggestStatus -> Int -> SuggestResponse
SuggestResponse'
            (Maybe SuggestModel
 -> Maybe SuggestStatus -> Int -> SuggestResponse)
-> Either String (Maybe SuggestModel)
-> Either String (Maybe SuggestStatus -> Int -> SuggestResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe SuggestModel)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"suggest")
            Either String (Maybe SuggestStatus -> Int -> SuggestResponse)
-> Either String (Maybe SuggestStatus)
-> Either String (Int -> SuggestResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe SuggestStatus)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"status")
            Either String (Int -> SuggestResponse)
-> Either String Int -> Either String SuggestResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable Suggest

instance Prelude.NFData Suggest

instance Core.ToHeaders Suggest where
  toHeaders :: Suggest -> ResponseHeaders
toHeaders =
    ResponseHeaders -> Suggest -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToPath Suggest where
  toPath :: Suggest -> ByteString
toPath = ByteString -> Suggest -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/2013-01-01/suggest"

instance Core.ToQuery Suggest where
  toQuery :: Suggest -> QueryString
toQuery Suggest' {Maybe Integer
Text
suggester :: Text
query :: Text
size :: Maybe Integer
$sel:suggester:Suggest' :: Suggest -> Text
$sel:query:Suggest' :: Suggest -> Text
$sel:size:Suggest' :: Suggest -> Maybe Integer
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"size" ByteString -> Maybe Integer -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Integer
size,
        ByteString
"q" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
query,
        ByteString
"suggester" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
suggester,
        QueryString
"format=sdk&pretty=true"
      ]

-- | Contains the response to a @Suggest@ request.
--
-- /See:/ 'newSuggestResponse' smart constructor.
data SuggestResponse = SuggestResponse'
  { -- | Container for the matching search suggestion information.
    SuggestResponse -> Maybe SuggestModel
suggest :: Prelude.Maybe SuggestModel,
    -- | The status of a @SuggestRequest@. Contains the resource ID (@rid@) and
    -- how long it took to process the request (@timems@).
    SuggestResponse -> Maybe SuggestStatus
status :: Prelude.Maybe SuggestStatus,
    -- | The response's http status code.
    SuggestResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (SuggestResponse -> SuggestResponse -> Bool
(SuggestResponse -> SuggestResponse -> Bool)
-> (SuggestResponse -> SuggestResponse -> Bool)
-> Eq SuggestResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SuggestResponse -> SuggestResponse -> Bool
$c/= :: SuggestResponse -> SuggestResponse -> Bool
== :: SuggestResponse -> SuggestResponse -> Bool
$c== :: SuggestResponse -> SuggestResponse -> Bool
Prelude.Eq, ReadPrec [SuggestResponse]
ReadPrec SuggestResponse
Int -> ReadS SuggestResponse
ReadS [SuggestResponse]
(Int -> ReadS SuggestResponse)
-> ReadS [SuggestResponse]
-> ReadPrec SuggestResponse
-> ReadPrec [SuggestResponse]
-> Read SuggestResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SuggestResponse]
$creadListPrec :: ReadPrec [SuggestResponse]
readPrec :: ReadPrec SuggestResponse
$creadPrec :: ReadPrec SuggestResponse
readList :: ReadS [SuggestResponse]
$creadList :: ReadS [SuggestResponse]
readsPrec :: Int -> ReadS SuggestResponse
$creadsPrec :: Int -> ReadS SuggestResponse
Prelude.Read, Int -> SuggestResponse -> ShowS
[SuggestResponse] -> ShowS
SuggestResponse -> String
(Int -> SuggestResponse -> ShowS)
-> (SuggestResponse -> String)
-> ([SuggestResponse] -> ShowS)
-> Show SuggestResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SuggestResponse] -> ShowS
$cshowList :: [SuggestResponse] -> ShowS
show :: SuggestResponse -> String
$cshow :: SuggestResponse -> String
showsPrec :: Int -> SuggestResponse -> ShowS
$cshowsPrec :: Int -> SuggestResponse -> ShowS
Prelude.Show, (forall x. SuggestResponse -> Rep SuggestResponse x)
-> (forall x. Rep SuggestResponse x -> SuggestResponse)
-> Generic SuggestResponse
forall x. Rep SuggestResponse x -> SuggestResponse
forall x. SuggestResponse -> Rep SuggestResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SuggestResponse x -> SuggestResponse
$cfrom :: forall x. SuggestResponse -> Rep SuggestResponse x
Prelude.Generic)

-- |
-- Create a value of 'SuggestResponse' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'suggest', 'suggestResponse_suggest' - Container for the matching search suggestion information.
--
-- 'status', 'suggestResponse_status' - The status of a @SuggestRequest@. Contains the resource ID (@rid@) and
-- how long it took to process the request (@timems@).
--
-- 'httpStatus', 'suggestResponse_httpStatus' - The response's http status code.
newSuggestResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  SuggestResponse
newSuggestResponse :: Int -> SuggestResponse
newSuggestResponse Int
pHttpStatus_ =
  SuggestResponse' :: Maybe SuggestModel -> Maybe SuggestStatus -> Int -> SuggestResponse
SuggestResponse'
    { $sel:suggest:SuggestResponse' :: Maybe SuggestModel
suggest = Maybe SuggestModel
forall a. Maybe a
Prelude.Nothing,
      $sel:status:SuggestResponse' :: Maybe SuggestStatus
status = Maybe SuggestStatus
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:SuggestResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Container for the matching search suggestion information.
suggestResponse_suggest :: Lens.Lens' SuggestResponse (Prelude.Maybe SuggestModel)
suggestResponse_suggest :: (Maybe SuggestModel -> f (Maybe SuggestModel))
-> SuggestResponse -> f SuggestResponse
suggestResponse_suggest = (SuggestResponse -> Maybe SuggestModel)
-> (SuggestResponse -> Maybe SuggestModel -> SuggestResponse)
-> Lens
     SuggestResponse
     SuggestResponse
     (Maybe SuggestModel)
     (Maybe SuggestModel)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SuggestResponse' {Maybe SuggestModel
suggest :: Maybe SuggestModel
$sel:suggest:SuggestResponse' :: SuggestResponse -> Maybe SuggestModel
suggest} -> Maybe SuggestModel
suggest) (\s :: SuggestResponse
s@SuggestResponse' {} Maybe SuggestModel
a -> SuggestResponse
s {$sel:suggest:SuggestResponse' :: Maybe SuggestModel
suggest = Maybe SuggestModel
a} :: SuggestResponse)

-- | The status of a @SuggestRequest@. Contains the resource ID (@rid@) and
-- how long it took to process the request (@timems@).
suggestResponse_status :: Lens.Lens' SuggestResponse (Prelude.Maybe SuggestStatus)
suggestResponse_status :: (Maybe SuggestStatus -> f (Maybe SuggestStatus))
-> SuggestResponse -> f SuggestResponse
suggestResponse_status = (SuggestResponse -> Maybe SuggestStatus)
-> (SuggestResponse -> Maybe SuggestStatus -> SuggestResponse)
-> Lens
     SuggestResponse
     SuggestResponse
     (Maybe SuggestStatus)
     (Maybe SuggestStatus)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SuggestResponse' {Maybe SuggestStatus
status :: Maybe SuggestStatus
$sel:status:SuggestResponse' :: SuggestResponse -> Maybe SuggestStatus
status} -> Maybe SuggestStatus
status) (\s :: SuggestResponse
s@SuggestResponse' {} Maybe SuggestStatus
a -> SuggestResponse
s {$sel:status:SuggestResponse' :: Maybe SuggestStatus
status = Maybe SuggestStatus
a} :: SuggestResponse)

-- | The response's http status code.
suggestResponse_httpStatus :: Lens.Lens' SuggestResponse Prelude.Int
suggestResponse_httpStatus :: (Int -> f Int) -> SuggestResponse -> f SuggestResponse
suggestResponse_httpStatus = (SuggestResponse -> Int)
-> (SuggestResponse -> Int -> SuggestResponse)
-> Lens SuggestResponse SuggestResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SuggestResponse' {Int
httpStatus :: Int
$sel:httpStatus:SuggestResponse' :: SuggestResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: SuggestResponse
s@SuggestResponse' {} Int
a -> SuggestResponse
s {$sel:httpStatus:SuggestResponse' :: Int
httpStatus = Int
a} :: SuggestResponse)

instance Prelude.NFData SuggestResponse