{-# 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.CloudSearchDomains.Types.Hit
-- 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.CloudSearchDomains.Types.Hit 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

-- | Information about a document that matches the search request.
--
-- /See:/ 'newHit' smart constructor.
data Hit = Hit'
  { -- | The expressions returned from a document that matches the search
    -- request.
    Hit -> Maybe (HashMap Text Text)
exprs :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The fields returned from a document that matches the search request.
    Hit -> Maybe (HashMap Text [Text])
fields :: Prelude.Maybe (Prelude.HashMap Prelude.Text [Prelude.Text]),
    -- | The highlights returned from a document that matches the search request.
    Hit -> Maybe (HashMap Text Text)
highlights :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The document ID of a document that matches the search request.
    Hit -> Maybe Text
id :: Prelude.Maybe Prelude.Text
  }
  deriving (Hit -> Hit -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Hit -> Hit -> Bool
$c/= :: Hit -> Hit -> Bool
== :: Hit -> Hit -> Bool
$c== :: Hit -> Hit -> Bool
Prelude.Eq, ReadPrec [Hit]
ReadPrec Hit
Int -> ReadS Hit
ReadS [Hit]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Hit]
$creadListPrec :: ReadPrec [Hit]
readPrec :: ReadPrec Hit
$creadPrec :: ReadPrec Hit
readList :: ReadS [Hit]
$creadList :: ReadS [Hit]
readsPrec :: Int -> ReadS Hit
$creadsPrec :: Int -> ReadS Hit
Prelude.Read, Int -> Hit -> ShowS
[Hit] -> ShowS
Hit -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Hit] -> ShowS
$cshowList :: [Hit] -> ShowS
show :: Hit -> String
$cshow :: Hit -> String
showsPrec :: Int -> Hit -> ShowS
$cshowsPrec :: Int -> Hit -> ShowS
Prelude.Show, forall x. Rep Hit x -> Hit
forall x. Hit -> Rep Hit x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Hit x -> Hit
$cfrom :: forall x. Hit -> Rep Hit x
Prelude.Generic)

-- |
-- Create a value of 'Hit' 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:
--
-- 'exprs', 'hit_exprs' - The expressions returned from a document that matches the search
-- request.
--
-- 'fields', 'hit_fields' - The fields returned from a document that matches the search request.
--
-- 'highlights', 'hit_highlights' - The highlights returned from a document that matches the search request.
--
-- 'id', 'hit_id' - The document ID of a document that matches the search request.
newHit ::
  Hit
newHit :: Hit
newHit =
  Hit'
    { $sel:exprs:Hit' :: Maybe (HashMap Text Text)
exprs = forall a. Maybe a
Prelude.Nothing,
      $sel:fields:Hit' :: Maybe (HashMap Text [Text])
fields = forall a. Maybe a
Prelude.Nothing,
      $sel:highlights:Hit' :: Maybe (HashMap Text Text)
highlights = forall a. Maybe a
Prelude.Nothing,
      $sel:id:Hit' :: Maybe Text
id = forall a. Maybe a
Prelude.Nothing
    }

-- | The expressions returned from a document that matches the search
-- request.
hit_exprs :: Lens.Lens' Hit (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
hit_exprs :: Lens' Hit (Maybe (HashMap Text Text))
hit_exprs = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Hit' {Maybe (HashMap Text Text)
exprs :: Maybe (HashMap Text Text)
$sel:exprs:Hit' :: Hit -> Maybe (HashMap Text Text)
exprs} -> Maybe (HashMap Text Text)
exprs) (\s :: Hit
s@Hit' {} Maybe (HashMap Text Text)
a -> Hit
s {$sel:exprs:Hit' :: Maybe (HashMap Text Text)
exprs = Maybe (HashMap Text Text)
a} :: Hit) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The fields returned from a document that matches the search request.
hit_fields :: Lens.Lens' Hit (Prelude.Maybe (Prelude.HashMap Prelude.Text [Prelude.Text]))
hit_fields :: Lens' Hit (Maybe (HashMap Text [Text]))
hit_fields = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Hit' {Maybe (HashMap Text [Text])
fields :: Maybe (HashMap Text [Text])
$sel:fields:Hit' :: Hit -> Maybe (HashMap Text [Text])
fields} -> Maybe (HashMap Text [Text])
fields) (\s :: Hit
s@Hit' {} Maybe (HashMap Text [Text])
a -> Hit
s {$sel:fields:Hit' :: Maybe (HashMap Text [Text])
fields = Maybe (HashMap Text [Text])
a} :: Hit) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The highlights returned from a document that matches the search request.
hit_highlights :: Lens.Lens' Hit (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
hit_highlights :: Lens' Hit (Maybe (HashMap Text Text))
hit_highlights = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Hit' {Maybe (HashMap Text Text)
highlights :: Maybe (HashMap Text Text)
$sel:highlights:Hit' :: Hit -> Maybe (HashMap Text Text)
highlights} -> Maybe (HashMap Text Text)
highlights) (\s :: Hit
s@Hit' {} Maybe (HashMap Text Text)
a -> Hit
s {$sel:highlights:Hit' :: Maybe (HashMap Text Text)
highlights = Maybe (HashMap Text Text)
a} :: Hit) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The document ID of a document that matches the search request.
hit_id :: Lens.Lens' Hit (Prelude.Maybe Prelude.Text)
hit_id :: Lens' Hit (Maybe Text)
hit_id = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Hit' {Maybe Text
id :: Maybe Text
$sel:id:Hit' :: Hit -> Maybe Text
id} -> Maybe Text
id) (\s :: Hit
s@Hit' {} Maybe Text
a -> Hit
s {$sel:id:Hit' :: Maybe Text
id = Maybe Text
a} :: Hit)

instance Data.FromJSON Hit where
  parseJSON :: Value -> Parser Hit
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Hit"
      ( \Object
x ->
          Maybe (HashMap Text Text)
-> Maybe (HashMap Text [Text])
-> Maybe (HashMap Text Text)
-> Maybe Text
-> Hit
Hit'
            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
"exprs" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"fields" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"highlights" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"id")
      )

instance Prelude.Hashable Hit where
  hashWithSalt :: Int -> Hit -> Int
hashWithSalt Int
_salt Hit' {Maybe Text
Maybe (HashMap Text [Text])
Maybe (HashMap Text Text)
id :: Maybe Text
highlights :: Maybe (HashMap Text Text)
fields :: Maybe (HashMap Text [Text])
exprs :: Maybe (HashMap Text Text)
$sel:id:Hit' :: Hit -> Maybe Text
$sel:highlights:Hit' :: Hit -> Maybe (HashMap Text Text)
$sel:fields:Hit' :: Hit -> Maybe (HashMap Text [Text])
$sel:exprs:Hit' :: Hit -> Maybe (HashMap Text Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
exprs
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text [Text])
fields
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
highlights
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
id

instance Prelude.NFData Hit where
  rnf :: Hit -> ()
rnf Hit' {Maybe Text
Maybe (HashMap Text [Text])
Maybe (HashMap Text Text)
id :: Maybe Text
highlights :: Maybe (HashMap Text Text)
fields :: Maybe (HashMap Text [Text])
exprs :: Maybe (HashMap Text Text)
$sel:id:Hit' :: Hit -> Maybe Text
$sel:highlights:Hit' :: Hit -> Maybe (HashMap Text Text)
$sel:fields:Hit' :: Hit -> Maybe (HashMap Text [Text])
$sel:exprs:Hit' :: Hit -> Maybe (HashMap Text Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
exprs
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text [Text])
fields
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
highlights
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
id