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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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 document ID of a document that matches the search request.
    Hit -> Maybe Text
id :: Prelude.Maybe 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 fields returned from a document that matches the search request.
    Hit -> Maybe (HashMap Text [Text])
fields :: Prelude.Maybe (Prelude.HashMap Prelude.Text [Prelude.Text])
  }
  deriving (Hit -> Hit -> Bool
(Hit -> Hit -> Bool) -> (Hit -> Hit -> Bool) -> Eq Hit
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]
(Int -> ReadS Hit)
-> ReadS [Hit] -> ReadPrec Hit -> ReadPrec [Hit] -> Read 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
(Int -> Hit -> ShowS)
-> (Hit -> String) -> ([Hit] -> ShowS) -> Show Hit
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. Hit -> Rep Hit x)
-> (forall x. Rep Hit x -> Hit) -> Generic Hit
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.
--
-- 'id', 'hit_id' - The document ID of a document that matches the search request.
--
-- 'highlights', 'hit_highlights' - The highlights returned from a document that matches the search request.
--
-- 'fields', 'hit_fields' - The fields returned from a document that matches the search request.
newHit ::
  Hit
newHit :: Hit
newHit =
  Hit' :: Maybe (HashMap Text Text)
-> Maybe Text
-> Maybe (HashMap Text Text)
-> Maybe (HashMap Text [Text])
-> Hit
Hit'
    { $sel:exprs:Hit' :: Maybe (HashMap Text Text)
exprs = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:id:Hit' :: Maybe Text
id = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:highlights:Hit' :: Maybe (HashMap Text Text)
highlights = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:fields:Hit' :: Maybe (HashMap Text [Text])
fields = Maybe (HashMap Text [Text])
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 :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> Hit -> f Hit
hit_exprs = (Hit -> Maybe (HashMap Text Text))
-> (Hit -> Maybe (HashMap Text Text) -> Hit)
-> Lens
     Hit Hit (Maybe (HashMap Text Text)) (Maybe (HashMap Text Text))
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) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> Hit -> f Hit)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> Hit
-> f Hit
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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 AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
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 :: (Maybe Text -> f (Maybe Text)) -> Hit -> f Hit
hit_id = (Hit -> Maybe Text)
-> (Hit -> Maybe Text -> Hit)
-> Lens Hit Hit (Maybe Text) (Maybe Text)
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)

-- | 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 :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> Hit -> f Hit
hit_highlights = (Hit -> Maybe (HashMap Text Text))
-> (Hit -> Maybe (HashMap Text Text) -> Hit)
-> Lens
     Hit Hit (Maybe (HashMap Text Text)) (Maybe (HashMap Text Text))
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) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> Hit -> f Hit)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> Hit
-> f Hit
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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 AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
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 :: (Maybe (HashMap Text [Text]) -> f (Maybe (HashMap Text [Text])))
-> Hit -> f Hit
hit_fields = (Hit -> Maybe (HashMap Text [Text]))
-> (Hit -> Maybe (HashMap Text [Text]) -> Hit)
-> Lens
     Hit Hit (Maybe (HashMap Text [Text])) (Maybe (HashMap Text [Text]))
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) ((Maybe (HashMap Text [Text]) -> f (Maybe (HashMap Text [Text])))
 -> Hit -> f Hit)
-> ((Maybe (HashMap Text [Text])
     -> f (Maybe (HashMap Text [Text])))
    -> Maybe (HashMap Text [Text]) -> f (Maybe (HashMap Text [Text])))
-> (Maybe (HashMap Text [Text]) -> f (Maybe (HashMap Text [Text])))
-> Hit
-> f Hit
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text [Text])
  (HashMap Text [Text])
  (HashMap Text [Text])
  (HashMap Text [Text])
-> Iso
     (Maybe (HashMap Text [Text]))
     (Maybe (HashMap Text [Text]))
     (Maybe (HashMap Text [Text]))
     (Maybe (HashMap Text [Text]))
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 AnIso
  (HashMap Text [Text])
  (HashMap Text [Text])
  (HashMap Text [Text])
  (HashMap Text [Text])
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON Hit where
  parseJSON :: Value -> Parser Hit
parseJSON =
    String -> (Object -> Parser Hit) -> Value -> Parser Hit
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Hit"
      ( \Object
x ->
          Maybe (HashMap Text Text)
-> Maybe Text
-> Maybe (HashMap Text Text)
-> Maybe (HashMap Text [Text])
-> Hit
Hit'
            (Maybe (HashMap Text Text)
 -> Maybe Text
 -> Maybe (HashMap Text Text)
 -> Maybe (HashMap Text [Text])
 -> Hit)
-> Parser (Maybe (HashMap Text Text))
-> Parser
     (Maybe Text
      -> Maybe (HashMap Text Text) -> Maybe (HashMap Text [Text]) -> Hit)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text Text)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"exprs" Parser (Maybe (Maybe (HashMap Text Text)))
-> Maybe (HashMap Text Text) -> Parser (Maybe (HashMap Text Text))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text Text)
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Maybe Text
   -> Maybe (HashMap Text Text) -> Maybe (HashMap Text [Text]) -> Hit)
-> Parser (Maybe Text)
-> Parser
     (Maybe (HashMap Text Text) -> Maybe (HashMap Text [Text]) -> Hit)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"id")
            Parser
  (Maybe (HashMap Text Text) -> Maybe (HashMap Text [Text]) -> Hit)
-> Parser (Maybe (HashMap Text Text))
-> Parser (Maybe (HashMap Text [Text]) -> Hit)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text Text)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"highlights" Parser (Maybe (Maybe (HashMap Text Text)))
-> Maybe (HashMap Text Text) -> Parser (Maybe (HashMap Text Text))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text Text)
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe (HashMap Text [Text]) -> Hit)
-> Parser (Maybe (HashMap Text [Text])) -> Parser Hit
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text [Text])))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"fields" Parser (Maybe (Maybe (HashMap Text [Text])))
-> Maybe (HashMap Text [Text])
-> Parser (Maybe (HashMap Text [Text]))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text [Text])
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable Hit

instance Prelude.NFData Hit