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

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

-- |
-- Module      : Amazonka.CloudSearch.Types.DocumentSuggesterOptions
-- 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)
module Amazonka.CloudSearch.Types.DocumentSuggesterOptions where

import Amazonka.CloudSearch.Types.SuggesterFuzzyMatching
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Options for a search suggester.
--
-- /See:/ 'newDocumentSuggesterOptions' smart constructor.
data DocumentSuggesterOptions = DocumentSuggesterOptions'
  { -- | An expression that computes a score for each suggestion to control how
    -- they are sorted. The scores are rounded to the nearest integer, with a
    -- floor of 0 and a ceiling of 2^31-1. A document\'s relevance score is not
    -- computed for suggestions, so sort expressions cannot reference the
    -- @_score@ value. To sort suggestions using a numeric field or existing
    -- expression, simply specify the name of the field or expression. If no
    -- expression is configured for the suggester, the suggestions are sorted
    -- with the closest matches listed first.
    DocumentSuggesterOptions -> Maybe Text
sortExpression :: Prelude.Maybe Prelude.Text,
    -- | The level of fuzziness allowed when suggesting matches for a string:
    -- @none@, @low@, or @high@. With none, the specified string is treated as
    -- an exact prefix. With low, suggestions must differ from the specified
    -- string by no more than one character. With high, suggestions can differ
    -- by up to two characters. The default is none.
    DocumentSuggesterOptions -> Maybe SuggesterFuzzyMatching
fuzzyMatching :: Prelude.Maybe SuggesterFuzzyMatching,
    -- | The name of the index field you want to use for suggestions.
    DocumentSuggesterOptions -> Text
sourceField :: Prelude.Text
  }
  deriving (DocumentSuggesterOptions -> DocumentSuggesterOptions -> Bool
(DocumentSuggesterOptions -> DocumentSuggesterOptions -> Bool)
-> (DocumentSuggesterOptions -> DocumentSuggesterOptions -> Bool)
-> Eq DocumentSuggesterOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DocumentSuggesterOptions -> DocumentSuggesterOptions -> Bool
$c/= :: DocumentSuggesterOptions -> DocumentSuggesterOptions -> Bool
== :: DocumentSuggesterOptions -> DocumentSuggesterOptions -> Bool
$c== :: DocumentSuggesterOptions -> DocumentSuggesterOptions -> Bool
Prelude.Eq, ReadPrec [DocumentSuggesterOptions]
ReadPrec DocumentSuggesterOptions
Int -> ReadS DocumentSuggesterOptions
ReadS [DocumentSuggesterOptions]
(Int -> ReadS DocumentSuggesterOptions)
-> ReadS [DocumentSuggesterOptions]
-> ReadPrec DocumentSuggesterOptions
-> ReadPrec [DocumentSuggesterOptions]
-> Read DocumentSuggesterOptions
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DocumentSuggesterOptions]
$creadListPrec :: ReadPrec [DocumentSuggesterOptions]
readPrec :: ReadPrec DocumentSuggesterOptions
$creadPrec :: ReadPrec DocumentSuggesterOptions
readList :: ReadS [DocumentSuggesterOptions]
$creadList :: ReadS [DocumentSuggesterOptions]
readsPrec :: Int -> ReadS DocumentSuggesterOptions
$creadsPrec :: Int -> ReadS DocumentSuggesterOptions
Prelude.Read, Int -> DocumentSuggesterOptions -> ShowS
[DocumentSuggesterOptions] -> ShowS
DocumentSuggesterOptions -> String
(Int -> DocumentSuggesterOptions -> ShowS)
-> (DocumentSuggesterOptions -> String)
-> ([DocumentSuggesterOptions] -> ShowS)
-> Show DocumentSuggesterOptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DocumentSuggesterOptions] -> ShowS
$cshowList :: [DocumentSuggesterOptions] -> ShowS
show :: DocumentSuggesterOptions -> String
$cshow :: DocumentSuggesterOptions -> String
showsPrec :: Int -> DocumentSuggesterOptions -> ShowS
$cshowsPrec :: Int -> DocumentSuggesterOptions -> ShowS
Prelude.Show, (forall x.
 DocumentSuggesterOptions -> Rep DocumentSuggesterOptions x)
-> (forall x.
    Rep DocumentSuggesterOptions x -> DocumentSuggesterOptions)
-> Generic DocumentSuggesterOptions
forall x.
Rep DocumentSuggesterOptions x -> DocumentSuggesterOptions
forall x.
DocumentSuggesterOptions -> Rep DocumentSuggesterOptions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DocumentSuggesterOptions x -> DocumentSuggesterOptions
$cfrom :: forall x.
DocumentSuggesterOptions -> Rep DocumentSuggesterOptions x
Prelude.Generic)

-- |
-- Create a value of 'DocumentSuggesterOptions' 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:
--
-- 'sortExpression', 'documentSuggesterOptions_sortExpression' - An expression that computes a score for each suggestion to control how
-- they are sorted. The scores are rounded to the nearest integer, with a
-- floor of 0 and a ceiling of 2^31-1. A document\'s relevance score is not
-- computed for suggestions, so sort expressions cannot reference the
-- @_score@ value. To sort suggestions using a numeric field or existing
-- expression, simply specify the name of the field or expression. If no
-- expression is configured for the suggester, the suggestions are sorted
-- with the closest matches listed first.
--
-- 'fuzzyMatching', 'documentSuggesterOptions_fuzzyMatching' - The level of fuzziness allowed when suggesting matches for a string:
-- @none@, @low@, or @high@. With none, the specified string is treated as
-- an exact prefix. With low, suggestions must differ from the specified
-- string by no more than one character. With high, suggestions can differ
-- by up to two characters. The default is none.
--
-- 'sourceField', 'documentSuggesterOptions_sourceField' - The name of the index field you want to use for suggestions.
newDocumentSuggesterOptions ::
  -- | 'sourceField'
  Prelude.Text ->
  DocumentSuggesterOptions
newDocumentSuggesterOptions :: Text -> DocumentSuggesterOptions
newDocumentSuggesterOptions Text
pSourceField_ =
  DocumentSuggesterOptions' :: Maybe Text
-> Maybe SuggesterFuzzyMatching -> Text -> DocumentSuggesterOptions
DocumentSuggesterOptions'
    { $sel:sortExpression:DocumentSuggesterOptions' :: Maybe Text
sortExpression =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:fuzzyMatching:DocumentSuggesterOptions' :: Maybe SuggesterFuzzyMatching
fuzzyMatching = Maybe SuggesterFuzzyMatching
forall a. Maybe a
Prelude.Nothing,
      $sel:sourceField:DocumentSuggesterOptions' :: Text
sourceField = Text
pSourceField_
    }

-- | An expression that computes a score for each suggestion to control how
-- they are sorted. The scores are rounded to the nearest integer, with a
-- floor of 0 and a ceiling of 2^31-1. A document\'s relevance score is not
-- computed for suggestions, so sort expressions cannot reference the
-- @_score@ value. To sort suggestions using a numeric field or existing
-- expression, simply specify the name of the field or expression. If no
-- expression is configured for the suggester, the suggestions are sorted
-- with the closest matches listed first.
documentSuggesterOptions_sortExpression :: Lens.Lens' DocumentSuggesterOptions (Prelude.Maybe Prelude.Text)
documentSuggesterOptions_sortExpression :: (Maybe Text -> f (Maybe Text))
-> DocumentSuggesterOptions -> f DocumentSuggesterOptions
documentSuggesterOptions_sortExpression = (DocumentSuggesterOptions -> Maybe Text)
-> (DocumentSuggesterOptions
    -> Maybe Text -> DocumentSuggesterOptions)
-> Lens
     DocumentSuggesterOptions
     DocumentSuggesterOptions
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DocumentSuggesterOptions' {Maybe Text
sortExpression :: Maybe Text
$sel:sortExpression:DocumentSuggesterOptions' :: DocumentSuggesterOptions -> Maybe Text
sortExpression} -> Maybe Text
sortExpression) (\s :: DocumentSuggesterOptions
s@DocumentSuggesterOptions' {} Maybe Text
a -> DocumentSuggesterOptions
s {$sel:sortExpression:DocumentSuggesterOptions' :: Maybe Text
sortExpression = Maybe Text
a} :: DocumentSuggesterOptions)

-- | The level of fuzziness allowed when suggesting matches for a string:
-- @none@, @low@, or @high@. With none, the specified string is treated as
-- an exact prefix. With low, suggestions must differ from the specified
-- string by no more than one character. With high, suggestions can differ
-- by up to two characters. The default is none.
documentSuggesterOptions_fuzzyMatching :: Lens.Lens' DocumentSuggesterOptions (Prelude.Maybe SuggesterFuzzyMatching)
documentSuggesterOptions_fuzzyMatching :: (Maybe SuggesterFuzzyMatching -> f (Maybe SuggesterFuzzyMatching))
-> DocumentSuggesterOptions -> f DocumentSuggesterOptions
documentSuggesterOptions_fuzzyMatching = (DocumentSuggesterOptions -> Maybe SuggesterFuzzyMatching)
-> (DocumentSuggesterOptions
    -> Maybe SuggesterFuzzyMatching -> DocumentSuggesterOptions)
-> Lens
     DocumentSuggesterOptions
     DocumentSuggesterOptions
     (Maybe SuggesterFuzzyMatching)
     (Maybe SuggesterFuzzyMatching)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DocumentSuggesterOptions' {Maybe SuggesterFuzzyMatching
fuzzyMatching :: Maybe SuggesterFuzzyMatching
$sel:fuzzyMatching:DocumentSuggesterOptions' :: DocumentSuggesterOptions -> Maybe SuggesterFuzzyMatching
fuzzyMatching} -> Maybe SuggesterFuzzyMatching
fuzzyMatching) (\s :: DocumentSuggesterOptions
s@DocumentSuggesterOptions' {} Maybe SuggesterFuzzyMatching
a -> DocumentSuggesterOptions
s {$sel:fuzzyMatching:DocumentSuggesterOptions' :: Maybe SuggesterFuzzyMatching
fuzzyMatching = Maybe SuggesterFuzzyMatching
a} :: DocumentSuggesterOptions)

-- | The name of the index field you want to use for suggestions.
documentSuggesterOptions_sourceField :: Lens.Lens' DocumentSuggesterOptions Prelude.Text
documentSuggesterOptions_sourceField :: (Text -> f Text)
-> DocumentSuggesterOptions -> f DocumentSuggesterOptions
documentSuggesterOptions_sourceField = (DocumentSuggesterOptions -> Text)
-> (DocumentSuggesterOptions -> Text -> DocumentSuggesterOptions)
-> Lens DocumentSuggesterOptions DocumentSuggesterOptions Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DocumentSuggesterOptions' {Text
sourceField :: Text
$sel:sourceField:DocumentSuggesterOptions' :: DocumentSuggesterOptions -> Text
sourceField} -> Text
sourceField) (\s :: DocumentSuggesterOptions
s@DocumentSuggesterOptions' {} Text
a -> DocumentSuggesterOptions
s {$sel:sourceField:DocumentSuggesterOptions' :: Text
sourceField = Text
a} :: DocumentSuggesterOptions)

instance Core.FromXML DocumentSuggesterOptions where
  parseXML :: [Node] -> Either String DocumentSuggesterOptions
parseXML [Node]
x =
    Maybe Text
-> Maybe SuggesterFuzzyMatching -> Text -> DocumentSuggesterOptions
DocumentSuggesterOptions'
      (Maybe Text
 -> Maybe SuggesterFuzzyMatching
 -> Text
 -> DocumentSuggesterOptions)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe SuggesterFuzzyMatching -> Text -> DocumentSuggesterOptions)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"SortExpression")
      Either
  String
  (Maybe SuggesterFuzzyMatching -> Text -> DocumentSuggesterOptions)
-> Either String (Maybe SuggesterFuzzyMatching)
-> Either String (Text -> DocumentSuggesterOptions)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe SuggesterFuzzyMatching)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"FuzzyMatching")
      Either String (Text -> DocumentSuggesterOptions)
-> Either String Text -> Either String DocumentSuggesterOptions
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"SourceField")

instance Prelude.Hashable DocumentSuggesterOptions

instance Prelude.NFData DocumentSuggesterOptions

instance Core.ToQuery DocumentSuggesterOptions where
  toQuery :: DocumentSuggesterOptions -> QueryString
toQuery DocumentSuggesterOptions' {Maybe Text
Maybe SuggesterFuzzyMatching
Text
sourceField :: Text
fuzzyMatching :: Maybe SuggesterFuzzyMatching
sortExpression :: Maybe Text
$sel:sourceField:DocumentSuggesterOptions' :: DocumentSuggesterOptions -> Text
$sel:fuzzyMatching:DocumentSuggesterOptions' :: DocumentSuggesterOptions -> Maybe SuggesterFuzzyMatching
$sel:sortExpression:DocumentSuggesterOptions' :: DocumentSuggesterOptions -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"SortExpression" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
sortExpression,
        ByteString
"FuzzyMatching" ByteString -> Maybe SuggesterFuzzyMatching -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe SuggesterFuzzyMatching
fuzzyMatching,
        ByteString
"SourceField" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
sourceField
      ]