{-# 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.Kendra.Types.Search
-- 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.Kendra.Types.Search where

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

-- | Provides information about how a custom index field is used during a
-- search.
--
-- /See:/ 'newSearch' smart constructor.
data Search = Search'
  { -- | Determines whether the field is returned in the query response. The
    -- default is @true@.
    Search -> Maybe Bool
displayable :: Prelude.Maybe Prelude.Bool,
    -- | Indicates that the field can be used to create search facets, a count of
    -- results for each value in the field. The default is @false@ .
    Search -> Maybe Bool
facetable :: Prelude.Maybe Prelude.Bool,
    -- | Determines whether the field is used in the search. If the @Searchable@
    -- field is @true@, you can use relevance tuning to manually tune how
    -- Amazon Kendra weights the field in the search. The default is @true@ for
    -- string fields and @false@ for number and date fields.
    Search -> Maybe Bool
searchable :: Prelude.Maybe Prelude.Bool,
    -- | Determines whether the field can be used to sort the results of a query.
    -- If you specify sorting on a field that does not have @Sortable@ set to
    -- @true@, Amazon Kendra returns an exception. The default is @false@.
    Search -> Maybe Bool
sortable :: Prelude.Maybe Prelude.Bool
  }
  deriving (Search -> Search -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Search -> Search -> Bool
$c/= :: Search -> Search -> Bool
== :: Search -> Search -> Bool
$c== :: Search -> Search -> Bool
Prelude.Eq, ReadPrec [Search]
ReadPrec Search
Int -> ReadS Search
ReadS [Search]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Search]
$creadListPrec :: ReadPrec [Search]
readPrec :: ReadPrec Search
$creadPrec :: ReadPrec Search
readList :: ReadS [Search]
$creadList :: ReadS [Search]
readsPrec :: Int -> ReadS Search
$creadsPrec :: Int -> ReadS Search
Prelude.Read, Int -> Search -> ShowS
[Search] -> ShowS
Search -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Search] -> ShowS
$cshowList :: [Search] -> ShowS
show :: Search -> String
$cshow :: Search -> String
showsPrec :: Int -> Search -> ShowS
$cshowsPrec :: Int -> Search -> ShowS
Prelude.Show, forall x. Rep Search x -> Search
forall x. Search -> Rep Search x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Search x -> Search
$cfrom :: forall x. Search -> Rep Search x
Prelude.Generic)

-- |
-- Create a value of 'Search' 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:
--
-- 'displayable', 'search_displayable' - Determines whether the field is returned in the query response. The
-- default is @true@.
--
-- 'facetable', 'search_facetable' - Indicates that the field can be used to create search facets, a count of
-- results for each value in the field. The default is @false@ .
--
-- 'searchable', 'search_searchable' - Determines whether the field is used in the search. If the @Searchable@
-- field is @true@, you can use relevance tuning to manually tune how
-- Amazon Kendra weights the field in the search. The default is @true@ for
-- string fields and @false@ for number and date fields.
--
-- 'sortable', 'search_sortable' - Determines whether the field can be used to sort the results of a query.
-- If you specify sorting on a field that does not have @Sortable@ set to
-- @true@, Amazon Kendra returns an exception. The default is @false@.
newSearch ::
  Search
newSearch :: Search
newSearch =
  Search'
    { $sel:displayable:Search' :: Maybe Bool
displayable = forall a. Maybe a
Prelude.Nothing,
      $sel:facetable:Search' :: Maybe Bool
facetable = forall a. Maybe a
Prelude.Nothing,
      $sel:searchable:Search' :: Maybe Bool
searchable = forall a. Maybe a
Prelude.Nothing,
      $sel:sortable:Search' :: Maybe Bool
sortable = forall a. Maybe a
Prelude.Nothing
    }

-- | Determines whether the field is returned in the query response. The
-- default is @true@.
search_displayable :: Lens.Lens' Search (Prelude.Maybe Prelude.Bool)
search_displayable :: Lens' Search (Maybe Bool)
search_displayable = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Search' {Maybe Bool
displayable :: Maybe Bool
$sel:displayable:Search' :: Search -> Maybe Bool
displayable} -> Maybe Bool
displayable) (\s :: Search
s@Search' {} Maybe Bool
a -> Search
s {$sel:displayable:Search' :: Maybe Bool
displayable = Maybe Bool
a} :: Search)

-- | Indicates that the field can be used to create search facets, a count of
-- results for each value in the field. The default is @false@ .
search_facetable :: Lens.Lens' Search (Prelude.Maybe Prelude.Bool)
search_facetable :: Lens' Search (Maybe Bool)
search_facetable = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Search' {Maybe Bool
facetable :: Maybe Bool
$sel:facetable:Search' :: Search -> Maybe Bool
facetable} -> Maybe Bool
facetable) (\s :: Search
s@Search' {} Maybe Bool
a -> Search
s {$sel:facetable:Search' :: Maybe Bool
facetable = Maybe Bool
a} :: Search)

-- | Determines whether the field is used in the search. If the @Searchable@
-- field is @true@, you can use relevance tuning to manually tune how
-- Amazon Kendra weights the field in the search. The default is @true@ for
-- string fields and @false@ for number and date fields.
search_searchable :: Lens.Lens' Search (Prelude.Maybe Prelude.Bool)
search_searchable :: Lens' Search (Maybe Bool)
search_searchable = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Search' {Maybe Bool
searchable :: Maybe Bool
$sel:searchable:Search' :: Search -> Maybe Bool
searchable} -> Maybe Bool
searchable) (\s :: Search
s@Search' {} Maybe Bool
a -> Search
s {$sel:searchable:Search' :: Maybe Bool
searchable = Maybe Bool
a} :: Search)

-- | Determines whether the field can be used to sort the results of a query.
-- If you specify sorting on a field that does not have @Sortable@ set to
-- @true@, Amazon Kendra returns an exception. The default is @false@.
search_sortable :: Lens.Lens' Search (Prelude.Maybe Prelude.Bool)
search_sortable :: Lens' Search (Maybe Bool)
search_sortable = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Search' {Maybe Bool
sortable :: Maybe Bool
$sel:sortable:Search' :: Search -> Maybe Bool
sortable} -> Maybe Bool
sortable) (\s :: Search
s@Search' {} Maybe Bool
a -> Search
s {$sel:sortable:Search' :: Maybe Bool
sortable = Maybe Bool
a} :: Search)

instance Data.FromJSON Search where
  parseJSON :: Value -> Parser Search
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Search"
      ( \Object
x ->
          Maybe Bool -> Maybe Bool -> Maybe Bool -> Maybe Bool -> Search
Search'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Displayable")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Facetable")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Searchable")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Sortable")
      )

instance Prelude.Hashable Search where
  hashWithSalt :: Int -> Search -> Int
hashWithSalt Int
_salt Search' {Maybe Bool
sortable :: Maybe Bool
searchable :: Maybe Bool
facetable :: Maybe Bool
displayable :: Maybe Bool
$sel:sortable:Search' :: Search -> Maybe Bool
$sel:searchable:Search' :: Search -> Maybe Bool
$sel:facetable:Search' :: Search -> Maybe Bool
$sel:displayable:Search' :: Search -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
displayable
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
facetable
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
searchable
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
sortable

instance Prelude.NFData Search where
  rnf :: Search -> ()
rnf Search' {Maybe Bool
sortable :: Maybe Bool
searchable :: Maybe Bool
facetable :: Maybe Bool
displayable :: Maybe Bool
$sel:sortable:Search' :: Search -> Maybe Bool
$sel:searchable:Search' :: Search -> Maybe Bool
$sel:facetable:Search' :: Search -> Maybe Bool
$sel:displayable:Search' :: Search -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
displayable
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
facetable
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
searchable
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
sortable

instance Data.ToJSON Search where
  toJSON :: Search -> Value
toJSON Search' {Maybe Bool
sortable :: Maybe Bool
searchable :: Maybe Bool
facetable :: Maybe Bool
displayable :: Maybe Bool
$sel:sortable:Search' :: Search -> Maybe Bool
$sel:searchable:Search' :: Search -> Maybe Bool
$sel:facetable:Search' :: Search -> Maybe Bool
$sel:displayable:Search' :: Search -> Maybe Bool
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Displayable" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
displayable,
            (Key
"Facetable" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
facetable,
            (Key
"Searchable" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
searchable,
            (Key
"Sortable" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
sortable
          ]
      )