{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE RecordWildCards            #-}
{-# LANGUAGE OverloadedStrings          #-}

module Database.Bloodhound.Internal.Suggest where

import           Bloodhound.Import

import qualified Data.Aeson.KeyMap as X

import           Database.Bloodhound.Internal.Newtypes
import           Database.Bloodhound.Internal.Query (Query, TemplateQueryKeyValuePairs)

data Suggest = Suggest
  { Suggest -> Text
suggestText :: Text
  , Suggest -> Text
suggestName :: Text
  , Suggest -> SuggestType
suggestType :: SuggestType
  } deriving (Suggest -> Suggest -> Bool
(Suggest -> Suggest -> Bool)
-> (Suggest -> Suggest -> Bool) -> Eq Suggest
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Suggest -> Suggest -> Bool
$c/= :: Suggest -> Suggest -> Bool
== :: Suggest -> Suggest -> Bool
$c== :: Suggest -> Suggest -> Bool
Eq, Int -> Suggest -> ShowS
[Suggest] -> ShowS
Suggest -> String
(Int -> Suggest -> ShowS)
-> (Suggest -> String) -> ([Suggest] -> ShowS) -> Show Suggest
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Suggest] -> ShowS
$cshowList :: [Suggest] -> ShowS
show :: Suggest -> String
$cshow :: Suggest -> String
showsPrec :: Int -> Suggest -> ShowS
$cshowsPrec :: Int -> Suggest -> ShowS
Show)

instance ToJSON Suggest where
  toJSON :: Suggest -> Value
toJSON Suggest{Text
SuggestType
suggestType :: SuggestType
suggestName :: Text
suggestText :: Text
suggestType :: Suggest -> SuggestType
suggestName :: Suggest -> Text
suggestText :: Suggest -> Text
..} =
    [Pair] -> Value
object [ Key
"text" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
suggestText
           , Text -> Key
fromText Text
suggestName Key -> SuggestType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= SuggestType
suggestType
           ]

instance FromJSON Suggest where
  parseJSON :: Value -> Parser Suggest
parseJSON (Object Object
o) = do
    Text
suggestText' <- Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"text"
    let dropTextList :: [Pair]
dropTextList =
            Object -> [Pair]
forall v. KeyMap v -> [(Key, v)]
X.toList
          (Object -> [Pair]) -> Object -> [Pair]
forall a b. (a -> b) -> a -> b
$ (Key -> Value -> Bool) -> Object -> Object
forall v. (Key -> v -> Bool) -> KeyMap v -> KeyMap v
X.filterWithKey (\Key
x Value
_ -> Key
x Key -> Key -> Bool
forall a. Eq a => a -> a -> Bool
/= Key
"text") Object
o
    Key
suggestName' <-
      case [Pair]
dropTextList of
        [(Key
x, Value
_)] -> Key -> Parser Key
forall (m :: * -> *) a. Monad m => a -> m a
return Key
x
        [Pair]
_ -> String -> Parser Key
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"error parsing Suggest field name"
    SuggestType
suggestType' <- Object
o Object -> Key -> Parser SuggestType
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
suggestName'
    Suggest -> Parser Suggest
forall (m :: * -> *) a. Monad m => a -> m a
return (Suggest -> Parser Suggest) -> Suggest -> Parser Suggest
forall a b. (a -> b) -> a -> b
$ Text -> Text -> SuggestType -> Suggest
Suggest Text
suggestText' (Key -> Text
toText Key
suggestName') SuggestType
suggestType'
  parseJSON Value
x = String -> Value -> Parser Suggest
forall a. String -> Value -> Parser a
typeMismatch String
"Suggest" Value
x

data SuggestType =
  SuggestTypePhraseSuggester PhraseSuggester
  deriving (SuggestType -> SuggestType -> Bool
(SuggestType -> SuggestType -> Bool)
-> (SuggestType -> SuggestType -> Bool) -> Eq SuggestType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SuggestType -> SuggestType -> Bool
$c/= :: SuggestType -> SuggestType -> Bool
== :: SuggestType -> SuggestType -> Bool
$c== :: SuggestType -> SuggestType -> Bool
Eq, Int -> SuggestType -> ShowS
[SuggestType] -> ShowS
SuggestType -> String
(Int -> SuggestType -> ShowS)
-> (SuggestType -> String)
-> ([SuggestType] -> ShowS)
-> Show SuggestType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SuggestType] -> ShowS
$cshowList :: [SuggestType] -> ShowS
show :: SuggestType -> String
$cshow :: SuggestType -> String
showsPrec :: Int -> SuggestType -> ShowS
$cshowsPrec :: Int -> SuggestType -> ShowS
Show)

instance ToJSON SuggestType where
  toJSON :: SuggestType -> Value
toJSON (SuggestTypePhraseSuggester PhraseSuggester
x) =
    [Pair] -> Value
object [ Key
"phrase" Key -> PhraseSuggester -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= PhraseSuggester
x ]

instance FromJSON SuggestType where
  parseJSON :: Value -> Parser SuggestType
parseJSON = String
-> (Object -> Parser SuggestType) -> Value -> Parser SuggestType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"SuggestType" Object -> Parser SuggestType
parse
    where parse :: Object -> Parser SuggestType
parse Object
o = PhraseSuggester -> Parser SuggestType
phraseSuggester (PhraseSuggester -> Parser SuggestType)
-> Key -> Parser SuggestType
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"phrase"
           where taggedWith :: (a -> Parser b) -> Key -> Parser b
taggedWith a -> Parser b
parser Key
k = a -> Parser b
parser (a -> Parser b) -> Parser a -> Parser b
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Object
o Object -> Key -> Parser a
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
k
                 phraseSuggester :: PhraseSuggester -> Parser SuggestType
phraseSuggester = SuggestType -> Parser SuggestType
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SuggestType -> Parser SuggestType)
-> (PhraseSuggester -> SuggestType)
-> PhraseSuggester
-> Parser SuggestType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PhraseSuggester -> SuggestType
SuggestTypePhraseSuggester

data PhraseSuggester = PhraseSuggester
  { PhraseSuggester -> FieldName
phraseSuggesterField :: FieldName
  , PhraseSuggester -> Maybe Int
phraseSuggesterGramSize :: Maybe Int
  , PhraseSuggester -> Maybe Int
phraseSuggesterRealWordErrorLikelihood :: Maybe Int
  , PhraseSuggester -> Maybe Int
phraseSuggesterConfidence :: Maybe Int
  , PhraseSuggester -> Maybe Int
phraseSuggesterMaxErrors :: Maybe Int
  , PhraseSuggester -> Maybe Text
phraseSuggesterSeparator :: Maybe Text
  , PhraseSuggester -> Maybe Size
phraseSuggesterSize :: Maybe Size
  , PhraseSuggester -> Maybe Analyzer
phraseSuggesterAnalyzer :: Maybe Analyzer
  , PhraseSuggester -> Maybe Int
phraseSuggesterShardSize :: Maybe Int
  , PhraseSuggester -> Maybe PhraseSuggesterHighlighter
phraseSuggesterHighlight :: Maybe PhraseSuggesterHighlighter
  , PhraseSuggester -> Maybe PhraseSuggesterCollate
phraseSuggesterCollate :: Maybe PhraseSuggesterCollate
  , PhraseSuggester -> [DirectGenerators]
phraseSuggesterCandidateGenerators :: [DirectGenerators]
  } deriving (PhraseSuggester -> PhraseSuggester -> Bool
(PhraseSuggester -> PhraseSuggester -> Bool)
-> (PhraseSuggester -> PhraseSuggester -> Bool)
-> Eq PhraseSuggester
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PhraseSuggester -> PhraseSuggester -> Bool
$c/= :: PhraseSuggester -> PhraseSuggester -> Bool
== :: PhraseSuggester -> PhraseSuggester -> Bool
$c== :: PhraseSuggester -> PhraseSuggester -> Bool
Eq, Int -> PhraseSuggester -> ShowS
[PhraseSuggester] -> ShowS
PhraseSuggester -> String
(Int -> PhraseSuggester -> ShowS)
-> (PhraseSuggester -> String)
-> ([PhraseSuggester] -> ShowS)
-> Show PhraseSuggester
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PhraseSuggester] -> ShowS
$cshowList :: [PhraseSuggester] -> ShowS
show :: PhraseSuggester -> String
$cshow :: PhraseSuggester -> String
showsPrec :: Int -> PhraseSuggester -> ShowS
$cshowsPrec :: Int -> PhraseSuggester -> ShowS
Show)

instance ToJSON PhraseSuggester where
  toJSON :: PhraseSuggester -> Value
toJSON PhraseSuggester{[DirectGenerators]
Maybe Int
Maybe Text
Maybe Analyzer
Maybe Size
Maybe PhraseSuggesterCollate
Maybe PhraseSuggesterHighlighter
FieldName
phraseSuggesterCandidateGenerators :: [DirectGenerators]
phraseSuggesterCollate :: Maybe PhraseSuggesterCollate
phraseSuggesterHighlight :: Maybe PhraseSuggesterHighlighter
phraseSuggesterShardSize :: Maybe Int
phraseSuggesterAnalyzer :: Maybe Analyzer
phraseSuggesterSize :: Maybe Size
phraseSuggesterSeparator :: Maybe Text
phraseSuggesterMaxErrors :: Maybe Int
phraseSuggesterConfidence :: Maybe Int
phraseSuggesterRealWordErrorLikelihood :: Maybe Int
phraseSuggesterGramSize :: Maybe Int
phraseSuggesterField :: FieldName
phraseSuggesterCandidateGenerators :: PhraseSuggester -> [DirectGenerators]
phraseSuggesterCollate :: PhraseSuggester -> Maybe PhraseSuggesterCollate
phraseSuggesterHighlight :: PhraseSuggester -> Maybe PhraseSuggesterHighlighter
phraseSuggesterShardSize :: PhraseSuggester -> Maybe Int
phraseSuggesterAnalyzer :: PhraseSuggester -> Maybe Analyzer
phraseSuggesterSize :: PhraseSuggester -> Maybe Size
phraseSuggesterSeparator :: PhraseSuggester -> Maybe Text
phraseSuggesterMaxErrors :: PhraseSuggester -> Maybe Int
phraseSuggesterConfidence :: PhraseSuggester -> Maybe Int
phraseSuggesterRealWordErrorLikelihood :: PhraseSuggester -> Maybe Int
phraseSuggesterGramSize :: PhraseSuggester -> Maybe Int
phraseSuggesterField :: PhraseSuggester -> FieldName
..} =
    [Pair] -> Value
omitNulls [ Key
"field" Key -> FieldName -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= FieldName
phraseSuggesterField
              , Key
"gram_size" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Int
phraseSuggesterGramSize
              , Key
"real_word_error_likelihood" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.=
                Maybe Int
phraseSuggesterRealWordErrorLikelihood
              , Key
"confidence" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Int
phraseSuggesterConfidence
              , Key
"max_errors" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Int
phraseSuggesterMaxErrors
              , Key
"separator" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Text
phraseSuggesterSeparator
              , Key
"size" Key -> Maybe Size -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Size
phraseSuggesterSize
              , Key
"analyzer" Key -> Maybe Analyzer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Analyzer
phraseSuggesterAnalyzer
              , Key
"shard_size" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Int
phraseSuggesterShardSize
              , Key
"highlight" Key -> Maybe PhraseSuggesterHighlighter -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe PhraseSuggesterHighlighter
phraseSuggesterHighlight
              , Key
"collate" Key -> Maybe PhraseSuggesterCollate -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe PhraseSuggesterCollate
phraseSuggesterCollate
              , Key
"direct_generator" Key -> [DirectGenerators] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.=
                [DirectGenerators]
phraseSuggesterCandidateGenerators
              ]

instance FromJSON PhraseSuggester where
  parseJSON :: Value -> Parser PhraseSuggester
parseJSON = String
-> (Object -> Parser PhraseSuggester)
-> Value
-> Parser PhraseSuggester
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"PhraseSuggester" Object -> Parser PhraseSuggester
parse
    where parse :: Object -> Parser PhraseSuggester
parse Object
o = FieldName
-> Maybe Int
-> Maybe Int
-> Maybe Int
-> Maybe Int
-> Maybe Text
-> Maybe Size
-> Maybe Analyzer
-> Maybe Int
-> Maybe PhraseSuggesterHighlighter
-> Maybe PhraseSuggesterCollate
-> [DirectGenerators]
-> PhraseSuggester
PhraseSuggester
                      (FieldName
 -> Maybe Int
 -> Maybe Int
 -> Maybe Int
 -> Maybe Int
 -> Maybe Text
 -> Maybe Size
 -> Maybe Analyzer
 -> Maybe Int
 -> Maybe PhraseSuggesterHighlighter
 -> Maybe PhraseSuggesterCollate
 -> [DirectGenerators]
 -> PhraseSuggester)
-> Parser FieldName
-> Parser
     (Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Text
      -> Maybe Size
      -> Maybe Analyzer
      -> Maybe Int
      -> Maybe PhraseSuggesterHighlighter
      -> Maybe PhraseSuggesterCollate
      -> [DirectGenerators]
      -> PhraseSuggester)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser FieldName
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"field"
                      Parser
  (Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Text
   -> Maybe Size
   -> Maybe Analyzer
   -> Maybe Int
   -> Maybe PhraseSuggesterHighlighter
   -> Maybe PhraseSuggesterCollate
   -> [DirectGenerators]
   -> PhraseSuggester)
-> Parser (Maybe Int)
-> Parser
     (Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Text
      -> Maybe Size
      -> Maybe Analyzer
      -> Maybe Int
      -> Maybe PhraseSuggesterHighlighter
      -> Maybe PhraseSuggesterCollate
      -> [DirectGenerators]
      -> PhraseSuggester)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"gram_size"
                      Parser
  (Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Text
   -> Maybe Size
   -> Maybe Analyzer
   -> Maybe Int
   -> Maybe PhraseSuggesterHighlighter
   -> Maybe PhraseSuggesterCollate
   -> [DirectGenerators]
   -> PhraseSuggester)
-> Parser (Maybe Int)
-> Parser
     (Maybe Int
      -> Maybe Int
      -> Maybe Text
      -> Maybe Size
      -> Maybe Analyzer
      -> Maybe Int
      -> Maybe PhraseSuggesterHighlighter
      -> Maybe PhraseSuggesterCollate
      -> [DirectGenerators]
      -> PhraseSuggester)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"real_word_error_likelihood"
                      Parser
  (Maybe Int
   -> Maybe Int
   -> Maybe Text
   -> Maybe Size
   -> Maybe Analyzer
   -> Maybe Int
   -> Maybe PhraseSuggesterHighlighter
   -> Maybe PhraseSuggesterCollate
   -> [DirectGenerators]
   -> PhraseSuggester)
-> Parser (Maybe Int)
-> Parser
     (Maybe Int
      -> Maybe Text
      -> Maybe Size
      -> Maybe Analyzer
      -> Maybe Int
      -> Maybe PhraseSuggesterHighlighter
      -> Maybe PhraseSuggesterCollate
      -> [DirectGenerators]
      -> PhraseSuggester)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"confidence"
                      Parser
  (Maybe Int
   -> Maybe Text
   -> Maybe Size
   -> Maybe Analyzer
   -> Maybe Int
   -> Maybe PhraseSuggesterHighlighter
   -> Maybe PhraseSuggesterCollate
   -> [DirectGenerators]
   -> PhraseSuggester)
-> Parser (Maybe Int)
-> Parser
     (Maybe Text
      -> Maybe Size
      -> Maybe Analyzer
      -> Maybe Int
      -> Maybe PhraseSuggesterHighlighter
      -> Maybe PhraseSuggesterCollate
      -> [DirectGenerators]
      -> PhraseSuggester)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"max_errors"
                      Parser
  (Maybe Text
   -> Maybe Size
   -> Maybe Analyzer
   -> Maybe Int
   -> Maybe PhraseSuggesterHighlighter
   -> Maybe PhraseSuggesterCollate
   -> [DirectGenerators]
   -> PhraseSuggester)
-> Parser (Maybe Text)
-> Parser
     (Maybe Size
      -> Maybe Analyzer
      -> Maybe Int
      -> Maybe PhraseSuggesterHighlighter
      -> Maybe PhraseSuggesterCollate
      -> [DirectGenerators]
      -> PhraseSuggester)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"separator"
                      Parser
  (Maybe Size
   -> Maybe Analyzer
   -> Maybe Int
   -> Maybe PhraseSuggesterHighlighter
   -> Maybe PhraseSuggesterCollate
   -> [DirectGenerators]
   -> PhraseSuggester)
-> Parser (Maybe Size)
-> Parser
     (Maybe Analyzer
      -> Maybe Int
      -> Maybe PhraseSuggesterHighlighter
      -> Maybe PhraseSuggesterCollate
      -> [DirectGenerators]
      -> PhraseSuggester)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Size)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"size"
                      Parser
  (Maybe Analyzer
   -> Maybe Int
   -> Maybe PhraseSuggesterHighlighter
   -> Maybe PhraseSuggesterCollate
   -> [DirectGenerators]
   -> PhraseSuggester)
-> Parser (Maybe Analyzer)
-> Parser
     (Maybe Int
      -> Maybe PhraseSuggesterHighlighter
      -> Maybe PhraseSuggesterCollate
      -> [DirectGenerators]
      -> PhraseSuggester)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Analyzer)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"analyzer"
                      Parser
  (Maybe Int
   -> Maybe PhraseSuggesterHighlighter
   -> Maybe PhraseSuggesterCollate
   -> [DirectGenerators]
   -> PhraseSuggester)
-> Parser (Maybe Int)
-> Parser
     (Maybe PhraseSuggesterHighlighter
      -> Maybe PhraseSuggesterCollate
      -> [DirectGenerators]
      -> PhraseSuggester)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"shard_size"
                      Parser
  (Maybe PhraseSuggesterHighlighter
   -> Maybe PhraseSuggesterCollate
   -> [DirectGenerators]
   -> PhraseSuggester)
-> Parser (Maybe PhraseSuggesterHighlighter)
-> Parser
     (Maybe PhraseSuggesterCollate
      -> [DirectGenerators] -> PhraseSuggester)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe PhraseSuggesterHighlighter)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"highlight"
                      Parser
  (Maybe PhraseSuggesterCollate
   -> [DirectGenerators] -> PhraseSuggester)
-> Parser (Maybe PhraseSuggesterCollate)
-> Parser ([DirectGenerators] -> PhraseSuggester)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe PhraseSuggesterCollate)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"collate"
                      Parser ([DirectGenerators] -> PhraseSuggester)
-> Parser [DirectGenerators] -> Parser PhraseSuggester
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe [DirectGenerators])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"direct_generator" Parser (Maybe [DirectGenerators])
-> [DirectGenerators] -> Parser [DirectGenerators]
forall a. Parser (Maybe a) -> a -> Parser a
.!= []

mkPhraseSuggester :: FieldName -> PhraseSuggester
mkPhraseSuggester :: FieldName -> PhraseSuggester
mkPhraseSuggester FieldName
fName =
  FieldName
-> Maybe Int
-> Maybe Int
-> Maybe Int
-> Maybe Int
-> Maybe Text
-> Maybe Size
-> Maybe Analyzer
-> Maybe Int
-> Maybe PhraseSuggesterHighlighter
-> Maybe PhraseSuggesterCollate
-> [DirectGenerators]
-> PhraseSuggester
PhraseSuggester FieldName
fName Maybe Int
forall a. Maybe a
Nothing Maybe Int
forall a. Maybe a
Nothing Maybe Int
forall a. Maybe a
Nothing Maybe Int
forall a. Maybe a
Nothing Maybe Text
forall a. Maybe a
Nothing Maybe Size
forall a. Maybe a
Nothing
    Maybe Analyzer
forall a. Maybe a
Nothing Maybe Int
forall a. Maybe a
Nothing Maybe PhraseSuggesterHighlighter
forall a. Maybe a
Nothing Maybe PhraseSuggesterCollate
forall a. Maybe a
Nothing []

data PhraseSuggesterHighlighter =
  PhraseSuggesterHighlighter { PhraseSuggesterHighlighter -> Text
phraseSuggesterHighlighterPreTag :: Text
                             , PhraseSuggesterHighlighter -> Text
phraseSuggesterHighlighterPostTag :: Text
                             }
  deriving (PhraseSuggesterHighlighter -> PhraseSuggesterHighlighter -> Bool
(PhraseSuggesterHighlighter -> PhraseSuggesterHighlighter -> Bool)
-> (PhraseSuggesterHighlighter
    -> PhraseSuggesterHighlighter -> Bool)
-> Eq PhraseSuggesterHighlighter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PhraseSuggesterHighlighter -> PhraseSuggesterHighlighter -> Bool
$c/= :: PhraseSuggesterHighlighter -> PhraseSuggesterHighlighter -> Bool
== :: PhraseSuggesterHighlighter -> PhraseSuggesterHighlighter -> Bool
$c== :: PhraseSuggesterHighlighter -> PhraseSuggesterHighlighter -> Bool
Eq, Int -> PhraseSuggesterHighlighter -> ShowS
[PhraseSuggesterHighlighter] -> ShowS
PhraseSuggesterHighlighter -> String
(Int -> PhraseSuggesterHighlighter -> ShowS)
-> (PhraseSuggesterHighlighter -> String)
-> ([PhraseSuggesterHighlighter] -> ShowS)
-> Show PhraseSuggesterHighlighter
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PhraseSuggesterHighlighter] -> ShowS
$cshowList :: [PhraseSuggesterHighlighter] -> ShowS
show :: PhraseSuggesterHighlighter -> String
$cshow :: PhraseSuggesterHighlighter -> String
showsPrec :: Int -> PhraseSuggesterHighlighter -> ShowS
$cshowsPrec :: Int -> PhraseSuggesterHighlighter -> ShowS
Show)

instance ToJSON PhraseSuggesterHighlighter where
  toJSON :: PhraseSuggesterHighlighter -> Value
toJSON PhraseSuggesterHighlighter{Text
phraseSuggesterHighlighterPostTag :: Text
phraseSuggesterHighlighterPreTag :: Text
phraseSuggesterHighlighterPostTag :: PhraseSuggesterHighlighter -> Text
phraseSuggesterHighlighterPreTag :: PhraseSuggesterHighlighter -> Text
..} =
            [Pair] -> Value
object [ Key
"pre_tag" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
phraseSuggesterHighlighterPreTag
                   , Key
"post_tag" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
phraseSuggesterHighlighterPostTag
                   ]

instance FromJSON PhraseSuggesterHighlighter where
  parseJSON :: Value -> Parser PhraseSuggesterHighlighter
parseJSON = String
-> (Object -> Parser PhraseSuggesterHighlighter)
-> Value
-> Parser PhraseSuggesterHighlighter
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"PhraseSuggesterHighlighter" Object -> Parser PhraseSuggesterHighlighter
parse
    where parse :: Object -> Parser PhraseSuggesterHighlighter
parse Object
o = Text -> Text -> PhraseSuggesterHighlighter
PhraseSuggesterHighlighter
                      (Text -> Text -> PhraseSuggesterHighlighter)
-> Parser Text -> Parser (Text -> PhraseSuggesterHighlighter)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"pre_tag"
                      Parser (Text -> PhraseSuggesterHighlighter)
-> Parser Text -> Parser PhraseSuggesterHighlighter
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"post_tag"

data PhraseSuggesterCollate = PhraseSuggesterCollate
  { PhraseSuggesterCollate -> Query
phraseSuggesterCollateTemplateQuery :: Query
  , PhraseSuggesterCollate -> TemplateQueryKeyValuePairs
phraseSuggesterCollateParams :: TemplateQueryKeyValuePairs
  , PhraseSuggesterCollate -> Bool
phraseSuggesterCollatePrune :: Bool
  } deriving (PhraseSuggesterCollate -> PhraseSuggesterCollate -> Bool
(PhraseSuggesterCollate -> PhraseSuggesterCollate -> Bool)
-> (PhraseSuggesterCollate -> PhraseSuggesterCollate -> Bool)
-> Eq PhraseSuggesterCollate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PhraseSuggesterCollate -> PhraseSuggesterCollate -> Bool
$c/= :: PhraseSuggesterCollate -> PhraseSuggesterCollate -> Bool
== :: PhraseSuggesterCollate -> PhraseSuggesterCollate -> Bool
$c== :: PhraseSuggesterCollate -> PhraseSuggesterCollate -> Bool
Eq, Int -> PhraseSuggesterCollate -> ShowS
[PhraseSuggesterCollate] -> ShowS
PhraseSuggesterCollate -> String
(Int -> PhraseSuggesterCollate -> ShowS)
-> (PhraseSuggesterCollate -> String)
-> ([PhraseSuggesterCollate] -> ShowS)
-> Show PhraseSuggesterCollate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PhraseSuggesterCollate] -> ShowS
$cshowList :: [PhraseSuggesterCollate] -> ShowS
show :: PhraseSuggesterCollate -> String
$cshow :: PhraseSuggesterCollate -> String
showsPrec :: Int -> PhraseSuggesterCollate -> ShowS
$cshowsPrec :: Int -> PhraseSuggesterCollate -> ShowS
Show)

instance ToJSON PhraseSuggesterCollate where
  toJSON :: PhraseSuggesterCollate -> Value
toJSON PhraseSuggesterCollate{Bool
TemplateQueryKeyValuePairs
Query
phraseSuggesterCollatePrune :: Bool
phraseSuggesterCollateParams :: TemplateQueryKeyValuePairs
phraseSuggesterCollateTemplateQuery :: Query
phraseSuggesterCollatePrune :: PhraseSuggesterCollate -> Bool
phraseSuggesterCollateParams :: PhraseSuggesterCollate -> TemplateQueryKeyValuePairs
phraseSuggesterCollateTemplateQuery :: PhraseSuggesterCollate -> Query
..} =
    [Pair] -> Value
object [ Key
"query" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Pair] -> Value
object
             [ Key
"source" Key -> Query -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Query
phraseSuggesterCollateTemplateQuery
             ]
           , Key
"params" Key -> TemplateQueryKeyValuePairs -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= TemplateQueryKeyValuePairs
phraseSuggesterCollateParams
           , Key
"prune" Key -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Bool
phraseSuggesterCollatePrune
           ]

instance FromJSON PhraseSuggesterCollate where
  parseJSON :: Value -> Parser PhraseSuggesterCollate
parseJSON (Object Object
o) = do
    Object
query' <- Object
o Object -> Key -> Parser Object
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"query"
    Query
inline' <- Object
query' Object -> Key -> Parser Query
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"source"
    TemplateQueryKeyValuePairs
params' <- Object
o Object -> Key -> Parser TemplateQueryKeyValuePairs
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"params"
    Bool
prune' <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"prune" Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= Bool
False
    PhraseSuggesterCollate -> Parser PhraseSuggesterCollate
forall (m :: * -> *) a. Monad m => a -> m a
return (PhraseSuggesterCollate -> Parser PhraseSuggesterCollate)
-> PhraseSuggesterCollate -> Parser PhraseSuggesterCollate
forall a b. (a -> b) -> a -> b
$ Query
-> TemplateQueryKeyValuePairs -> Bool -> PhraseSuggesterCollate
PhraseSuggesterCollate Query
inline' TemplateQueryKeyValuePairs
params' Bool
prune'
  parseJSON Value
x = String -> Value -> Parser PhraseSuggesterCollate
forall a. String -> Value -> Parser a
typeMismatch String
"PhraseSuggesterCollate" Value
x

data SuggestOptions =
  SuggestOptions { SuggestOptions -> Text
suggestOptionsText :: Text
                 , SuggestOptions -> Double
suggestOptionsScore :: Double
                 , SuggestOptions -> Maybe Int
suggestOptionsFreq :: Maybe Int
                 , SuggestOptions -> Maybe Text
suggestOptionsHighlighted :: Maybe Text
                 }
  deriving (SuggestOptions -> SuggestOptions -> Bool
(SuggestOptions -> SuggestOptions -> Bool)
-> (SuggestOptions -> SuggestOptions -> Bool) -> Eq SuggestOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SuggestOptions -> SuggestOptions -> Bool
$c/= :: SuggestOptions -> SuggestOptions -> Bool
== :: SuggestOptions -> SuggestOptions -> Bool
$c== :: SuggestOptions -> SuggestOptions -> Bool
Eq, ReadPrec [SuggestOptions]
ReadPrec SuggestOptions
Int -> ReadS SuggestOptions
ReadS [SuggestOptions]
(Int -> ReadS SuggestOptions)
-> ReadS [SuggestOptions]
-> ReadPrec SuggestOptions
-> ReadPrec [SuggestOptions]
-> Read SuggestOptions
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SuggestOptions]
$creadListPrec :: ReadPrec [SuggestOptions]
readPrec :: ReadPrec SuggestOptions
$creadPrec :: ReadPrec SuggestOptions
readList :: ReadS [SuggestOptions]
$creadList :: ReadS [SuggestOptions]
readsPrec :: Int -> ReadS SuggestOptions
$creadsPrec :: Int -> ReadS SuggestOptions
Read, Int -> SuggestOptions -> ShowS
[SuggestOptions] -> ShowS
SuggestOptions -> String
(Int -> SuggestOptions -> ShowS)
-> (SuggestOptions -> String)
-> ([SuggestOptions] -> ShowS)
-> Show SuggestOptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SuggestOptions] -> ShowS
$cshowList :: [SuggestOptions] -> ShowS
show :: SuggestOptions -> String
$cshow :: SuggestOptions -> String
showsPrec :: Int -> SuggestOptions -> ShowS
$cshowsPrec :: Int -> SuggestOptions -> ShowS
Show)

instance FromJSON SuggestOptions where
  parseJSON :: Value -> Parser SuggestOptions
parseJSON = String
-> (Object -> Parser SuggestOptions)
-> Value
-> Parser SuggestOptions
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"SuggestOptions" Object -> Parser SuggestOptions
parse
    where
      parse :: Object -> Parser SuggestOptions
parse Object
o = Text -> Double -> Maybe Int -> Maybe Text -> SuggestOptions
SuggestOptions
            (Text -> Double -> Maybe Int -> Maybe Text -> SuggestOptions)
-> Parser Text
-> Parser (Double -> Maybe Int -> Maybe Text -> SuggestOptions)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"text"
            Parser (Double -> Maybe Int -> Maybe Text -> SuggestOptions)
-> Parser Double
-> Parser (Maybe Int -> Maybe Text -> SuggestOptions)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Double
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"score"
            Parser (Maybe Int -> Maybe Text -> SuggestOptions)
-> Parser (Maybe Int) -> Parser (Maybe Text -> SuggestOptions)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"freq"
            Parser (Maybe Text -> SuggestOptions)
-> Parser (Maybe Text) -> Parser SuggestOptions
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"highlighted"

data SuggestResponse =
  SuggestResponse { SuggestResponse -> Text
suggestResponseText :: Text
                  , SuggestResponse -> Int
suggestResponseOffset :: Int
                  , SuggestResponse -> Int
suggestResponseLength :: Int
                  , SuggestResponse -> [SuggestOptions]
suggestResponseOptions :: [SuggestOptions]
                  }
  deriving (SuggestResponse -> SuggestResponse -> Bool
(SuggestResponse -> SuggestResponse -> Bool)
-> (SuggestResponse -> SuggestResponse -> Bool)
-> Eq SuggestResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SuggestResponse -> SuggestResponse -> Bool
$c/= :: SuggestResponse -> SuggestResponse -> Bool
== :: SuggestResponse -> SuggestResponse -> Bool
$c== :: SuggestResponse -> SuggestResponse -> Bool
Eq, ReadPrec [SuggestResponse]
ReadPrec SuggestResponse
Int -> ReadS SuggestResponse
ReadS [SuggestResponse]
(Int -> ReadS SuggestResponse)
-> ReadS [SuggestResponse]
-> ReadPrec SuggestResponse
-> ReadPrec [SuggestResponse]
-> Read SuggestResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SuggestResponse]
$creadListPrec :: ReadPrec [SuggestResponse]
readPrec :: ReadPrec SuggestResponse
$creadPrec :: ReadPrec SuggestResponse
readList :: ReadS [SuggestResponse]
$creadList :: ReadS [SuggestResponse]
readsPrec :: Int -> ReadS SuggestResponse
$creadsPrec :: Int -> ReadS SuggestResponse
Read, Int -> SuggestResponse -> ShowS
[SuggestResponse] -> ShowS
SuggestResponse -> String
(Int -> SuggestResponse -> ShowS)
-> (SuggestResponse -> String)
-> ([SuggestResponse] -> ShowS)
-> Show SuggestResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SuggestResponse] -> ShowS
$cshowList :: [SuggestResponse] -> ShowS
show :: SuggestResponse -> String
$cshow :: SuggestResponse -> String
showsPrec :: Int -> SuggestResponse -> ShowS
$cshowsPrec :: Int -> SuggestResponse -> ShowS
Show)

instance FromJSON SuggestResponse where
  parseJSON :: Value -> Parser SuggestResponse
parseJSON = String
-> (Object -> Parser SuggestResponse)
-> Value
-> Parser SuggestResponse
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"SuggestResponse" Object -> Parser SuggestResponse
parse
    where parse :: Object -> Parser SuggestResponse
parse Object
o = Text -> Int -> Int -> [SuggestOptions] -> SuggestResponse
SuggestResponse
                    (Text -> Int -> Int -> [SuggestOptions] -> SuggestResponse)
-> Parser Text
-> Parser (Int -> Int -> [SuggestOptions] -> SuggestResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"text"
                    Parser (Int -> Int -> [SuggestOptions] -> SuggestResponse)
-> Parser Int
-> Parser (Int -> [SuggestOptions] -> SuggestResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"offset"
                    Parser (Int -> [SuggestOptions] -> SuggestResponse)
-> Parser Int -> Parser ([SuggestOptions] -> SuggestResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"length"
                    Parser ([SuggestOptions] -> SuggestResponse)
-> Parser [SuggestOptions] -> Parser SuggestResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser [SuggestOptions]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"options"

data NamedSuggestionResponse = NamedSuggestionResponse
  { NamedSuggestionResponse -> Text
nsrName :: Text
  , NamedSuggestionResponse -> [SuggestResponse]
nsrResponses :: [SuggestResponse]
  } deriving (NamedSuggestionResponse -> NamedSuggestionResponse -> Bool
(NamedSuggestionResponse -> NamedSuggestionResponse -> Bool)
-> (NamedSuggestionResponse -> NamedSuggestionResponse -> Bool)
-> Eq NamedSuggestionResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NamedSuggestionResponse -> NamedSuggestionResponse -> Bool
$c/= :: NamedSuggestionResponse -> NamedSuggestionResponse -> Bool
== :: NamedSuggestionResponse -> NamedSuggestionResponse -> Bool
$c== :: NamedSuggestionResponse -> NamedSuggestionResponse -> Bool
Eq, ReadPrec [NamedSuggestionResponse]
ReadPrec NamedSuggestionResponse
Int -> ReadS NamedSuggestionResponse
ReadS [NamedSuggestionResponse]
(Int -> ReadS NamedSuggestionResponse)
-> ReadS [NamedSuggestionResponse]
-> ReadPrec NamedSuggestionResponse
-> ReadPrec [NamedSuggestionResponse]
-> Read NamedSuggestionResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [NamedSuggestionResponse]
$creadListPrec :: ReadPrec [NamedSuggestionResponse]
readPrec :: ReadPrec NamedSuggestionResponse
$creadPrec :: ReadPrec NamedSuggestionResponse
readList :: ReadS [NamedSuggestionResponse]
$creadList :: ReadS [NamedSuggestionResponse]
readsPrec :: Int -> ReadS NamedSuggestionResponse
$creadsPrec :: Int -> ReadS NamedSuggestionResponse
Read, Int -> NamedSuggestionResponse -> ShowS
[NamedSuggestionResponse] -> ShowS
NamedSuggestionResponse -> String
(Int -> NamedSuggestionResponse -> ShowS)
-> (NamedSuggestionResponse -> String)
-> ([NamedSuggestionResponse] -> ShowS)
-> Show NamedSuggestionResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NamedSuggestionResponse] -> ShowS
$cshowList :: [NamedSuggestionResponse] -> ShowS
show :: NamedSuggestionResponse -> String
$cshow :: NamedSuggestionResponse -> String
showsPrec :: Int -> NamedSuggestionResponse -> ShowS
$cshowsPrec :: Int -> NamedSuggestionResponse -> ShowS
Show)

instance FromJSON NamedSuggestionResponse where
  parseJSON :: Value -> Parser NamedSuggestionResponse
parseJSON (Object Object
o) = do
    Key
suggestionName' <- case Object -> [Pair]
forall v. KeyMap v -> [(Key, v)]
X.toList Object
o of
                        [(Key
x, Value
_)] -> Key -> Parser Key
forall (m :: * -> *) a. Monad m => a -> m a
return Key
x
                        [Pair]
_ -> String -> Parser Key
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"error parsing NamedSuggestionResponse name"
    [SuggestResponse]
suggestionResponses' <- Object
o Object -> Key -> Parser [SuggestResponse]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
suggestionName'
    NamedSuggestionResponse -> Parser NamedSuggestionResponse
forall (m :: * -> *) a. Monad m => a -> m a
return (NamedSuggestionResponse -> Parser NamedSuggestionResponse)
-> NamedSuggestionResponse -> Parser NamedSuggestionResponse
forall a b. (a -> b) -> a -> b
$ Text -> [SuggestResponse] -> NamedSuggestionResponse
NamedSuggestionResponse (Key -> Text
toText Key
suggestionName') [SuggestResponse]
suggestionResponses'

  parseJSON Value
x = String -> Value -> Parser NamedSuggestionResponse
forall a. String -> Value -> Parser a
typeMismatch String
"NamedSuggestionResponse" Value
x

data DirectGeneratorSuggestModeTypes = DirectGeneratorSuggestModeMissing
                                | DirectGeneratorSuggestModePopular
                                | DirectGeneratorSuggestModeAlways
  deriving (DirectGeneratorSuggestModeTypes
-> DirectGeneratorSuggestModeTypes -> Bool
(DirectGeneratorSuggestModeTypes
 -> DirectGeneratorSuggestModeTypes -> Bool)
-> (DirectGeneratorSuggestModeTypes
    -> DirectGeneratorSuggestModeTypes -> Bool)
-> Eq DirectGeneratorSuggestModeTypes
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DirectGeneratorSuggestModeTypes
-> DirectGeneratorSuggestModeTypes -> Bool
$c/= :: DirectGeneratorSuggestModeTypes
-> DirectGeneratorSuggestModeTypes -> Bool
== :: DirectGeneratorSuggestModeTypes
-> DirectGeneratorSuggestModeTypes -> Bool
$c== :: DirectGeneratorSuggestModeTypes
-> DirectGeneratorSuggestModeTypes -> Bool
Eq, Int -> DirectGeneratorSuggestModeTypes -> ShowS
[DirectGeneratorSuggestModeTypes] -> ShowS
DirectGeneratorSuggestModeTypes -> String
(Int -> DirectGeneratorSuggestModeTypes -> ShowS)
-> (DirectGeneratorSuggestModeTypes -> String)
-> ([DirectGeneratorSuggestModeTypes] -> ShowS)
-> Show DirectGeneratorSuggestModeTypes
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DirectGeneratorSuggestModeTypes] -> ShowS
$cshowList :: [DirectGeneratorSuggestModeTypes] -> ShowS
show :: DirectGeneratorSuggestModeTypes -> String
$cshow :: DirectGeneratorSuggestModeTypes -> String
showsPrec :: Int -> DirectGeneratorSuggestModeTypes -> ShowS
$cshowsPrec :: Int -> DirectGeneratorSuggestModeTypes -> ShowS
Show)

instance ToJSON DirectGeneratorSuggestModeTypes where
  toJSON :: DirectGeneratorSuggestModeTypes -> Value
toJSON DirectGeneratorSuggestModeTypes
DirectGeneratorSuggestModeMissing = Value
"missing"
  toJSON DirectGeneratorSuggestModeTypes
DirectGeneratorSuggestModePopular = Value
"popular"
  toJSON DirectGeneratorSuggestModeTypes
DirectGeneratorSuggestModeAlways = Value
"always"

instance FromJSON DirectGeneratorSuggestModeTypes where
  parseJSON :: Value -> Parser DirectGeneratorSuggestModeTypes
parseJSON = String
-> (Text -> Parser DirectGeneratorSuggestModeTypes)
-> Value
-> Parser DirectGeneratorSuggestModeTypes
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"DirectGeneratorSuggestModeTypes" Text -> Parser DirectGeneratorSuggestModeTypes
forall a (f :: * -> *).
(Eq a, IsString a, MonadFail f, Show a) =>
a -> f DirectGeneratorSuggestModeTypes
parse
    where
      parse :: a -> f DirectGeneratorSuggestModeTypes
parse a
"missing" =
        DirectGeneratorSuggestModeTypes
-> f DirectGeneratorSuggestModeTypes
forall (f :: * -> *) a. Applicative f => a -> f a
pure DirectGeneratorSuggestModeTypes
DirectGeneratorSuggestModeMissing
      parse a
"popular" =
        DirectGeneratorSuggestModeTypes
-> f DirectGeneratorSuggestModeTypes
forall (f :: * -> *) a. Applicative f => a -> f a
pure DirectGeneratorSuggestModeTypes
DirectGeneratorSuggestModePopular
      parse a
"always" =
        DirectGeneratorSuggestModeTypes
-> f DirectGeneratorSuggestModeTypes
forall (f :: * -> *) a. Applicative f => a -> f a
pure DirectGeneratorSuggestModeTypes
DirectGeneratorSuggestModeAlways
      parse a
f =
        String -> f DirectGeneratorSuggestModeTypes
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"Unexpected DirectGeneratorSuggestModeTypes: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> a -> String
forall a. Show a => a -> String
show a
f)

data DirectGenerators = DirectGenerators
  { DirectGenerators -> FieldName
directGeneratorsField :: FieldName
  , DirectGenerators -> Maybe Int
directGeneratorsSize :: Maybe Int
  , DirectGenerators -> DirectGeneratorSuggestModeTypes
directGeneratorSuggestMode :: DirectGeneratorSuggestModeTypes
  , DirectGenerators -> Maybe Double
directGeneratorMaxEdits :: Maybe Double
  , DirectGenerators -> Maybe Int
directGeneratorPrefixLength :: Maybe Int
  , DirectGenerators -> Maybe Int
directGeneratorMinWordLength :: Maybe Int
  , DirectGenerators -> Maybe Int
directGeneratorMaxInspections :: Maybe Int
  , DirectGenerators -> Maybe Double
directGeneratorMinDocFreq :: Maybe Double
  , DirectGenerators -> Maybe Double
directGeneratorMaxTermFreq :: Maybe Double
  , DirectGenerators -> Maybe Text
directGeneratorPreFilter :: Maybe Text
  , DirectGenerators -> Maybe Text
directGeneratorPostFilter :: Maybe Text
  } deriving (DirectGenerators -> DirectGenerators -> Bool
(DirectGenerators -> DirectGenerators -> Bool)
-> (DirectGenerators -> DirectGenerators -> Bool)
-> Eq DirectGenerators
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DirectGenerators -> DirectGenerators -> Bool
$c/= :: DirectGenerators -> DirectGenerators -> Bool
== :: DirectGenerators -> DirectGenerators -> Bool
$c== :: DirectGenerators -> DirectGenerators -> Bool
Eq, Int -> DirectGenerators -> ShowS
[DirectGenerators] -> ShowS
DirectGenerators -> String
(Int -> DirectGenerators -> ShowS)
-> (DirectGenerators -> String)
-> ([DirectGenerators] -> ShowS)
-> Show DirectGenerators
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DirectGenerators] -> ShowS
$cshowList :: [DirectGenerators] -> ShowS
show :: DirectGenerators -> String
$cshow :: DirectGenerators -> String
showsPrec :: Int -> DirectGenerators -> ShowS
$cshowsPrec :: Int -> DirectGenerators -> ShowS
Show)

instance ToJSON DirectGenerators where
  toJSON :: DirectGenerators -> Value
toJSON DirectGenerators{Maybe Double
Maybe Int
Maybe Text
FieldName
DirectGeneratorSuggestModeTypes
directGeneratorPostFilter :: Maybe Text
directGeneratorPreFilter :: Maybe Text
directGeneratorMaxTermFreq :: Maybe Double
directGeneratorMinDocFreq :: Maybe Double
directGeneratorMaxInspections :: Maybe Int
directGeneratorMinWordLength :: Maybe Int
directGeneratorPrefixLength :: Maybe Int
directGeneratorMaxEdits :: Maybe Double
directGeneratorSuggestMode :: DirectGeneratorSuggestModeTypes
directGeneratorsSize :: Maybe Int
directGeneratorsField :: FieldName
directGeneratorPostFilter :: DirectGenerators -> Maybe Text
directGeneratorPreFilter :: DirectGenerators -> Maybe Text
directGeneratorMaxTermFreq :: DirectGenerators -> Maybe Double
directGeneratorMinDocFreq :: DirectGenerators -> Maybe Double
directGeneratorMaxInspections :: DirectGenerators -> Maybe Int
directGeneratorMinWordLength :: DirectGenerators -> Maybe Int
directGeneratorPrefixLength :: DirectGenerators -> Maybe Int
directGeneratorMaxEdits :: DirectGenerators -> Maybe Double
directGeneratorSuggestMode :: DirectGenerators -> DirectGeneratorSuggestModeTypes
directGeneratorsSize :: DirectGenerators -> Maybe Int
directGeneratorsField :: DirectGenerators -> FieldName
..} =
    [Pair] -> Value
omitNulls [ Key
"field" Key -> FieldName -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= FieldName
directGeneratorsField
              , Key
"size" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Int
directGeneratorsSize
              , Key
"suggest_mode" Key -> DirectGeneratorSuggestModeTypes -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= DirectGeneratorSuggestModeTypes
directGeneratorSuggestMode
              , Key
"max_edits" Key -> Maybe Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Double
directGeneratorMaxEdits
              , Key
"prefix_length" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Int
directGeneratorPrefixLength
              , Key
"min_word_length" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Int
directGeneratorMinWordLength
              , Key
"max_inspections" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Int
directGeneratorMaxInspections
              , Key
"min_doc_freq" Key -> Maybe Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Double
directGeneratorMinDocFreq
              , Key
"max_term_freq" Key -> Maybe Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Double
directGeneratorMaxTermFreq
              , Key
"pre_filter" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Text
directGeneratorPreFilter
              , Key
"post_filter" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Text
directGeneratorPostFilter
              ]

instance FromJSON DirectGenerators where
  parseJSON :: Value -> Parser DirectGenerators
parseJSON = String
-> (Object -> Parser DirectGenerators)
-> Value
-> Parser DirectGenerators
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"DirectGenerators" Object -> Parser DirectGenerators
parse
    where parse :: Object -> Parser DirectGenerators
parse Object
o = FieldName
-> Maybe Int
-> DirectGeneratorSuggestModeTypes
-> Maybe Double
-> Maybe Int
-> Maybe Int
-> Maybe Int
-> Maybe Double
-> Maybe Double
-> Maybe Text
-> Maybe Text
-> DirectGenerators
DirectGenerators
                      (FieldName
 -> Maybe Int
 -> DirectGeneratorSuggestModeTypes
 -> Maybe Double
 -> Maybe Int
 -> Maybe Int
 -> Maybe Int
 -> Maybe Double
 -> Maybe Double
 -> Maybe Text
 -> Maybe Text
 -> DirectGenerators)
-> Parser FieldName
-> Parser
     (Maybe Int
      -> DirectGeneratorSuggestModeTypes
      -> Maybe Double
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Double
      -> Maybe Double
      -> Maybe Text
      -> Maybe Text
      -> DirectGenerators)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser FieldName
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"field"
                      Parser
  (Maybe Int
   -> DirectGeneratorSuggestModeTypes
   -> Maybe Double
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Double
   -> Maybe Double
   -> Maybe Text
   -> Maybe Text
   -> DirectGenerators)
-> Parser (Maybe Int)
-> Parser
     (DirectGeneratorSuggestModeTypes
      -> Maybe Double
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Double
      -> Maybe Double
      -> Maybe Text
      -> Maybe Text
      -> DirectGenerators)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"size"
                      Parser
  (DirectGeneratorSuggestModeTypes
   -> Maybe Double
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Double
   -> Maybe Double
   -> Maybe Text
   -> Maybe Text
   -> DirectGenerators)
-> Parser DirectGeneratorSuggestModeTypes
-> Parser
     (Maybe Double
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Double
      -> Maybe Double
      -> Maybe Text
      -> Maybe Text
      -> DirectGenerators)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser DirectGeneratorSuggestModeTypes
forall a. FromJSON a => Object -> Key -> Parser a
.:  Key
"suggest_mode"
                      Parser
  (Maybe Double
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Double
   -> Maybe Double
   -> Maybe Text
   -> Maybe Text
   -> DirectGenerators)
-> Parser (Maybe Double)
-> Parser
     (Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Double
      -> Maybe Double
      -> Maybe Text
      -> Maybe Text
      -> DirectGenerators)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"max_edits"
                      Parser
  (Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Double
   -> Maybe Double
   -> Maybe Text
   -> Maybe Text
   -> DirectGenerators)
-> Parser (Maybe Int)
-> Parser
     (Maybe Int
      -> Maybe Int
      -> Maybe Double
      -> Maybe Double
      -> Maybe Text
      -> Maybe Text
      -> DirectGenerators)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"prefix_length"
                      Parser
  (Maybe Int
   -> Maybe Int
   -> Maybe Double
   -> Maybe Double
   -> Maybe Text
   -> Maybe Text
   -> DirectGenerators)
-> Parser (Maybe Int)
-> Parser
     (Maybe Int
      -> Maybe Double
      -> Maybe Double
      -> Maybe Text
      -> Maybe Text
      -> DirectGenerators)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"min_word_length"
                      Parser
  (Maybe Int
   -> Maybe Double
   -> Maybe Double
   -> Maybe Text
   -> Maybe Text
   -> DirectGenerators)
-> Parser (Maybe Int)
-> Parser
     (Maybe Double
      -> Maybe Double -> Maybe Text -> Maybe Text -> DirectGenerators)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"max_inspections"
                      Parser
  (Maybe Double
   -> Maybe Double -> Maybe Text -> Maybe Text -> DirectGenerators)
-> Parser (Maybe Double)
-> Parser
     (Maybe Double -> Maybe Text -> Maybe Text -> DirectGenerators)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"min_doc_freq"
                      Parser
  (Maybe Double -> Maybe Text -> Maybe Text -> DirectGenerators)
-> Parser (Maybe Double)
-> Parser (Maybe Text -> Maybe Text -> DirectGenerators)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"max_term_freq"
                      Parser (Maybe Text -> Maybe Text -> DirectGenerators)
-> Parser (Maybe Text) -> Parser (Maybe Text -> DirectGenerators)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"pre_filter"
                      Parser (Maybe Text -> DirectGenerators)
-> Parser (Maybe Text) -> Parser DirectGenerators
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"post_filter"

mkDirectGenerators :: FieldName -> DirectGenerators
mkDirectGenerators :: FieldName -> DirectGenerators
mkDirectGenerators FieldName
fn =
  FieldName
-> Maybe Int
-> DirectGeneratorSuggestModeTypes
-> Maybe Double
-> Maybe Int
-> Maybe Int
-> Maybe Int
-> Maybe Double
-> Maybe Double
-> Maybe Text
-> Maybe Text
-> DirectGenerators
DirectGenerators
  FieldName
fn
  Maybe Int
forall a. Maybe a
Nothing
  DirectGeneratorSuggestModeTypes
DirectGeneratorSuggestModeMissing
  Maybe Double
forall a. Maybe a
Nothing Maybe Int
forall a. Maybe a
Nothing Maybe Int
forall a. Maybe a
Nothing Maybe Int
forall a. Maybe a
Nothing Maybe Double
forall a. Maybe a
Nothing Maybe Double
forall a. Maybe a
Nothing Maybe Text
forall a. Maybe a
Nothing Maybe Text
forall a. Maybe a
Nothing