{-# LANGUAGE OverloadedStrings #-}
module Database.Bloodhound.Internal.Versions.Common.Types.Query.MoreLikeThis
( MoreLikeThisQuery (..),
)
where
import Database.Bloodhound.Internal.Utils.Imports
import Database.Bloodhound.Internal.Versions.Common.Types.Newtypes
import GHC.Generics
data MoreLikeThisQuery = MoreLikeThisQuery
{ MoreLikeThisQuery -> Text
moreLikeThisText :: Text,
MoreLikeThisQuery -> Maybe (NonEmpty FieldName)
moreLikeThisFields :: Maybe (NonEmpty FieldName),
MoreLikeThisQuery -> Maybe PercentMatch
moreLikeThisPercentMatch :: Maybe PercentMatch,
MoreLikeThisQuery -> Maybe MinimumTermFrequency
moreLikeThisMinimumTermFreq :: Maybe MinimumTermFrequency,
MoreLikeThisQuery -> Maybe MaxQueryTerms
moreLikeThisMaxQueryTerms :: Maybe MaxQueryTerms,
MoreLikeThisQuery -> Maybe (NonEmpty StopWord)
moreLikeThisStopWords :: Maybe (NonEmpty StopWord),
MoreLikeThisQuery -> Maybe MinDocFrequency
moreLikeThisMinDocFrequency :: Maybe MinDocFrequency,
MoreLikeThisQuery -> Maybe MaxDocFrequency
moreLikeThisMaxDocFrequency :: Maybe MaxDocFrequency,
MoreLikeThisQuery -> Maybe MinWordLength
moreLikeThisMinWordLength :: Maybe MinWordLength,
MoreLikeThisQuery -> Maybe MaxWordLength
moreLikeThisMaxWordLength :: Maybe MaxWordLength,
MoreLikeThisQuery -> Maybe BoostTerms
moreLikeThisBoostTerms :: Maybe BoostTerms,
MoreLikeThisQuery -> Maybe Boost
moreLikeThisBoost :: Maybe Boost,
MoreLikeThisQuery -> Maybe Analyzer
moreLikeThisAnalyzer :: Maybe Analyzer
}
deriving stock (MoreLikeThisQuery -> MoreLikeThisQuery -> Bool
(MoreLikeThisQuery -> MoreLikeThisQuery -> Bool)
-> (MoreLikeThisQuery -> MoreLikeThisQuery -> Bool)
-> Eq MoreLikeThisQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MoreLikeThisQuery -> MoreLikeThisQuery -> Bool
== :: MoreLikeThisQuery -> MoreLikeThisQuery -> Bool
$c/= :: MoreLikeThisQuery -> MoreLikeThisQuery -> Bool
/= :: MoreLikeThisQuery -> MoreLikeThisQuery -> Bool
Eq, Int -> MoreLikeThisQuery -> ShowS
[MoreLikeThisQuery] -> ShowS
MoreLikeThisQuery -> String
(Int -> MoreLikeThisQuery -> ShowS)
-> (MoreLikeThisQuery -> String)
-> ([MoreLikeThisQuery] -> ShowS)
-> Show MoreLikeThisQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MoreLikeThisQuery -> ShowS
showsPrec :: Int -> MoreLikeThisQuery -> ShowS
$cshow :: MoreLikeThisQuery -> String
show :: MoreLikeThisQuery -> String
$cshowList :: [MoreLikeThisQuery] -> ShowS
showList :: [MoreLikeThisQuery] -> ShowS
Show, (forall x. MoreLikeThisQuery -> Rep MoreLikeThisQuery x)
-> (forall x. Rep MoreLikeThisQuery x -> MoreLikeThisQuery)
-> Generic MoreLikeThisQuery
forall x. Rep MoreLikeThisQuery x -> MoreLikeThisQuery
forall x. MoreLikeThisQuery -> Rep MoreLikeThisQuery x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. MoreLikeThisQuery -> Rep MoreLikeThisQuery x
from :: forall x. MoreLikeThisQuery -> Rep MoreLikeThisQuery x
$cto :: forall x. Rep MoreLikeThisQuery x -> MoreLikeThisQuery
to :: forall x. Rep MoreLikeThisQuery x -> MoreLikeThisQuery
Generic)
instance ToJSON MoreLikeThisQuery where
toJSON :: MoreLikeThisQuery -> Value
toJSON
( MoreLikeThisQuery
Text
text
Maybe (NonEmpty FieldName)
fields
Maybe PercentMatch
percent
Maybe MinimumTermFrequency
mtf
Maybe MaxQueryTerms
mqt
Maybe (NonEmpty StopWord)
stopwords
Maybe MinDocFrequency
mindf
Maybe MaxDocFrequency
maxdf
Maybe MinWordLength
minwl
Maybe MaxWordLength
maxwl
Maybe BoostTerms
boostTerms
Maybe Boost
boost
Maybe Analyzer
analyzer
) =
[(Key, Value)] -> Value
omitNulls [(Key, Value)]
base
where
base :: [(Key, Value)]
base =
[ Key
"like_text" Key -> Text -> (Key, Value)
forall v. ToJSON v => Key -> v -> (Key, Value)
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
text,
Key
"fields" Key -> Maybe (NonEmpty FieldName) -> (Key, Value)
forall v. ToJSON v => Key -> v -> (Key, Value)
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe (NonEmpty FieldName)
fields,
Key
"percent_terms_to_match" Key -> Maybe PercentMatch -> (Key, Value)
forall v. ToJSON v => Key -> v -> (Key, Value)
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe PercentMatch
percent,
Key
"min_term_freq" Key -> Maybe MinimumTermFrequency -> (Key, Value)
forall v. ToJSON v => Key -> v -> (Key, Value)
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe MinimumTermFrequency
mtf,
Key
"max_query_terms" Key -> Maybe MaxQueryTerms -> (Key, Value)
forall v. ToJSON v => Key -> v -> (Key, Value)
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe MaxQueryTerms
mqt,
Key
"stop_words" Key -> Maybe (NonEmpty StopWord) -> (Key, Value)
forall v. ToJSON v => Key -> v -> (Key, Value)
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe (NonEmpty StopWord)
stopwords,
Key
"min_doc_freq" Key -> Maybe MinDocFrequency -> (Key, Value)
forall v. ToJSON v => Key -> v -> (Key, Value)
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe MinDocFrequency
mindf,
Key
"max_doc_freq" Key -> Maybe MaxDocFrequency -> (Key, Value)
forall v. ToJSON v => Key -> v -> (Key, Value)
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe MaxDocFrequency
maxdf,
Key
"min_word_length" Key -> Maybe MinWordLength -> (Key, Value)
forall v. ToJSON v => Key -> v -> (Key, Value)
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe MinWordLength
minwl,
Key
"max_word_length" Key -> Maybe MaxWordLength -> (Key, Value)
forall v. ToJSON v => Key -> v -> (Key, Value)
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe MaxWordLength
maxwl,
Key
"boost_terms" Key -> Maybe BoostTerms -> (Key, Value)
forall v. ToJSON v => Key -> v -> (Key, Value)
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe BoostTerms
boostTerms,
Key
"boost" Key -> Maybe Boost -> (Key, Value)
forall v. ToJSON v => Key -> v -> (Key, Value)
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe Boost
boost,
Key
"analyzer" Key -> Maybe Analyzer -> (Key, Value)
forall v. ToJSON v => Key -> v -> (Key, Value)
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe Analyzer
analyzer
]
instance FromJSON MoreLikeThisQuery where
parseJSON :: Value -> Parser MoreLikeThisQuery
parseJSON = String
-> (Object -> Parser MoreLikeThisQuery)
-> Value
-> Parser MoreLikeThisQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"MoreLikeThisQuery" Object -> Parser MoreLikeThisQuery
parse
where
parse :: Object -> Parser MoreLikeThisQuery
parse Object
o =
Text
-> Maybe (NonEmpty FieldName)
-> Maybe PercentMatch
-> Maybe MinimumTermFrequency
-> Maybe MaxQueryTerms
-> Maybe (NonEmpty StopWord)
-> Maybe MinDocFrequency
-> Maybe MaxDocFrequency
-> Maybe MinWordLength
-> Maybe MaxWordLength
-> Maybe BoostTerms
-> Maybe Boost
-> Maybe Analyzer
-> MoreLikeThisQuery
MoreLikeThisQuery
(Text
-> Maybe (NonEmpty FieldName)
-> Maybe PercentMatch
-> Maybe MinimumTermFrequency
-> Maybe MaxQueryTerms
-> Maybe (NonEmpty StopWord)
-> Maybe MinDocFrequency
-> Maybe MaxDocFrequency
-> Maybe MinWordLength
-> Maybe MaxWordLength
-> Maybe BoostTerms
-> Maybe Boost
-> Maybe Analyzer
-> MoreLikeThisQuery)
-> Parser Text
-> Parser
(Maybe (NonEmpty FieldName)
-> Maybe PercentMatch
-> Maybe MinimumTermFrequency
-> Maybe MaxQueryTerms
-> Maybe (NonEmpty StopWord)
-> Maybe MinDocFrequency
-> Maybe MaxDocFrequency
-> Maybe MinWordLength
-> Maybe MaxWordLength
-> Maybe BoostTerms
-> Maybe Boost
-> Maybe Analyzer
-> MoreLikeThisQuery)
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
"like_text"
Parser
(Maybe (NonEmpty FieldName)
-> Maybe PercentMatch
-> Maybe MinimumTermFrequency
-> Maybe MaxQueryTerms
-> Maybe (NonEmpty StopWord)
-> Maybe MinDocFrequency
-> Maybe MaxDocFrequency
-> Maybe MinWordLength
-> Maybe MaxWordLength
-> Maybe BoostTerms
-> Maybe Boost
-> Maybe Analyzer
-> MoreLikeThisQuery)
-> Parser (Maybe (NonEmpty FieldName))
-> Parser
(Maybe PercentMatch
-> Maybe MinimumTermFrequency
-> Maybe MaxQueryTerms
-> Maybe (NonEmpty StopWord)
-> Maybe MinDocFrequency
-> Maybe MaxDocFrequency
-> Maybe MinWordLength
-> Maybe MaxWordLength
-> Maybe BoostTerms
-> Maybe Boost
-> Maybe Analyzer
-> MoreLikeThisQuery)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe (NonEmpty FieldName))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"fields"
Parser
(Maybe PercentMatch
-> Maybe MinimumTermFrequency
-> Maybe MaxQueryTerms
-> Maybe (NonEmpty StopWord)
-> Maybe MinDocFrequency
-> Maybe MaxDocFrequency
-> Maybe MinWordLength
-> Maybe MaxWordLength
-> Maybe BoostTerms
-> Maybe Boost
-> Maybe Analyzer
-> MoreLikeThisQuery)
-> Parser (Maybe PercentMatch)
-> Parser
(Maybe MinimumTermFrequency
-> Maybe MaxQueryTerms
-> Maybe (NonEmpty StopWord)
-> Maybe MinDocFrequency
-> Maybe MaxDocFrequency
-> Maybe MinWordLength
-> Maybe MaxWordLength
-> Maybe BoostTerms
-> Maybe Boost
-> Maybe Analyzer
-> MoreLikeThisQuery)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe PercentMatch)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"percent_terms_to_match"
Parser
(Maybe MinimumTermFrequency
-> Maybe MaxQueryTerms
-> Maybe (NonEmpty StopWord)
-> Maybe MinDocFrequency
-> Maybe MaxDocFrequency
-> Maybe MinWordLength
-> Maybe MaxWordLength
-> Maybe BoostTerms
-> Maybe Boost
-> Maybe Analyzer
-> MoreLikeThisQuery)
-> Parser (Maybe MinimumTermFrequency)
-> Parser
(Maybe MaxQueryTerms
-> Maybe (NonEmpty StopWord)
-> Maybe MinDocFrequency
-> Maybe MaxDocFrequency
-> Maybe MinWordLength
-> Maybe MaxWordLength
-> Maybe BoostTerms
-> Maybe Boost
-> Maybe Analyzer
-> MoreLikeThisQuery)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe MinimumTermFrequency)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"min_term_freq"
Parser
(Maybe MaxQueryTerms
-> Maybe (NonEmpty StopWord)
-> Maybe MinDocFrequency
-> Maybe MaxDocFrequency
-> Maybe MinWordLength
-> Maybe MaxWordLength
-> Maybe BoostTerms
-> Maybe Boost
-> Maybe Analyzer
-> MoreLikeThisQuery)
-> Parser (Maybe MaxQueryTerms)
-> Parser
(Maybe (NonEmpty StopWord)
-> Maybe MinDocFrequency
-> Maybe MaxDocFrequency
-> Maybe MinWordLength
-> Maybe MaxWordLength
-> Maybe BoostTerms
-> Maybe Boost
-> Maybe Analyzer
-> MoreLikeThisQuery)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe MaxQueryTerms)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"max_query_terms"
Parser
(Maybe (NonEmpty StopWord)
-> Maybe MinDocFrequency
-> Maybe MaxDocFrequency
-> Maybe MinWordLength
-> Maybe MaxWordLength
-> Maybe BoostTerms
-> Maybe Boost
-> Maybe Analyzer
-> MoreLikeThisQuery)
-> Parser (Maybe (NonEmpty StopWord))
-> Parser
(Maybe MinDocFrequency
-> Maybe MaxDocFrequency
-> Maybe MinWordLength
-> Maybe MaxWordLength
-> Maybe BoostTerms
-> Maybe Boost
-> Maybe Analyzer
-> MoreLikeThisQuery)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe (NonEmpty StopWord))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"stop_words"
Parser
(Maybe MinDocFrequency
-> Maybe MaxDocFrequency
-> Maybe MinWordLength
-> Maybe MaxWordLength
-> Maybe BoostTerms
-> Maybe Boost
-> Maybe Analyzer
-> MoreLikeThisQuery)
-> Parser (Maybe MinDocFrequency)
-> Parser
(Maybe MaxDocFrequency
-> Maybe MinWordLength
-> Maybe MaxWordLength
-> Maybe BoostTerms
-> Maybe Boost
-> Maybe Analyzer
-> MoreLikeThisQuery)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe MinDocFrequency)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"min_doc_freq"
Parser
(Maybe MaxDocFrequency
-> Maybe MinWordLength
-> Maybe MaxWordLength
-> Maybe BoostTerms
-> Maybe Boost
-> Maybe Analyzer
-> MoreLikeThisQuery)
-> Parser (Maybe MaxDocFrequency)
-> Parser
(Maybe MinWordLength
-> Maybe MaxWordLength
-> Maybe BoostTerms
-> Maybe Boost
-> Maybe Analyzer
-> MoreLikeThisQuery)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe MaxDocFrequency)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"max_doc_freq"
Parser
(Maybe MinWordLength
-> Maybe MaxWordLength
-> Maybe BoostTerms
-> Maybe Boost
-> Maybe Analyzer
-> MoreLikeThisQuery)
-> Parser (Maybe MinWordLength)
-> Parser
(Maybe MaxWordLength
-> Maybe BoostTerms
-> Maybe Boost
-> Maybe Analyzer
-> MoreLikeThisQuery)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe MinWordLength)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"min_word_length"
Parser
(Maybe MaxWordLength
-> Maybe BoostTerms
-> Maybe Boost
-> Maybe Analyzer
-> MoreLikeThisQuery)
-> Parser (Maybe MaxWordLength)
-> Parser
(Maybe BoostTerms
-> Maybe Boost -> Maybe Analyzer -> MoreLikeThisQuery)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe MaxWordLength)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"max_word_length"
Parser
(Maybe BoostTerms
-> Maybe Boost -> Maybe Analyzer -> MoreLikeThisQuery)
-> Parser (Maybe BoostTerms)
-> Parser (Maybe Boost -> Maybe Analyzer -> MoreLikeThisQuery)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe BoostTerms)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"boost_terms"
Parser (Maybe Boost -> Maybe Analyzer -> MoreLikeThisQuery)
-> Parser (Maybe Boost)
-> Parser (Maybe Analyzer -> MoreLikeThisQuery)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Boost)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"boost"
Parser (Maybe Analyzer -> MoreLikeThisQuery)
-> Parser (Maybe Analyzer) -> Parser MoreLikeThisQuery
forall a b. Parser (a -> b) -> Parser a -> Parser b
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"