{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | Options for a search suggester.
--
-- /See:/ 'newDocumentSuggesterOptions' smart constructor.
data DocumentSuggesterOptions = 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 -> Maybe SuggesterFuzzyMatching
fuzzyMatching :: Prelude.Maybe SuggesterFuzzyMatching,
    -- | 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 name of the index field you want to use for suggestions.
    DocumentSuggesterOptions -> Text
sourceField :: Prelude.Text
  }
  deriving (DocumentSuggesterOptions -> DocumentSuggesterOptions -> Bool
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]
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
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.
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:
--
-- '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.
--
-- '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.
--
-- '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'
    { $sel:fuzzyMatching:DocumentSuggesterOptions' :: Maybe SuggesterFuzzyMatching
fuzzyMatching =
        forall a. Maybe a
Prelude.Nothing,
      $sel:sortExpression:DocumentSuggesterOptions' :: Maybe Text
sortExpression = forall a. Maybe a
Prelude.Nothing,
      $sel:sourceField:DocumentSuggesterOptions' :: Text
sourceField = Text
pSourceField_
    }

-- | 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 :: Lens' DocumentSuggesterOptions (Maybe SuggesterFuzzyMatching)
documentSuggesterOptions_fuzzyMatching = 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)

-- | 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 :: Lens' DocumentSuggesterOptions (Maybe Text)
documentSuggesterOptions_sortExpression = 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 name of the index field you want to use for suggestions.
documentSuggesterOptions_sourceField :: Lens.Lens' DocumentSuggesterOptions Prelude.Text
documentSuggesterOptions_sourceField :: Lens' DocumentSuggesterOptions Text
documentSuggesterOptions_sourceField = 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 Data.FromXML DocumentSuggesterOptions where
  parseXML :: [Node] -> Either String DocumentSuggesterOptions
parseXML [Node]
x =
    Maybe SuggesterFuzzyMatching
-> Maybe Text -> Text -> DocumentSuggesterOptions
DocumentSuggesterOptions'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"FuzzyMatching")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"SortExpression")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"SourceField")

instance Prelude.Hashable DocumentSuggesterOptions where
  hashWithSalt :: Int -> DocumentSuggesterOptions -> Int
hashWithSalt Int
_salt DocumentSuggesterOptions' {Maybe Text
Maybe SuggesterFuzzyMatching
Text
sourceField :: Text
sortExpression :: Maybe Text
fuzzyMatching :: Maybe SuggesterFuzzyMatching
$sel:sourceField:DocumentSuggesterOptions' :: DocumentSuggesterOptions -> Text
$sel:sortExpression:DocumentSuggesterOptions' :: DocumentSuggesterOptions -> Maybe Text
$sel:fuzzyMatching:DocumentSuggesterOptions' :: DocumentSuggesterOptions -> Maybe SuggesterFuzzyMatching
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe SuggesterFuzzyMatching
fuzzyMatching
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
sortExpression
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
sourceField

instance Prelude.NFData DocumentSuggesterOptions where
  rnf :: DocumentSuggesterOptions -> ()
rnf DocumentSuggesterOptions' {Maybe Text
Maybe SuggesterFuzzyMatching
Text
sourceField :: Text
sortExpression :: Maybe Text
fuzzyMatching :: Maybe SuggesterFuzzyMatching
$sel:sourceField:DocumentSuggesterOptions' :: DocumentSuggesterOptions -> Text
$sel:sortExpression:DocumentSuggesterOptions' :: DocumentSuggesterOptions -> Maybe Text
$sel:fuzzyMatching:DocumentSuggesterOptions' :: DocumentSuggesterOptions -> Maybe SuggesterFuzzyMatching
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe SuggesterFuzzyMatching
fuzzyMatching
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
sortExpression
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
sourceField

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