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

module Database.Bloodhound.Internal.Query
  ( module X
  , module Database.Bloodhound.Internal.Query
  ) where

import           Bloodhound.Import

import qualified Data.Aeson.KeyMap   as X
import qualified Data.HashMap.Strict as HM
import qualified Data.Text           as T

import           Database.Bloodhound.Common.Script as X
import           Database.Bloodhound.Internal.Newtypes

data Query =
    TermQuery                   Term (Maybe Boost)
  | TermsQuery                  Key (NonEmpty Text)
  | QueryMatchQuery             MatchQuery
  | QueryMultiMatchQuery        MultiMatchQuery
  | QueryBoolQuery              BoolQuery
  | QueryBoostingQuery          BoostingQuery
  | QueryCommonTermsQuery       CommonTermsQuery
  | ConstantScoreQuery          Query Boost
  | QueryFunctionScoreQuery     FunctionScoreQuery
  | QueryDisMaxQuery            DisMaxQuery
  | QueryFuzzyLikeThisQuery     FuzzyLikeThisQuery
  | QueryFuzzyLikeFieldQuery    FuzzyLikeFieldQuery
  | QueryFuzzyQuery             FuzzyQuery
  | QueryHasChildQuery          HasChildQuery
  | QueryHasParentQuery         HasParentQuery
  | IdsQuery                    [DocId]
  | QueryIndicesQuery           IndicesQuery
  | MatchAllQuery               (Maybe Boost)
  | QueryMoreLikeThisQuery      MoreLikeThisQuery
  | QueryMoreLikeThisFieldQuery MoreLikeThisFieldQuery
  | QueryNestedQuery            NestedQuery
  | QueryPrefixQuery            PrefixQuery
  | QueryQueryStringQuery       QueryStringQuery
  | QuerySimpleQueryStringQuery SimpleQueryStringQuery
  | QueryRangeQuery             RangeQuery
  | QueryRegexpQuery            RegexpQuery
  | QueryExistsQuery            FieldName
  | QueryMatchNoneQuery
  | QueryWildcardQuery          WildcardQuery
  deriving (Query -> Query -> Bool
(Query -> Query -> Bool) -> (Query -> Query -> Bool) -> Eq Query
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Query -> Query -> Bool
$c/= :: Query -> Query -> Bool
== :: Query -> Query -> Bool
$c== :: Query -> Query -> Bool
Eq, Int -> Query -> ShowS
[Query] -> ShowS
Query -> String
(Int -> Query -> ShowS)
-> (Query -> String) -> ([Query] -> ShowS) -> Show Query
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Query] -> ShowS
$cshowList :: [Query] -> ShowS
show :: Query -> String
$cshow :: Query -> String
showsPrec :: Int -> Query -> ShowS
$cshowsPrec :: Int -> Query -> ShowS
Show)

instance ToJSON Query where
  toJSON :: Query -> Value
toJSON (TermQuery (Term Key
termQueryField Text
termQueryValue) Maybe Boost
boost) =
    [Pair] -> Value
object [ Key
"term" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.=
             [Pair] -> Value
object [Key
termQueryField Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Pair] -> Value
object [Pair]
merged]]
    where
      base :: [Pair]
base = [ Key
"value" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
termQueryValue ]
      boosted :: [Pair]
boosted = [Pair] -> (Boost -> [Pair]) -> Maybe Boost -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (Pair -> [Pair]
forall (m :: * -> *) a. Monad m => a -> m a
return (Pair -> [Pair]) -> (Boost -> Pair) -> Boost -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key
"boost" Key -> Boost -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.=)) Maybe Boost
boost
      merged :: [Pair]
merged = [Pair] -> [Pair] -> [Pair]
forall a. Monoid a => a -> a -> a
mappend [Pair]
base [Pair]
boosted

  toJSON (TermsQuery Key
fieldName NonEmpty Text
terms) =
    [Pair] -> Value
object [ Key
"terms" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Pair] -> Value
object [Pair]
conjoined ]
    where conjoined :: [Pair]
conjoined = [Key
fieldName Key -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= NonEmpty Text
terms]

  toJSON (IdsQuery [DocId]
docIds) =
    [Pair] -> Value
object [ Key
"ids" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Pair] -> Value
object [Pair]
conjoined ]
    where conjoined :: [Pair]
conjoined = [ Key
"values" Key -> [Value] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= (DocId -> Value) -> [DocId] -> [Value]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DocId -> Value
forall a. ToJSON a => a -> Value
toJSON [DocId]
docIds ]

  toJSON (QueryQueryStringQuery QueryStringQuery
qQueryStringQuery) =
    [Pair] -> Value
object [ Key
"query_string" Key -> QueryStringQuery -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= QueryStringQuery
qQueryStringQuery ]

  toJSON (QueryMatchQuery MatchQuery
matchQuery) =
    [Pair] -> Value
object [ Key
"match" Key -> MatchQuery -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= MatchQuery
matchQuery ]

  toJSON (QueryMultiMatchQuery MultiMatchQuery
multiMatchQuery) =
      MultiMatchQuery -> Value
forall a. ToJSON a => a -> Value
toJSON MultiMatchQuery
multiMatchQuery

  toJSON (QueryBoolQuery BoolQuery
boolQuery) =
    [Pair] -> Value
object [ Key
"bool" Key -> BoolQuery -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= BoolQuery
boolQuery ]

  toJSON (QueryBoostingQuery BoostingQuery
boostingQuery) =
    [Pair] -> Value
object [ Key
"boosting" Key -> BoostingQuery -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= BoostingQuery
boostingQuery ]

  toJSON (QueryCommonTermsQuery CommonTermsQuery
commonTermsQuery) =
    [Pair] -> Value
object [ Key
"common" Key -> CommonTermsQuery -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= CommonTermsQuery
commonTermsQuery ]

  toJSON (ConstantScoreQuery Query
query Boost
boost) =
    [Pair] -> Value
object [Key
"constant_score" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Pair] -> Value
object [Key
"filter" Key -> Query -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Query
query
                                       , Key
"boost" Key -> Boost -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Boost
boost]]

  toJSON (QueryFunctionScoreQuery FunctionScoreQuery
functionScoreQuery) =
    [Pair] -> Value
object [ Key
"function_score" Key -> FunctionScoreQuery -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= FunctionScoreQuery
functionScoreQuery ]

  toJSON (QueryDisMaxQuery DisMaxQuery
disMaxQuery) =
    [Pair] -> Value
object [ Key
"dis_max" Key -> DisMaxQuery -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= DisMaxQuery
disMaxQuery ]

  toJSON (QueryFuzzyLikeThisQuery FuzzyLikeThisQuery
fuzzyQuery) =
    [Pair] -> Value
object [ Key
"fuzzy_like_this" Key -> FuzzyLikeThisQuery -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= FuzzyLikeThisQuery
fuzzyQuery ]

  toJSON (QueryFuzzyLikeFieldQuery FuzzyLikeFieldQuery
fuzzyFieldQuery) =
    [Pair] -> Value
object [ Key
"fuzzy_like_this_field" Key -> FuzzyLikeFieldQuery -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= FuzzyLikeFieldQuery
fuzzyFieldQuery ]

  toJSON (QueryFuzzyQuery FuzzyQuery
fuzzyQuery) =
    [Pair] -> Value
object [ Key
"fuzzy" Key -> FuzzyQuery -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= FuzzyQuery
fuzzyQuery ]

  toJSON (QueryHasChildQuery HasChildQuery
childQuery) =
    [Pair] -> Value
object [ Key
"has_child" Key -> HasChildQuery -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= HasChildQuery
childQuery ]

  toJSON (QueryHasParentQuery HasParentQuery
parentQuery) =
    [Pair] -> Value
object [ Key
"has_parent" Key -> HasParentQuery -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= HasParentQuery
parentQuery ]

  toJSON (QueryIndicesQuery IndicesQuery
qIndicesQuery) =
    [Pair] -> Value
object [ Key
"indices" Key -> IndicesQuery -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= IndicesQuery
qIndicesQuery ]

  toJSON (MatchAllQuery Maybe Boost
boost) =
    [Pair] -> Value
object [ Key
"match_all" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Pair] -> Value
omitNulls [ Key
"boost" Key -> Maybe Boost -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Boost
boost ] ]

  toJSON (QueryMoreLikeThisQuery MoreLikeThisQuery
query) =
    [Pair] -> Value
object [ Key
"more_like_this" Key -> MoreLikeThisQuery -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= MoreLikeThisQuery
query ]

  toJSON (QueryMoreLikeThisFieldQuery MoreLikeThisFieldQuery
query) =
    [Pair] -> Value
object [ Key
"more_like_this_field" Key -> MoreLikeThisFieldQuery -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= MoreLikeThisFieldQuery
query ]

  toJSON (QueryNestedQuery NestedQuery
query) =
    [Pair] -> Value
object [ Key
"nested" Key -> NestedQuery -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= NestedQuery
query ]

  toJSON (QueryPrefixQuery PrefixQuery
query) =
    [Pair] -> Value
object [ Key
"prefix" Key -> PrefixQuery -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= PrefixQuery
query ]

  toJSON (QueryRangeQuery RangeQuery
query) =
    [Pair] -> Value
object [ Key
"range"  Key -> RangeQuery -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= RangeQuery
query ]

  toJSON (QueryRegexpQuery RegexpQuery
query) =
    [Pair] -> Value
object [ Key
"regexp" Key -> RegexpQuery -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= RegexpQuery
query ]

  toJSON (QuerySimpleQueryStringQuery SimpleQueryStringQuery
query) =
    [Pair] -> Value
object [ Key
"simple_query_string" Key -> SimpleQueryStringQuery -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= SimpleQueryStringQuery
query ]

  toJSON (QueryExistsQuery (FieldName Text
fieldName)) =
    [Pair] -> Value
object [Key
"exists"  Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Pair] -> Value
object
             [Key
"field"  Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
fieldName]
           ]
  toJSON Query
QueryMatchNoneQuery =
    [Pair] -> Value
object [Key
"match_none" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Pair] -> Value
object []]

  toJSON (QueryWildcardQuery WildcardQuery
query) =
    [Pair] -> Value
object [ Key
"wildcard" Key -> WildcardQuery -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= WildcardQuery
query ]

instance FromJSON Query where
  parseJSON :: Value -> Parser Query
parseJSON Value
v = String -> (Object -> Parser Query) -> Value -> Parser Query
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Query" Object -> Parser Query
parse Value
v
    where parse :: Object -> Parser Query
parse Object
o = Object -> Parser Query
termQuery (Object -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"term"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> HashMap Key Value -> Parser Query
termsQuery (HashMap Key Value -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"terms"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Object -> Parser Query
idsQuery (Object -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"ids"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> QueryStringQuery -> Parser Query
queryQueryStringQuery (QueryStringQuery -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"query_string"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> MatchQuery -> Parser Query
queryMatchQuery (MatchQuery -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"match"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser Query
queryMultiMatchQuery
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> BoolQuery -> Parser Query
queryBoolQuery (BoolQuery -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"bool"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> BoostingQuery -> Parser Query
queryBoostingQuery (BoostingQuery -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"boosting"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> CommonTermsQuery -> Parser Query
queryCommonTermsQuery (CommonTermsQuery -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"common"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Object -> Parser Query
constantScoreQuery (Object -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"constant_score"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FunctionScoreQuery -> Parser Query
queryFunctionScoreQuery (FunctionScoreQuery -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"function_score"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> DisMaxQuery -> Parser Query
queryDisMaxQuery (DisMaxQuery -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"dis_max"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FuzzyLikeThisQuery -> Parser Query
queryFuzzyLikeThisQuery (FuzzyLikeThisQuery -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"fuzzy_like_this"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FuzzyLikeFieldQuery -> Parser Query
queryFuzzyLikeFieldQuery (FuzzyLikeFieldQuery -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"fuzzy_like_this_field"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FuzzyQuery -> Parser Query
queryFuzzyQuery (FuzzyQuery -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"fuzzy"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> HasChildQuery -> Parser Query
queryHasChildQuery (HasChildQuery -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"has_child"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> HasParentQuery -> Parser Query
queryHasParentQuery (HasParentQuery -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"has_parent"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> IndicesQuery -> Parser Query
queryIndicesQuery (IndicesQuery -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"indices"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Object -> Parser Query
matchAllQuery (Object -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"match_all"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> MoreLikeThisQuery -> Parser Query
queryMoreLikeThisQuery (MoreLikeThisQuery -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"more_like_this"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> MoreLikeThisFieldQuery -> Parser Query
queryMoreLikeThisFieldQuery (MoreLikeThisFieldQuery -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"more_like_this_field"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> NestedQuery -> Parser Query
queryNestedQuery (NestedQuery -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"nested"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> PrefixQuery -> Parser Query
queryPrefixQuery (PrefixQuery -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"prefix"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> RangeQuery -> Parser Query
queryRangeQuery (RangeQuery -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"range"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> RegexpQuery -> Parser Query
queryRegexpQuery (RegexpQuery -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"regexp"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> SimpleQueryStringQuery -> Parser Query
querySimpleQueryStringQuery (SimpleQueryStringQuery -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"simple_query_string"
                Parser Query -> Parser Query -> Parser Query
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> WildcardQuery -> Parser Query
queryWildcardQuery (WildcardQuery -> Parser Query) -> Key -> Parser Query
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"wildcard"
            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
          termQuery :: Object -> Parser Query
termQuery = (FieldName -> Object -> Parser Query) -> Object -> Parser Query
forall (m :: * -> *) a.
(Monad m, MonadFail m) =>
(FieldName -> Object -> m a) -> Object -> m a
fieldTagged ((FieldName -> Object -> Parser Query) -> Object -> Parser Query)
-> (FieldName -> Object -> Parser Query) -> Object -> Parser Query
forall a b. (a -> b) -> a -> b
$ \(FieldName Text
fn) Object
o ->
                        Term -> Maybe Boost -> Query
TermQuery (Term -> Maybe Boost -> Query)
-> Parser Term -> Parser (Maybe Boost -> Query)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Key -> Text -> Term
Term (Text -> Key
fromText Text
fn) (Text -> Term) -> Parser Text -> Parser Term
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
"value") Parser (Maybe Boost -> Query)
-> Parser (Maybe Boost) -> Parser Query
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"
          termsQuery :: HashMap Key Value -> Parser Query
termsQuery HashMap Key Value
o = case HashMap Key Value -> [Pair]
forall k v. HashMap k v -> [(k, v)]
HM.toList HashMap Key Value
o of
                           [(Key
fn, Value
vs)] -> do [Text]
vals <- Value -> Parser [Text]
forall a. FromJSON a => Value -> Parser a
parseJSON Value
vs
                                            case [Text]
vals of
                                              Text
x:[Text]
xs -> Query -> Parser Query
forall (m :: * -> *) a. Monad m => a -> m a
return (Key -> NonEmpty Text -> Query
TermsQuery Key
fn (Text
x Text -> [Text] -> NonEmpty Text
forall a. a -> [a] -> NonEmpty a
:| [Text]
xs))
                                              [Text]
_ -> String -> Parser Query
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Expected non empty list of values"
                           [Pair]
_ -> String -> Parser Query
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Expected object with 1 field-named key"
          idsQuery :: Object -> Parser Query
idsQuery Object
o = [DocId] -> Query
IdsQuery ([DocId] -> Query) -> Parser [DocId] -> Parser Query
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser [DocId]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"values"
          queryQueryStringQuery :: QueryStringQuery -> Parser Query
queryQueryStringQuery = Query -> Parser Query
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Query -> Parser Query)
-> (QueryStringQuery -> Query) -> QueryStringQuery -> Parser Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QueryStringQuery -> Query
QueryQueryStringQuery
          queryMatchQuery :: MatchQuery -> Parser Query
queryMatchQuery = Query -> Parser Query
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Query -> Parser Query)
-> (MatchQuery -> Query) -> MatchQuery -> Parser Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MatchQuery -> Query
QueryMatchQuery
          queryMultiMatchQuery :: Parser Query
queryMultiMatchQuery = MultiMatchQuery -> Query
QueryMultiMatchQuery (MultiMatchQuery -> Query)
-> Parser MultiMatchQuery -> Parser Query
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser MultiMatchQuery
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v
          queryBoolQuery :: BoolQuery -> Parser Query
queryBoolQuery = Query -> Parser Query
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Query -> Parser Query)
-> (BoolQuery -> Query) -> BoolQuery -> Parser Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BoolQuery -> Query
QueryBoolQuery
          queryBoostingQuery :: BoostingQuery -> Parser Query
queryBoostingQuery = Query -> Parser Query
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Query -> Parser Query)
-> (BoostingQuery -> Query) -> BoostingQuery -> Parser Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BoostingQuery -> Query
QueryBoostingQuery
          queryCommonTermsQuery :: CommonTermsQuery -> Parser Query
queryCommonTermsQuery = Query -> Parser Query
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Query -> Parser Query)
-> (CommonTermsQuery -> Query) -> CommonTermsQuery -> Parser Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CommonTermsQuery -> Query
QueryCommonTermsQuery
          constantScoreQuery :: Object -> Parser Query
constantScoreQuery Object
o = case Key -> Object -> Maybe Value
forall v. Key -> KeyMap v -> Maybe v
X.lookup Key
"filter" Object
o of
            Just Value
x -> Query -> Boost -> Query
ConstantScoreQuery (Query -> Boost -> Query)
-> Parser Query -> Parser (Boost -> Query)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser Query
forall a. FromJSON a => Value -> Parser a
parseJSON Value
x
                                         Parser (Boost -> Query) -> Parser Boost -> Parser Query
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Boost
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"boost"
            Maybe Value
_ -> String -> Parser Query
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Does not appear to be a ConstantScoreQuery"
          queryFunctionScoreQuery :: FunctionScoreQuery -> Parser Query
queryFunctionScoreQuery = Query -> Parser Query
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Query -> Parser Query)
-> (FunctionScoreQuery -> Query)
-> FunctionScoreQuery
-> Parser Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FunctionScoreQuery -> Query
QueryFunctionScoreQuery
          queryDisMaxQuery :: DisMaxQuery -> Parser Query
queryDisMaxQuery = Query -> Parser Query
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Query -> Parser Query)
-> (DisMaxQuery -> Query) -> DisMaxQuery -> Parser Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DisMaxQuery -> Query
QueryDisMaxQuery
          queryFuzzyLikeThisQuery :: FuzzyLikeThisQuery -> Parser Query
queryFuzzyLikeThisQuery = Query -> Parser Query
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Query -> Parser Query)
-> (FuzzyLikeThisQuery -> Query)
-> FuzzyLikeThisQuery
-> Parser Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FuzzyLikeThisQuery -> Query
QueryFuzzyLikeThisQuery
          queryFuzzyLikeFieldQuery :: FuzzyLikeFieldQuery -> Parser Query
queryFuzzyLikeFieldQuery = Query -> Parser Query
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Query -> Parser Query)
-> (FuzzyLikeFieldQuery -> Query)
-> FuzzyLikeFieldQuery
-> Parser Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FuzzyLikeFieldQuery -> Query
QueryFuzzyLikeFieldQuery
          queryFuzzyQuery :: FuzzyQuery -> Parser Query
queryFuzzyQuery = Query -> Parser Query
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Query -> Parser Query)
-> (FuzzyQuery -> Query) -> FuzzyQuery -> Parser Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FuzzyQuery -> Query
QueryFuzzyQuery
          queryHasChildQuery :: HasChildQuery -> Parser Query
queryHasChildQuery = Query -> Parser Query
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Query -> Parser Query)
-> (HasChildQuery -> Query) -> HasChildQuery -> Parser Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasChildQuery -> Query
QueryHasChildQuery
          queryHasParentQuery :: HasParentQuery -> Parser Query
queryHasParentQuery = Query -> Parser Query
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Query -> Parser Query)
-> (HasParentQuery -> Query) -> HasParentQuery -> Parser Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasParentQuery -> Query
QueryHasParentQuery
          queryIndicesQuery :: IndicesQuery -> Parser Query
queryIndicesQuery = Query -> Parser Query
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Query -> Parser Query)
-> (IndicesQuery -> Query) -> IndicesQuery -> Parser Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IndicesQuery -> Query
QueryIndicesQuery
          matchAllQuery :: Object -> Parser Query
matchAllQuery Object
o = Maybe Boost -> Query
MatchAllQuery (Maybe Boost -> Query) -> Parser (Maybe Boost) -> Parser Query
forall (f :: * -> *) a b. Functor 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"
          queryMoreLikeThisQuery :: MoreLikeThisQuery -> Parser Query
queryMoreLikeThisQuery = Query -> Parser Query
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Query -> Parser Query)
-> (MoreLikeThisQuery -> Query)
-> MoreLikeThisQuery
-> Parser Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MoreLikeThisQuery -> Query
QueryMoreLikeThisQuery
          queryMoreLikeThisFieldQuery :: MoreLikeThisFieldQuery -> Parser Query
queryMoreLikeThisFieldQuery = Query -> Parser Query
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Query -> Parser Query)
-> (MoreLikeThisFieldQuery -> Query)
-> MoreLikeThisFieldQuery
-> Parser Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MoreLikeThisFieldQuery -> Query
QueryMoreLikeThisFieldQuery
          queryNestedQuery :: NestedQuery -> Parser Query
queryNestedQuery = Query -> Parser Query
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Query -> Parser Query)
-> (NestedQuery -> Query) -> NestedQuery -> Parser Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NestedQuery -> Query
QueryNestedQuery
          queryPrefixQuery :: PrefixQuery -> Parser Query
queryPrefixQuery = Query -> Parser Query
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Query -> Parser Query)
-> (PrefixQuery -> Query) -> PrefixQuery -> Parser Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PrefixQuery -> Query
QueryPrefixQuery
          queryRangeQuery :: RangeQuery -> Parser Query
queryRangeQuery = Query -> Parser Query
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Query -> Parser Query)
-> (RangeQuery -> Query) -> RangeQuery -> Parser Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RangeQuery -> Query
QueryRangeQuery
          queryRegexpQuery :: RegexpQuery -> Parser Query
queryRegexpQuery = Query -> Parser Query
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Query -> Parser Query)
-> (RegexpQuery -> Query) -> RegexpQuery -> Parser Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RegexpQuery -> Query
QueryRegexpQuery
          querySimpleQueryStringQuery :: SimpleQueryStringQuery -> Parser Query
querySimpleQueryStringQuery = Query -> Parser Query
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Query -> Parser Query)
-> (SimpleQueryStringQuery -> Query)
-> SimpleQueryStringQuery
-> Parser Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimpleQueryStringQuery -> Query
QuerySimpleQueryStringQuery
          -- queryExistsQuery o = QueryExistsQuery <$> o .: "field"
          queryWildcardQuery :: WildcardQuery -> Parser Query
queryWildcardQuery = Query -> Parser Query
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Query -> Parser Query)
-> (WildcardQuery -> Query) -> WildcardQuery -> Parser Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WildcardQuery -> Query
QueryWildcardQuery

-- | As of Elastic 2.0, 'Filters' are just 'Queries' housed in a
--   Bool Query, and flagged in a different context.
newtype Filter = Filter { Filter -> Query
unFilter :: Query }
  deriving (Filter -> Filter -> Bool
(Filter -> Filter -> Bool)
-> (Filter -> Filter -> Bool) -> Eq Filter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Filter -> Filter -> Bool
$c/= :: Filter -> Filter -> Bool
== :: Filter -> Filter -> Bool
$c== :: Filter -> Filter -> Bool
Eq, Int -> Filter -> ShowS
[Filter] -> ShowS
Filter -> String
(Int -> Filter -> ShowS)
-> (Filter -> String) -> ([Filter] -> ShowS) -> Show Filter
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Filter] -> ShowS
$cshowList :: [Filter] -> ShowS
show :: Filter -> String
$cshow :: Filter -> String
showsPrec :: Int -> Filter -> ShowS
$cshowsPrec :: Int -> Filter -> ShowS
Show)

instance ToJSON Filter where
  toJSON :: Filter -> Value
toJSON = Query -> Value
forall a. ToJSON a => a -> Value
toJSON (Query -> Value) -> (Filter -> Query) -> Filter -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Filter -> Query
unFilter

instance FromJSON Filter where
  parseJSON :: Value -> Parser Filter
parseJSON Value
v = Query -> Filter
Filter (Query -> Filter) -> Parser Query -> Parser Filter
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser Query
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v

data RegexpQuery =
  RegexpQuery { RegexpQuery -> FieldName
regexpQueryField :: FieldName
              , RegexpQuery -> Regexp
regexpQuery      :: Regexp
              , RegexpQuery -> RegexpFlags
regexpQueryFlags :: RegexpFlags
              , RegexpQuery -> Maybe Boost
regexpQueryBoost :: Maybe Boost
              } deriving (RegexpQuery -> RegexpQuery -> Bool
(RegexpQuery -> RegexpQuery -> Bool)
-> (RegexpQuery -> RegexpQuery -> Bool) -> Eq RegexpQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegexpQuery -> RegexpQuery -> Bool
$c/= :: RegexpQuery -> RegexpQuery -> Bool
== :: RegexpQuery -> RegexpQuery -> Bool
$c== :: RegexpQuery -> RegexpQuery -> Bool
Eq, Int -> RegexpQuery -> ShowS
[RegexpQuery] -> ShowS
RegexpQuery -> String
(Int -> RegexpQuery -> ShowS)
-> (RegexpQuery -> String)
-> ([RegexpQuery] -> ShowS)
-> Show RegexpQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegexpQuery] -> ShowS
$cshowList :: [RegexpQuery] -> ShowS
show :: RegexpQuery -> String
$cshow :: RegexpQuery -> String
showsPrec :: Int -> RegexpQuery -> ShowS
$cshowsPrec :: Int -> RegexpQuery -> ShowS
Show)

instance ToJSON RegexpQuery where
  toJSON :: RegexpQuery -> Value
toJSON (RegexpQuery (FieldName Text
rqQueryField)
          (Regexp Text
regexpQueryQuery) RegexpFlags
rqQueryFlags
          Maybe Boost
rqQueryBoost) =
   [Pair] -> Value
object [ Text -> Key
fromText Text
rqQueryField Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Pair] -> Value
omitNulls [Pair]
base ]
   where base :: [Pair]
base = [ Key
"value" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
regexpQueryQuery
                , Key
"flags" Key -> RegexpFlags -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= RegexpFlags
rqQueryFlags
                , Key
"boost" Key -> Maybe Boost -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Boost
rqQueryBoost ]

instance FromJSON RegexpQuery where
  parseJSON :: Value -> Parser RegexpQuery
parseJSON = String
-> (Object -> Parser RegexpQuery) -> Value -> Parser RegexpQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"RegexpQuery" Object -> Parser RegexpQuery
parse
    where parse :: Object -> Parser RegexpQuery
parse = (FieldName -> Object -> Parser RegexpQuery)
-> Object -> Parser RegexpQuery
forall (m :: * -> *) a.
(Monad m, MonadFail m) =>
(FieldName -> Object -> m a) -> Object -> m a
fieldTagged ((FieldName -> Object -> Parser RegexpQuery)
 -> Object -> Parser RegexpQuery)
-> (FieldName -> Object -> Parser RegexpQuery)
-> Object
-> Parser RegexpQuery
forall a b. (a -> b) -> a -> b
$ \FieldName
fn Object
o ->
                    FieldName -> Regexp -> RegexpFlags -> Maybe Boost -> RegexpQuery
RegexpQuery FieldName
fn
                    (Regexp -> RegexpFlags -> Maybe Boost -> RegexpQuery)
-> Parser Regexp
-> Parser (RegexpFlags -> Maybe Boost -> RegexpQuery)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Regexp
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"value"
                    Parser (RegexpFlags -> Maybe Boost -> RegexpQuery)
-> Parser RegexpFlags -> Parser (Maybe Boost -> RegexpQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser RegexpFlags
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"flags"
                    Parser (Maybe Boost -> RegexpQuery)
-> Parser (Maybe Boost) -> Parser RegexpQuery
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"

data WildcardQuery =
  WildcardQuery { WildcardQuery -> FieldName
wildcardQueryField :: FieldName
                , WildcardQuery -> Key
wildcardQuery      :: Key
                , WildcardQuery -> Maybe Boost
wildcardQueryBoost :: Maybe Boost
              } deriving (WildcardQuery -> WildcardQuery -> Bool
(WildcardQuery -> WildcardQuery -> Bool)
-> (WildcardQuery -> WildcardQuery -> Bool) -> Eq WildcardQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: WildcardQuery -> WildcardQuery -> Bool
$c/= :: WildcardQuery -> WildcardQuery -> Bool
== :: WildcardQuery -> WildcardQuery -> Bool
$c== :: WildcardQuery -> WildcardQuery -> Bool
Eq, Int -> WildcardQuery -> ShowS
[WildcardQuery] -> ShowS
WildcardQuery -> String
(Int -> WildcardQuery -> ShowS)
-> (WildcardQuery -> String)
-> ([WildcardQuery] -> ShowS)
-> Show WildcardQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WildcardQuery] -> ShowS
$cshowList :: [WildcardQuery] -> ShowS
show :: WildcardQuery -> String
$cshow :: WildcardQuery -> String
showsPrec :: Int -> WildcardQuery -> ShowS
$cshowsPrec :: Int -> WildcardQuery -> ShowS
Show)

instance ToJSON WildcardQuery where
  toJSON :: WildcardQuery -> Value
toJSON (WildcardQuery (FieldName Text
wcQueryField)
         (Key
wcQueryQuery) Maybe Boost
wcQueryBoost) =
   [Pair] -> Value
object [ Text -> Key
fromText Text
wcQueryField Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Pair] -> Value
omitNulls [Pair]
base ]
   where base :: [Pair]
base = [ Key
"value" Key -> Key -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Key
wcQueryQuery
                , Key
"boost" Key -> Maybe Boost -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Boost
wcQueryBoost ]

instance FromJSON WildcardQuery where
  parseJSON :: Value -> Parser WildcardQuery
parseJSON = String
-> (Object -> Parser WildcardQuery)
-> Value
-> Parser WildcardQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"WildcardQuery" Object -> Parser WildcardQuery
parse
    where parse :: Object -> Parser WildcardQuery
parse = (FieldName -> Object -> Parser WildcardQuery)
-> Object -> Parser WildcardQuery
forall (m :: * -> *) a.
(Monad m, MonadFail m) =>
(FieldName -> Object -> m a) -> Object -> m a
fieldTagged ((FieldName -> Object -> Parser WildcardQuery)
 -> Object -> Parser WildcardQuery)
-> (FieldName -> Object -> Parser WildcardQuery)
-> Object
-> Parser WildcardQuery
forall a b. (a -> b) -> a -> b
$ \FieldName
fn Object
o ->
                    FieldName -> Key -> Maybe Boost -> WildcardQuery
WildcardQuery FieldName
fn
                    (Key -> Maybe Boost -> WildcardQuery)
-> Parser Key -> Parser (Maybe Boost -> WildcardQuery)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Key
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"value"
                    Parser (Maybe Boost -> WildcardQuery)
-> Parser (Maybe Boost) -> Parser WildcardQuery
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"

data RangeQuery =
  RangeQuery { RangeQuery -> FieldName
rangeQueryField :: FieldName
             , RangeQuery -> RangeValue
rangeQueryRange :: RangeValue
             , RangeQuery -> Boost
rangeQueryBoost :: Boost } deriving (RangeQuery -> RangeQuery -> Bool
(RangeQuery -> RangeQuery -> Bool)
-> (RangeQuery -> RangeQuery -> Bool) -> Eq RangeQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RangeQuery -> RangeQuery -> Bool
$c/= :: RangeQuery -> RangeQuery -> Bool
== :: RangeQuery -> RangeQuery -> Bool
$c== :: RangeQuery -> RangeQuery -> Bool
Eq, Int -> RangeQuery -> ShowS
[RangeQuery] -> ShowS
RangeQuery -> String
(Int -> RangeQuery -> ShowS)
-> (RangeQuery -> String)
-> ([RangeQuery] -> ShowS)
-> Show RangeQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RangeQuery] -> ShowS
$cshowList :: [RangeQuery] -> ShowS
show :: RangeQuery -> String
$cshow :: RangeQuery -> String
showsPrec :: Int -> RangeQuery -> ShowS
$cshowsPrec :: Int -> RangeQuery -> ShowS
Show)

instance ToJSON RangeQuery where
  toJSON :: RangeQuery -> Value
toJSON (RangeQuery (FieldName Text
fieldName) RangeValue
range Boost
boost) =
    [Pair] -> Value
object [ Text -> Key
fromText Text
fieldName Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Pair] -> Value
object [Pair]
conjoined ]
    where
      conjoined :: [Pair]
conjoined = (Key
"boost" Key -> Boost -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Boost
boost) Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: RangeValue -> [Pair]
rangeValueToPair RangeValue
range

instance FromJSON RangeQuery where
  parseJSON :: Value -> Parser RangeQuery
parseJSON = String
-> (Object -> Parser RangeQuery) -> Value -> Parser RangeQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"RangeQuery" Object -> Parser RangeQuery
parse
    where parse :: Object -> Parser RangeQuery
parse = (FieldName -> Object -> Parser RangeQuery)
-> Object -> Parser RangeQuery
forall (m :: * -> *) a.
(Monad m, MonadFail m) =>
(FieldName -> Object -> m a) -> Object -> m a
fieldTagged ((FieldName -> Object -> Parser RangeQuery)
 -> Object -> Parser RangeQuery)
-> (FieldName -> Object -> Parser RangeQuery)
-> Object
-> Parser RangeQuery
forall a b. (a -> b) -> a -> b
$ \FieldName
fn Object
o ->
                    FieldName -> RangeValue -> Boost -> RangeQuery
RangeQuery FieldName
fn
                    (RangeValue -> Boost -> RangeQuery)
-> Parser RangeValue -> Parser (Boost -> RangeQuery)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser RangeValue
forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
o)
                    Parser (Boost -> RangeQuery) -> Parser Boost -> Parser RangeQuery
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Boost
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"boost"

mkRangeQuery :: FieldName -> RangeValue -> RangeQuery
mkRangeQuery :: FieldName -> RangeValue -> RangeQuery
mkRangeQuery FieldName
f RangeValue
r = FieldName -> RangeValue -> Boost -> RangeQuery
RangeQuery FieldName
f RangeValue
r (Double -> Boost
Boost Double
1.0)

data SimpleQueryStringQuery =
  SimpleQueryStringQuery
    { SimpleQueryStringQuery -> QueryString
simpleQueryStringQuery             :: QueryString
    , SimpleQueryStringQuery -> Maybe FieldOrFields
simpleQueryStringField             :: Maybe FieldOrFields
    , SimpleQueryStringQuery -> Maybe BooleanOperator
simpleQueryStringOperator          :: Maybe BooleanOperator
    , SimpleQueryStringQuery -> Maybe Analyzer
simpleQueryStringAnalyzer          :: Maybe Analyzer
    , SimpleQueryStringQuery -> Maybe (NonEmpty SimpleQueryFlag)
simpleQueryStringFlags             :: Maybe (NonEmpty SimpleQueryFlag)
    , SimpleQueryStringQuery -> Maybe LowercaseExpanded
simpleQueryStringLowercaseExpanded :: Maybe LowercaseExpanded
    , SimpleQueryStringQuery -> Maybe Locale
simpleQueryStringLocale            :: Maybe Locale
    } deriving (SimpleQueryStringQuery -> SimpleQueryStringQuery -> Bool
(SimpleQueryStringQuery -> SimpleQueryStringQuery -> Bool)
-> (SimpleQueryStringQuery -> SimpleQueryStringQuery -> Bool)
-> Eq SimpleQueryStringQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SimpleQueryStringQuery -> SimpleQueryStringQuery -> Bool
$c/= :: SimpleQueryStringQuery -> SimpleQueryStringQuery -> Bool
== :: SimpleQueryStringQuery -> SimpleQueryStringQuery -> Bool
$c== :: SimpleQueryStringQuery -> SimpleQueryStringQuery -> Bool
Eq, Int -> SimpleQueryStringQuery -> ShowS
[SimpleQueryStringQuery] -> ShowS
SimpleQueryStringQuery -> String
(Int -> SimpleQueryStringQuery -> ShowS)
-> (SimpleQueryStringQuery -> String)
-> ([SimpleQueryStringQuery] -> ShowS)
-> Show SimpleQueryStringQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SimpleQueryStringQuery] -> ShowS
$cshowList :: [SimpleQueryStringQuery] -> ShowS
show :: SimpleQueryStringQuery -> String
$cshow :: SimpleQueryStringQuery -> String
showsPrec :: Int -> SimpleQueryStringQuery -> ShowS
$cshowsPrec :: Int -> SimpleQueryStringQuery -> ShowS
Show)


instance ToJSON SimpleQueryStringQuery where
  toJSON :: SimpleQueryStringQuery -> Value
toJSON SimpleQueryStringQuery {Maybe (NonEmpty SimpleQueryFlag)
Maybe Locale
Maybe LowercaseExpanded
Maybe Analyzer
Maybe BooleanOperator
Maybe FieldOrFields
QueryString
simpleQueryStringLocale :: Maybe Locale
simpleQueryStringLowercaseExpanded :: Maybe LowercaseExpanded
simpleQueryStringFlags :: Maybe (NonEmpty SimpleQueryFlag)
simpleQueryStringAnalyzer :: Maybe Analyzer
simpleQueryStringOperator :: Maybe BooleanOperator
simpleQueryStringField :: Maybe FieldOrFields
simpleQueryStringQuery :: QueryString
simpleQueryStringLocale :: SimpleQueryStringQuery -> Maybe Locale
simpleQueryStringLowercaseExpanded :: SimpleQueryStringQuery -> Maybe LowercaseExpanded
simpleQueryStringFlags :: SimpleQueryStringQuery -> Maybe (NonEmpty SimpleQueryFlag)
simpleQueryStringAnalyzer :: SimpleQueryStringQuery -> Maybe Analyzer
simpleQueryStringOperator :: SimpleQueryStringQuery -> Maybe BooleanOperator
simpleQueryStringField :: SimpleQueryStringQuery -> Maybe FieldOrFields
simpleQueryStringQuery :: SimpleQueryStringQuery -> QueryString
..} =
    [Pair] -> Value
omitNulls ([Pair]
base [Pair] -> [Pair] -> [Pair]
forall a. [a] -> [a] -> [a]
++ [Pair]
maybeAdd)
    where base :: [Pair]
base = [ Key
"query" Key -> QueryString -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= QueryString
simpleQueryStringQuery ]
          maybeAdd :: [Pair]
maybeAdd = [ Key
"fields" Key -> Maybe FieldOrFields -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe FieldOrFields
simpleQueryStringField
                     , Key
"default_operator" Key -> Maybe BooleanOperator -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe BooleanOperator
simpleQueryStringOperator
                     , Key
"analyzer" Key -> Maybe Analyzer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Analyzer
simpleQueryStringAnalyzer
                     , Key
"flags" Key -> Maybe (NonEmpty SimpleQueryFlag) -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe (NonEmpty SimpleQueryFlag)
simpleQueryStringFlags
                     , Key
"lowercase_expanded_terms" Key -> Maybe LowercaseExpanded -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe LowercaseExpanded
simpleQueryStringLowercaseExpanded
                     , Key
"locale" Key -> Maybe Locale -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Locale
simpleQueryStringLocale ]

instance FromJSON SimpleQueryStringQuery where
  parseJSON :: Value -> Parser SimpleQueryStringQuery
parseJSON = String
-> (Object -> Parser SimpleQueryStringQuery)
-> Value
-> Parser SimpleQueryStringQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"SimpleQueryStringQuery" Object -> Parser SimpleQueryStringQuery
parse
    where parse :: Object -> Parser SimpleQueryStringQuery
parse Object
o = QueryString
-> Maybe FieldOrFields
-> Maybe BooleanOperator
-> Maybe Analyzer
-> Maybe (NonEmpty SimpleQueryFlag)
-> Maybe LowercaseExpanded
-> Maybe Locale
-> SimpleQueryStringQuery
SimpleQueryStringQuery (QueryString
 -> Maybe FieldOrFields
 -> Maybe BooleanOperator
 -> Maybe Analyzer
 -> Maybe (NonEmpty SimpleQueryFlag)
 -> Maybe LowercaseExpanded
 -> Maybe Locale
 -> SimpleQueryStringQuery)
-> Parser QueryString
-> Parser
     (Maybe FieldOrFields
      -> Maybe BooleanOperator
      -> Maybe Analyzer
      -> Maybe (NonEmpty SimpleQueryFlag)
      -> Maybe LowercaseExpanded
      -> Maybe Locale
      -> SimpleQueryStringQuery)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser QueryString
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"query"
                                           Parser
  (Maybe FieldOrFields
   -> Maybe BooleanOperator
   -> Maybe Analyzer
   -> Maybe (NonEmpty SimpleQueryFlag)
   -> Maybe LowercaseExpanded
   -> Maybe Locale
   -> SimpleQueryStringQuery)
-> Parser (Maybe FieldOrFields)
-> Parser
     (Maybe BooleanOperator
      -> Maybe Analyzer
      -> Maybe (NonEmpty SimpleQueryFlag)
      -> Maybe LowercaseExpanded
      -> Maybe Locale
      -> SimpleQueryStringQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe FieldOrFields)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"fields"
                                           Parser
  (Maybe BooleanOperator
   -> Maybe Analyzer
   -> Maybe (NonEmpty SimpleQueryFlag)
   -> Maybe LowercaseExpanded
   -> Maybe Locale
   -> SimpleQueryStringQuery)
-> Parser (Maybe BooleanOperator)
-> Parser
     (Maybe Analyzer
      -> Maybe (NonEmpty SimpleQueryFlag)
      -> Maybe LowercaseExpanded
      -> Maybe Locale
      -> SimpleQueryStringQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe BooleanOperator)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"default_operator"
                                           Parser
  (Maybe Analyzer
   -> Maybe (NonEmpty SimpleQueryFlag)
   -> Maybe LowercaseExpanded
   -> Maybe Locale
   -> SimpleQueryStringQuery)
-> Parser (Maybe Analyzer)
-> Parser
     (Maybe (NonEmpty SimpleQueryFlag)
      -> Maybe LowercaseExpanded
      -> Maybe Locale
      -> SimpleQueryStringQuery)
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 (NonEmpty SimpleQueryFlag)
   -> Maybe LowercaseExpanded
   -> Maybe Locale
   -> SimpleQueryStringQuery)
-> Parser (Maybe (NonEmpty SimpleQueryFlag))
-> Parser
     (Maybe LowercaseExpanded -> Maybe Locale -> SimpleQueryStringQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Maybe [SimpleQueryFlag] -> Maybe (NonEmpty SimpleQueryFlag)
forall a. Maybe [a] -> Maybe (NonEmpty a)
parseFlags (Maybe [SimpleQueryFlag] -> Maybe (NonEmpty SimpleQueryFlag))
-> Parser (Maybe [SimpleQueryFlag])
-> Parser (Maybe (NonEmpty SimpleQueryFlag))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe [SimpleQueryFlag])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"flags")
                                           Parser
  (Maybe LowercaseExpanded -> Maybe Locale -> SimpleQueryStringQuery)
-> Parser (Maybe LowercaseExpanded)
-> Parser (Maybe Locale -> SimpleQueryStringQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe LowercaseExpanded)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"lowercase_expanded_terms"
                                           Parser (Maybe Locale -> SimpleQueryStringQuery)
-> Parser (Maybe Locale) -> Parser SimpleQueryStringQuery
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Locale)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"locale"
          parseFlags :: Maybe [a] -> Maybe (NonEmpty a)
parseFlags (Just (a
x:[a]
xs)) = NonEmpty a -> Maybe (NonEmpty a)
forall a. a -> Maybe a
Just (a
x a -> [a] -> NonEmpty a
forall a. a -> [a] -> NonEmpty a
:| [a]
xs)
          parseFlags Maybe [a]
_             = Maybe (NonEmpty a)
forall a. Maybe a
Nothing

data SimpleQueryFlag =
    SimpleQueryAll
  | SimpleQueryNone
  | SimpleQueryAnd
  | SimpleQueryOr
  | SimpleQueryPrefix
  | SimpleQueryPhrase
  | SimpleQueryPrecedence
  | SimpleQueryEscape
  | SimpleQueryWhitespace
  | SimpleQueryFuzzy
  | SimpleQueryNear
  | SimpleQuerySlop deriving (SimpleQueryFlag -> SimpleQueryFlag -> Bool
(SimpleQueryFlag -> SimpleQueryFlag -> Bool)
-> (SimpleQueryFlag -> SimpleQueryFlag -> Bool)
-> Eq SimpleQueryFlag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SimpleQueryFlag -> SimpleQueryFlag -> Bool
$c/= :: SimpleQueryFlag -> SimpleQueryFlag -> Bool
== :: SimpleQueryFlag -> SimpleQueryFlag -> Bool
$c== :: SimpleQueryFlag -> SimpleQueryFlag -> Bool
Eq, Int -> SimpleQueryFlag -> ShowS
[SimpleQueryFlag] -> ShowS
SimpleQueryFlag -> String
(Int -> SimpleQueryFlag -> ShowS)
-> (SimpleQueryFlag -> String)
-> ([SimpleQueryFlag] -> ShowS)
-> Show SimpleQueryFlag
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SimpleQueryFlag] -> ShowS
$cshowList :: [SimpleQueryFlag] -> ShowS
show :: SimpleQueryFlag -> String
$cshow :: SimpleQueryFlag -> String
showsPrec :: Int -> SimpleQueryFlag -> ShowS
$cshowsPrec :: Int -> SimpleQueryFlag -> ShowS
Show)

instance ToJSON SimpleQueryFlag where
  toJSON :: SimpleQueryFlag -> Value
toJSON SimpleQueryFlag
SimpleQueryAll        = Value
"ALL"
  toJSON SimpleQueryFlag
SimpleQueryNone       = Value
"NONE"
  toJSON SimpleQueryFlag
SimpleQueryAnd        = Value
"AND"
  toJSON SimpleQueryFlag
SimpleQueryOr         = Value
"OR"
  toJSON SimpleQueryFlag
SimpleQueryPrefix     = Value
"PREFIX"
  toJSON SimpleQueryFlag
SimpleQueryPhrase     = Value
"PHRASE"
  toJSON SimpleQueryFlag
SimpleQueryPrecedence = Value
"PRECEDENCE"
  toJSON SimpleQueryFlag
SimpleQueryEscape     = Value
"ESCAPE"
  toJSON SimpleQueryFlag
SimpleQueryWhitespace = Value
"WHITESPACE"
  toJSON SimpleQueryFlag
SimpleQueryFuzzy      = Value
"FUZZY"
  toJSON SimpleQueryFlag
SimpleQueryNear       = Value
"NEAR"
  toJSON SimpleQueryFlag
SimpleQuerySlop       = Value
"SLOP"

instance FromJSON SimpleQueryFlag where
  parseJSON :: Value -> Parser SimpleQueryFlag
parseJSON = String
-> (Text -> Parser SimpleQueryFlag)
-> Value
-> Parser SimpleQueryFlag
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"SimpleQueryFlag" Text -> Parser SimpleQueryFlag
forall a (f :: * -> *).
(Eq a, IsString a, MonadFail f, Show a) =>
a -> f SimpleQueryFlag
parse
    where parse :: a -> f SimpleQueryFlag
parse a
"ALL"        = SimpleQueryFlag -> f SimpleQueryFlag
forall (f :: * -> *) a. Applicative f => a -> f a
pure SimpleQueryFlag
SimpleQueryAll
          parse a
"NONE"       = SimpleQueryFlag -> f SimpleQueryFlag
forall (f :: * -> *) a. Applicative f => a -> f a
pure SimpleQueryFlag
SimpleQueryNone
          parse a
"AND"        = SimpleQueryFlag -> f SimpleQueryFlag
forall (f :: * -> *) a. Applicative f => a -> f a
pure SimpleQueryFlag
SimpleQueryAnd
          parse a
"OR"         = SimpleQueryFlag -> f SimpleQueryFlag
forall (f :: * -> *) a. Applicative f => a -> f a
pure SimpleQueryFlag
SimpleQueryOr
          parse a
"PREFIX"     = SimpleQueryFlag -> f SimpleQueryFlag
forall (f :: * -> *) a. Applicative f => a -> f a
pure SimpleQueryFlag
SimpleQueryPrefix
          parse a
"PHRASE"     = SimpleQueryFlag -> f SimpleQueryFlag
forall (f :: * -> *) a. Applicative f => a -> f a
pure SimpleQueryFlag
SimpleQueryPhrase
          parse a
"PRECEDENCE" = SimpleQueryFlag -> f SimpleQueryFlag
forall (f :: * -> *) a. Applicative f => a -> f a
pure SimpleQueryFlag
SimpleQueryPrecedence
          parse a
"ESCAPE"     = SimpleQueryFlag -> f SimpleQueryFlag
forall (f :: * -> *) a. Applicative f => a -> f a
pure SimpleQueryFlag
SimpleQueryEscape
          parse a
"WHITESPACE" = SimpleQueryFlag -> f SimpleQueryFlag
forall (f :: * -> *) a. Applicative f => a -> f a
pure SimpleQueryFlag
SimpleQueryWhitespace
          parse a
"FUZZY"      = SimpleQueryFlag -> f SimpleQueryFlag
forall (f :: * -> *) a. Applicative f => a -> f a
pure SimpleQueryFlag
SimpleQueryFuzzy
          parse a
"NEAR"       = SimpleQueryFlag -> f SimpleQueryFlag
forall (f :: * -> *) a. Applicative f => a -> f a
pure SimpleQueryFlag
SimpleQueryNear
          parse a
"SLOP"       = SimpleQueryFlag -> f SimpleQueryFlag
forall (f :: * -> *) a. Applicative f => a -> f a
pure SimpleQueryFlag
SimpleQuerySlop
          parse a
f            = String -> f SimpleQueryFlag
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"Unexpected SimpleQueryFlag: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> a -> String
forall a. Show a => a -> String
show a
f)

-- use_dis_max and tie_breaker when fields are plural?
data QueryStringQuery =
  QueryStringQuery
  { QueryStringQuery -> QueryString
queryStringQuery                    :: QueryString
  , QueryStringQuery -> Maybe FieldName
queryStringDefaultField             :: Maybe FieldName
  , QueryStringQuery -> Maybe BooleanOperator
queryStringOperator                 :: Maybe BooleanOperator
  , QueryStringQuery -> Maybe Analyzer
queryStringAnalyzer                 :: Maybe Analyzer
  , QueryStringQuery -> Maybe AllowLeadingWildcard
queryStringAllowLeadingWildcard     :: Maybe AllowLeadingWildcard
  , QueryStringQuery -> Maybe LowercaseExpanded
queryStringLowercaseExpanded        :: Maybe LowercaseExpanded
  , QueryStringQuery -> Maybe EnablePositionIncrements
queryStringEnablePositionIncrements :: Maybe EnablePositionIncrements
  , QueryStringQuery -> Maybe MaxExpansions
queryStringFuzzyMaxExpansions       :: Maybe MaxExpansions
  , QueryStringQuery -> Maybe Fuzziness
queryStringFuzziness                :: Maybe Fuzziness
  , QueryStringQuery -> Maybe PrefixLength
queryStringFuzzyPrefixLength        :: Maybe PrefixLength
  , QueryStringQuery -> Maybe PhraseSlop
queryStringPhraseSlop               :: Maybe PhraseSlop
  , QueryStringQuery -> Maybe Boost
queryStringBoost                    :: Maybe Boost
  , QueryStringQuery -> Maybe AnalyzeWildcard
queryStringAnalyzeWildcard          :: Maybe AnalyzeWildcard
  , QueryStringQuery -> Maybe GeneratePhraseQueries
queryStringGeneratePhraseQueries    :: Maybe GeneratePhraseQueries
  , QueryStringQuery -> Maybe MinimumMatch
queryStringMinimumShouldMatch       :: Maybe MinimumMatch
  , QueryStringQuery -> Maybe Lenient
queryStringLenient                  :: Maybe Lenient
  , QueryStringQuery -> Maybe Locale
queryStringLocale                   :: Maybe Locale
  } deriving (QueryStringQuery -> QueryStringQuery -> Bool
(QueryStringQuery -> QueryStringQuery -> Bool)
-> (QueryStringQuery -> QueryStringQuery -> Bool)
-> Eq QueryStringQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: QueryStringQuery -> QueryStringQuery -> Bool
$c/= :: QueryStringQuery -> QueryStringQuery -> Bool
== :: QueryStringQuery -> QueryStringQuery -> Bool
$c== :: QueryStringQuery -> QueryStringQuery -> Bool
Eq, Int -> QueryStringQuery -> ShowS
[QueryStringQuery] -> ShowS
QueryStringQuery -> String
(Int -> QueryStringQuery -> ShowS)
-> (QueryStringQuery -> String)
-> ([QueryStringQuery] -> ShowS)
-> Show QueryStringQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [QueryStringQuery] -> ShowS
$cshowList :: [QueryStringQuery] -> ShowS
show :: QueryStringQuery -> String
$cshow :: QueryStringQuery -> String
showsPrec :: Int -> QueryStringQuery -> ShowS
$cshowsPrec :: Int -> QueryStringQuery -> ShowS
Show)


instance ToJSON QueryStringQuery where
  toJSON :: QueryStringQuery -> Value
toJSON (QueryStringQuery QueryString
qsQueryString
          Maybe FieldName
qsDefaultField Maybe BooleanOperator
qsOperator
          Maybe Analyzer
qsAnalyzer Maybe AllowLeadingWildcard
qsAllowWildcard
          Maybe LowercaseExpanded
qsLowercaseExpanded  Maybe EnablePositionIncrements
qsEnablePositionIncrements
          Maybe MaxExpansions
qsFuzzyMaxExpansions Maybe Fuzziness
qsFuzziness
          Maybe PrefixLength
qsFuzzyPrefixLength Maybe PhraseSlop
qsPhraseSlop
          Maybe Boost
qsBoost Maybe AnalyzeWildcard
qsAnalyzeWildcard
          Maybe GeneratePhraseQueries
qsGeneratePhraseQueries Maybe MinimumMatch
qsMinimumShouldMatch
          Maybe Lenient
qsLenient Maybe Locale
qsLocale) =
    [Pair] -> Value
omitNulls [Pair]
base
    where
      base :: [Pair]
base = [ Key
"query" Key -> QueryString -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= QueryString
qsQueryString
             , Key
"default_field" Key -> Maybe FieldName -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe FieldName
qsDefaultField
             , Key
"default_operator" Key -> Maybe BooleanOperator -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe BooleanOperator
qsOperator
             , Key
"analyzer" Key -> Maybe Analyzer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Analyzer
qsAnalyzer
             , Key
"allow_leading_wildcard" Key -> Maybe AllowLeadingWildcard -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe AllowLeadingWildcard
qsAllowWildcard
             , Key
"lowercase_expanded_terms" Key -> Maybe LowercaseExpanded -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe LowercaseExpanded
qsLowercaseExpanded
             , Key
"enable_position_increments" Key -> Maybe EnablePositionIncrements -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe EnablePositionIncrements
qsEnablePositionIncrements
             , Key
"fuzzy_max_expansions" Key -> Maybe MaxExpansions -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe MaxExpansions
qsFuzzyMaxExpansions
             , Key
"fuzziness" Key -> Maybe Fuzziness -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Fuzziness
qsFuzziness
             , Key
"fuzzy_prefix_length" Key -> Maybe PrefixLength -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe PrefixLength
qsFuzzyPrefixLength
             , Key
"phrase_slop" Key -> Maybe PhraseSlop -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe PhraseSlop
qsPhraseSlop
             , Key
"boost" Key -> Maybe Boost -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Boost
qsBoost
             , Key
"analyze_wildcard" Key -> Maybe AnalyzeWildcard -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe AnalyzeWildcard
qsAnalyzeWildcard
             , Key
"auto_generate_phrase_queries" Key -> Maybe GeneratePhraseQueries -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe GeneratePhraseQueries
qsGeneratePhraseQueries
             , Key
"minimum_should_match" Key -> Maybe MinimumMatch -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe MinimumMatch
qsMinimumShouldMatch
             , Key
"lenient" Key -> Maybe Lenient -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Lenient
qsLenient
             , Key
"locale" Key -> Maybe Locale -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Locale
qsLocale ]

instance FromJSON QueryStringQuery where
  parseJSON :: Value -> Parser QueryStringQuery
parseJSON = String
-> (Object -> Parser QueryStringQuery)
-> Value
-> Parser QueryStringQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"QueryStringQuery" Object -> Parser QueryStringQuery
parse
    where parse :: Object -> Parser QueryStringQuery
parse Object
o = QueryString
-> Maybe FieldName
-> Maybe BooleanOperator
-> Maybe Analyzer
-> Maybe AllowLeadingWildcard
-> Maybe LowercaseExpanded
-> Maybe EnablePositionIncrements
-> Maybe MaxExpansions
-> Maybe Fuzziness
-> Maybe PrefixLength
-> Maybe PhraseSlop
-> Maybe Boost
-> Maybe AnalyzeWildcard
-> Maybe GeneratePhraseQueries
-> Maybe MinimumMatch
-> Maybe Lenient
-> Maybe Locale
-> QueryStringQuery
QueryStringQuery
                    (QueryString
 -> Maybe FieldName
 -> Maybe BooleanOperator
 -> Maybe Analyzer
 -> Maybe AllowLeadingWildcard
 -> Maybe LowercaseExpanded
 -> Maybe EnablePositionIncrements
 -> Maybe MaxExpansions
 -> Maybe Fuzziness
 -> Maybe PrefixLength
 -> Maybe PhraseSlop
 -> Maybe Boost
 -> Maybe AnalyzeWildcard
 -> Maybe GeneratePhraseQueries
 -> Maybe MinimumMatch
 -> Maybe Lenient
 -> Maybe Locale
 -> QueryStringQuery)
-> Parser QueryString
-> Parser
     (Maybe FieldName
      -> Maybe BooleanOperator
      -> Maybe Analyzer
      -> Maybe AllowLeadingWildcard
      -> Maybe LowercaseExpanded
      -> Maybe EnablePositionIncrements
      -> Maybe MaxExpansions
      -> Maybe Fuzziness
      -> Maybe PrefixLength
      -> Maybe PhraseSlop
      -> Maybe Boost
      -> Maybe AnalyzeWildcard
      -> Maybe GeneratePhraseQueries
      -> Maybe MinimumMatch
      -> Maybe Lenient
      -> Maybe Locale
      -> QueryStringQuery)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser QueryString
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"query"
                    Parser
  (Maybe FieldName
   -> Maybe BooleanOperator
   -> Maybe Analyzer
   -> Maybe AllowLeadingWildcard
   -> Maybe LowercaseExpanded
   -> Maybe EnablePositionIncrements
   -> Maybe MaxExpansions
   -> Maybe Fuzziness
   -> Maybe PrefixLength
   -> Maybe PhraseSlop
   -> Maybe Boost
   -> Maybe AnalyzeWildcard
   -> Maybe GeneratePhraseQueries
   -> Maybe MinimumMatch
   -> Maybe Lenient
   -> Maybe Locale
   -> QueryStringQuery)
-> Parser (Maybe FieldName)
-> Parser
     (Maybe BooleanOperator
      -> Maybe Analyzer
      -> Maybe AllowLeadingWildcard
      -> Maybe LowercaseExpanded
      -> Maybe EnablePositionIncrements
      -> Maybe MaxExpansions
      -> Maybe Fuzziness
      -> Maybe PrefixLength
      -> Maybe PhraseSlop
      -> Maybe Boost
      -> Maybe AnalyzeWildcard
      -> Maybe GeneratePhraseQueries
      -> Maybe MinimumMatch
      -> Maybe Lenient
      -> Maybe Locale
      -> QueryStringQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe FieldName)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"default_field"
                    Parser
  (Maybe BooleanOperator
   -> Maybe Analyzer
   -> Maybe AllowLeadingWildcard
   -> Maybe LowercaseExpanded
   -> Maybe EnablePositionIncrements
   -> Maybe MaxExpansions
   -> Maybe Fuzziness
   -> Maybe PrefixLength
   -> Maybe PhraseSlop
   -> Maybe Boost
   -> Maybe AnalyzeWildcard
   -> Maybe GeneratePhraseQueries
   -> Maybe MinimumMatch
   -> Maybe Lenient
   -> Maybe Locale
   -> QueryStringQuery)
-> Parser (Maybe BooleanOperator)
-> Parser
     (Maybe Analyzer
      -> Maybe AllowLeadingWildcard
      -> Maybe LowercaseExpanded
      -> Maybe EnablePositionIncrements
      -> Maybe MaxExpansions
      -> Maybe Fuzziness
      -> Maybe PrefixLength
      -> Maybe PhraseSlop
      -> Maybe Boost
      -> Maybe AnalyzeWildcard
      -> Maybe GeneratePhraseQueries
      -> Maybe MinimumMatch
      -> Maybe Lenient
      -> Maybe Locale
      -> QueryStringQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe BooleanOperator)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"default_operator"
                    Parser
  (Maybe Analyzer
   -> Maybe AllowLeadingWildcard
   -> Maybe LowercaseExpanded
   -> Maybe EnablePositionIncrements
   -> Maybe MaxExpansions
   -> Maybe Fuzziness
   -> Maybe PrefixLength
   -> Maybe PhraseSlop
   -> Maybe Boost
   -> Maybe AnalyzeWildcard
   -> Maybe GeneratePhraseQueries
   -> Maybe MinimumMatch
   -> Maybe Lenient
   -> Maybe Locale
   -> QueryStringQuery)
-> Parser (Maybe Analyzer)
-> Parser
     (Maybe AllowLeadingWildcard
      -> Maybe LowercaseExpanded
      -> Maybe EnablePositionIncrements
      -> Maybe MaxExpansions
      -> Maybe Fuzziness
      -> Maybe PrefixLength
      -> Maybe PhraseSlop
      -> Maybe Boost
      -> Maybe AnalyzeWildcard
      -> Maybe GeneratePhraseQueries
      -> Maybe MinimumMatch
      -> Maybe Lenient
      -> Maybe Locale
      -> QueryStringQuery)
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 AllowLeadingWildcard
   -> Maybe LowercaseExpanded
   -> Maybe EnablePositionIncrements
   -> Maybe MaxExpansions
   -> Maybe Fuzziness
   -> Maybe PrefixLength
   -> Maybe PhraseSlop
   -> Maybe Boost
   -> Maybe AnalyzeWildcard
   -> Maybe GeneratePhraseQueries
   -> Maybe MinimumMatch
   -> Maybe Lenient
   -> Maybe Locale
   -> QueryStringQuery)
-> Parser (Maybe AllowLeadingWildcard)
-> Parser
     (Maybe LowercaseExpanded
      -> Maybe EnablePositionIncrements
      -> Maybe MaxExpansions
      -> Maybe Fuzziness
      -> Maybe PrefixLength
      -> Maybe PhraseSlop
      -> Maybe Boost
      -> Maybe AnalyzeWildcard
      -> Maybe GeneratePhraseQueries
      -> Maybe MinimumMatch
      -> Maybe Lenient
      -> Maybe Locale
      -> QueryStringQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe AllowLeadingWildcard)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"allow_leading_wildcard"
                    Parser
  (Maybe LowercaseExpanded
   -> Maybe EnablePositionIncrements
   -> Maybe MaxExpansions
   -> Maybe Fuzziness
   -> Maybe PrefixLength
   -> Maybe PhraseSlop
   -> Maybe Boost
   -> Maybe AnalyzeWildcard
   -> Maybe GeneratePhraseQueries
   -> Maybe MinimumMatch
   -> Maybe Lenient
   -> Maybe Locale
   -> QueryStringQuery)
-> Parser (Maybe LowercaseExpanded)
-> Parser
     (Maybe EnablePositionIncrements
      -> Maybe MaxExpansions
      -> Maybe Fuzziness
      -> Maybe PrefixLength
      -> Maybe PhraseSlop
      -> Maybe Boost
      -> Maybe AnalyzeWildcard
      -> Maybe GeneratePhraseQueries
      -> Maybe MinimumMatch
      -> Maybe Lenient
      -> Maybe Locale
      -> QueryStringQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe LowercaseExpanded)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"lowercase_expanded_terms"
                    Parser
  (Maybe EnablePositionIncrements
   -> Maybe MaxExpansions
   -> Maybe Fuzziness
   -> Maybe PrefixLength
   -> Maybe PhraseSlop
   -> Maybe Boost
   -> Maybe AnalyzeWildcard
   -> Maybe GeneratePhraseQueries
   -> Maybe MinimumMatch
   -> Maybe Lenient
   -> Maybe Locale
   -> QueryStringQuery)
-> Parser (Maybe EnablePositionIncrements)
-> Parser
     (Maybe MaxExpansions
      -> Maybe Fuzziness
      -> Maybe PrefixLength
      -> Maybe PhraseSlop
      -> Maybe Boost
      -> Maybe AnalyzeWildcard
      -> Maybe GeneratePhraseQueries
      -> Maybe MinimumMatch
      -> Maybe Lenient
      -> Maybe Locale
      -> QueryStringQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe EnablePositionIncrements)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"enable_position_increments"
                    Parser
  (Maybe MaxExpansions
   -> Maybe Fuzziness
   -> Maybe PrefixLength
   -> Maybe PhraseSlop
   -> Maybe Boost
   -> Maybe AnalyzeWildcard
   -> Maybe GeneratePhraseQueries
   -> Maybe MinimumMatch
   -> Maybe Lenient
   -> Maybe Locale
   -> QueryStringQuery)
-> Parser (Maybe MaxExpansions)
-> Parser
     (Maybe Fuzziness
      -> Maybe PrefixLength
      -> Maybe PhraseSlop
      -> Maybe Boost
      -> Maybe AnalyzeWildcard
      -> Maybe GeneratePhraseQueries
      -> Maybe MinimumMatch
      -> Maybe Lenient
      -> Maybe Locale
      -> QueryStringQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe MaxExpansions)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"fuzzy_max_expansions"
                    Parser
  (Maybe Fuzziness
   -> Maybe PrefixLength
   -> Maybe PhraseSlop
   -> Maybe Boost
   -> Maybe AnalyzeWildcard
   -> Maybe GeneratePhraseQueries
   -> Maybe MinimumMatch
   -> Maybe Lenient
   -> Maybe Locale
   -> QueryStringQuery)
-> Parser (Maybe Fuzziness)
-> Parser
     (Maybe PrefixLength
      -> Maybe PhraseSlop
      -> Maybe Boost
      -> Maybe AnalyzeWildcard
      -> Maybe GeneratePhraseQueries
      -> Maybe MinimumMatch
      -> Maybe Lenient
      -> Maybe Locale
      -> QueryStringQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Fuzziness)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"fuzziness"
                    Parser
  (Maybe PrefixLength
   -> Maybe PhraseSlop
   -> Maybe Boost
   -> Maybe AnalyzeWildcard
   -> Maybe GeneratePhraseQueries
   -> Maybe MinimumMatch
   -> Maybe Lenient
   -> Maybe Locale
   -> QueryStringQuery)
-> Parser (Maybe PrefixLength)
-> Parser
     (Maybe PhraseSlop
      -> Maybe Boost
      -> Maybe AnalyzeWildcard
      -> Maybe GeneratePhraseQueries
      -> Maybe MinimumMatch
      -> Maybe Lenient
      -> Maybe Locale
      -> QueryStringQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe PrefixLength)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"fuzzy_prefix_length"
                    Parser
  (Maybe PhraseSlop
   -> Maybe Boost
   -> Maybe AnalyzeWildcard
   -> Maybe GeneratePhraseQueries
   -> Maybe MinimumMatch
   -> Maybe Lenient
   -> Maybe Locale
   -> QueryStringQuery)
-> Parser (Maybe PhraseSlop)
-> Parser
     (Maybe Boost
      -> Maybe AnalyzeWildcard
      -> Maybe GeneratePhraseQueries
      -> Maybe MinimumMatch
      -> Maybe Lenient
      -> Maybe Locale
      -> QueryStringQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe PhraseSlop)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"phrase_slop"
                    Parser
  (Maybe Boost
   -> Maybe AnalyzeWildcard
   -> Maybe GeneratePhraseQueries
   -> Maybe MinimumMatch
   -> Maybe Lenient
   -> Maybe Locale
   -> QueryStringQuery)
-> Parser (Maybe Boost)
-> Parser
     (Maybe AnalyzeWildcard
      -> Maybe GeneratePhraseQueries
      -> Maybe MinimumMatch
      -> Maybe Lenient
      -> Maybe Locale
      -> QueryStringQuery)
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 AnalyzeWildcard
   -> Maybe GeneratePhraseQueries
   -> Maybe MinimumMatch
   -> Maybe Lenient
   -> Maybe Locale
   -> QueryStringQuery)
-> Parser (Maybe AnalyzeWildcard)
-> Parser
     (Maybe GeneratePhraseQueries
      -> Maybe MinimumMatch
      -> Maybe Lenient
      -> Maybe Locale
      -> QueryStringQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe AnalyzeWildcard)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"analyze_wildcard"
                    Parser
  (Maybe GeneratePhraseQueries
   -> Maybe MinimumMatch
   -> Maybe Lenient
   -> Maybe Locale
   -> QueryStringQuery)
-> Parser (Maybe GeneratePhraseQueries)
-> Parser
     (Maybe MinimumMatch
      -> Maybe Lenient -> Maybe Locale -> QueryStringQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe GeneratePhraseQueries)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"auto_generate_phrase_queries"
                    Parser
  (Maybe MinimumMatch
   -> Maybe Lenient -> Maybe Locale -> QueryStringQuery)
-> Parser (Maybe MinimumMatch)
-> Parser (Maybe Lenient -> Maybe Locale -> QueryStringQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe MinimumMatch)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"minimum_should_match"
                    Parser (Maybe Lenient -> Maybe Locale -> QueryStringQuery)
-> Parser (Maybe Lenient)
-> Parser (Maybe Locale -> QueryStringQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Lenient)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"lenient"
                    Parser (Maybe Locale -> QueryStringQuery)
-> Parser (Maybe Locale) -> Parser QueryStringQuery
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Locale)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"locale"

mkQueryStringQuery :: QueryString -> QueryStringQuery
mkQueryStringQuery :: QueryString -> QueryStringQuery
mkQueryStringQuery QueryString
qs =
  QueryString
-> Maybe FieldName
-> Maybe BooleanOperator
-> Maybe Analyzer
-> Maybe AllowLeadingWildcard
-> Maybe LowercaseExpanded
-> Maybe EnablePositionIncrements
-> Maybe MaxExpansions
-> Maybe Fuzziness
-> Maybe PrefixLength
-> Maybe PhraseSlop
-> Maybe Boost
-> Maybe AnalyzeWildcard
-> Maybe GeneratePhraseQueries
-> Maybe MinimumMatch
-> Maybe Lenient
-> Maybe Locale
-> QueryStringQuery
QueryStringQuery QueryString
qs Maybe FieldName
forall a. Maybe a
Nothing Maybe BooleanOperator
forall a. Maybe a
Nothing
  Maybe Analyzer
forall a. Maybe a
Nothing Maybe AllowLeadingWildcard
forall a. Maybe a
Nothing Maybe LowercaseExpanded
forall a. Maybe a
Nothing Maybe EnablePositionIncrements
forall a. Maybe a
Nothing
  Maybe MaxExpansions
forall a. Maybe a
Nothing Maybe Fuzziness
forall a. Maybe a
Nothing Maybe PrefixLength
forall a. Maybe a
Nothing Maybe PhraseSlop
forall a. Maybe a
Nothing
  Maybe Boost
forall a. Maybe a
Nothing Maybe AnalyzeWildcard
forall a. Maybe a
Nothing Maybe GeneratePhraseQueries
forall a. Maybe a
Nothing Maybe MinimumMatch
forall a. Maybe a
Nothing
  Maybe Lenient
forall a. Maybe a
Nothing Maybe Locale
forall a. Maybe a
Nothing

data FieldOrFields = FofField   FieldName
                   | FofFields (NonEmpty FieldName) deriving (FieldOrFields -> FieldOrFields -> Bool
(FieldOrFields -> FieldOrFields -> Bool)
-> (FieldOrFields -> FieldOrFields -> Bool) -> Eq FieldOrFields
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FieldOrFields -> FieldOrFields -> Bool
$c/= :: FieldOrFields -> FieldOrFields -> Bool
== :: FieldOrFields -> FieldOrFields -> Bool
$c== :: FieldOrFields -> FieldOrFields -> Bool
Eq, Int -> FieldOrFields -> ShowS
[FieldOrFields] -> ShowS
FieldOrFields -> String
(Int -> FieldOrFields -> ShowS)
-> (FieldOrFields -> String)
-> ([FieldOrFields] -> ShowS)
-> Show FieldOrFields
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FieldOrFields] -> ShowS
$cshowList :: [FieldOrFields] -> ShowS
show :: FieldOrFields -> String
$cshow :: FieldOrFields -> String
showsPrec :: Int -> FieldOrFields -> ShowS
$cshowsPrec :: Int -> FieldOrFields -> ShowS
Show)

instance ToJSON FieldOrFields where
  toJSON :: FieldOrFields -> Value
toJSON (FofField FieldName
fieldName) =
    FieldName -> Value
forall a. ToJSON a => a -> Value
toJSON FieldName
fieldName
  toJSON (FofFields NonEmpty FieldName
fieldNames) =
    NonEmpty FieldName -> Value
forall a. ToJSON a => a -> Value
toJSON NonEmpty FieldName
fieldNames

instance FromJSON FieldOrFields where
  parseJSON :: Value -> Parser FieldOrFields
parseJSON Value
v = FieldName -> FieldOrFields
FofField  (FieldName -> FieldOrFields)
-> Parser FieldName -> Parser FieldOrFields
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser FieldName
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v
            Parser FieldOrFields
-> Parser FieldOrFields -> Parser FieldOrFields
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> NonEmpty FieldName -> FieldOrFields
FofFields (NonEmpty FieldName -> FieldOrFields)
-> Parser (NonEmpty FieldName) -> Parser FieldOrFields
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([Value] -> Parser (NonEmpty FieldName)
forall a. FromJSON a => [Value] -> Parser (NonEmpty a)
parseNEJSON ([Value] -> Parser (NonEmpty FieldName))
-> Parser [Value] -> Parser (NonEmpty FieldName)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Value -> Parser [Value]
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v)

data PrefixQuery =
  PrefixQuery
  { PrefixQuery -> FieldName
prefixQueryField       :: FieldName
  , PrefixQuery -> Text
prefixQueryPrefixValue :: Text
  , PrefixQuery -> Maybe Boost
prefixQueryBoost       :: Maybe Boost } deriving (PrefixQuery -> PrefixQuery -> Bool
(PrefixQuery -> PrefixQuery -> Bool)
-> (PrefixQuery -> PrefixQuery -> Bool) -> Eq PrefixQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PrefixQuery -> PrefixQuery -> Bool
$c/= :: PrefixQuery -> PrefixQuery -> Bool
== :: PrefixQuery -> PrefixQuery -> Bool
$c== :: PrefixQuery -> PrefixQuery -> Bool
Eq, Int -> PrefixQuery -> ShowS
[PrefixQuery] -> ShowS
PrefixQuery -> String
(Int -> PrefixQuery -> ShowS)
-> (PrefixQuery -> String)
-> ([PrefixQuery] -> ShowS)
-> Show PrefixQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PrefixQuery] -> ShowS
$cshowList :: [PrefixQuery] -> ShowS
show :: PrefixQuery -> String
$cshow :: PrefixQuery -> String
showsPrec :: Int -> PrefixQuery -> ShowS
$cshowsPrec :: Int -> PrefixQuery -> ShowS
Show)

instance ToJSON PrefixQuery where
  toJSON :: PrefixQuery -> Value
toJSON (PrefixQuery (FieldName Text
fieldName) Text
queryValue Maybe Boost
boost) =
    [Pair] -> Value
object [ Text -> Key
fromText Text
fieldName Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Pair] -> Value
omitNulls [Pair]
base ]
    where base :: [Pair]
base = [ Key
"value" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
queryValue
                 , Key
"boost" Key -> Maybe Boost -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Boost
boost ]

instance FromJSON PrefixQuery where
  parseJSON :: Value -> Parser PrefixQuery
parseJSON = String
-> (Object -> Parser PrefixQuery) -> Value -> Parser PrefixQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"PrefixQuery" Object -> Parser PrefixQuery
parse
    where parse :: Object -> Parser PrefixQuery
parse = (FieldName -> Object -> Parser PrefixQuery)
-> Object -> Parser PrefixQuery
forall (m :: * -> *) a.
(Monad m, MonadFail m) =>
(FieldName -> Object -> m a) -> Object -> m a
fieldTagged ((FieldName -> Object -> Parser PrefixQuery)
 -> Object -> Parser PrefixQuery)
-> (FieldName -> Object -> Parser PrefixQuery)
-> Object
-> Parser PrefixQuery
forall a b. (a -> b) -> a -> b
$ \FieldName
fn Object
o ->
                    FieldName -> Text -> Maybe Boost -> PrefixQuery
PrefixQuery FieldName
fn
                    (Text -> Maybe Boost -> PrefixQuery)
-> Parser Text -> Parser (Maybe Boost -> PrefixQuery)
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
"value"
                    Parser (Maybe Boost -> PrefixQuery)
-> Parser (Maybe Boost) -> Parser PrefixQuery
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"

data NestedQuery =
  NestedQuery
  { NestedQuery -> QueryPath
nestedQueryPath      :: QueryPath
  , NestedQuery -> ScoreType
nestedQueryScoreType :: ScoreType
  , NestedQuery -> Query
nestedQuery          :: Query
  , NestedQuery -> Maybe InnerHits
nestedQueryInnerHits :: Maybe InnerHits } deriving (NestedQuery -> NestedQuery -> Bool
(NestedQuery -> NestedQuery -> Bool)
-> (NestedQuery -> NestedQuery -> Bool) -> Eq NestedQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NestedQuery -> NestedQuery -> Bool
$c/= :: NestedQuery -> NestedQuery -> Bool
== :: NestedQuery -> NestedQuery -> Bool
$c== :: NestedQuery -> NestedQuery -> Bool
Eq, Int -> NestedQuery -> ShowS
[NestedQuery] -> ShowS
NestedQuery -> String
(Int -> NestedQuery -> ShowS)
-> (NestedQuery -> String)
-> ([NestedQuery] -> ShowS)
-> Show NestedQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NestedQuery] -> ShowS
$cshowList :: [NestedQuery] -> ShowS
show :: NestedQuery -> String
$cshow :: NestedQuery -> String
showsPrec :: Int -> NestedQuery -> ShowS
$cshowsPrec :: Int -> NestedQuery -> ShowS
Show)

instance ToJSON NestedQuery where
  toJSON :: NestedQuery -> Value
toJSON (NestedQuery QueryPath
nqPath ScoreType
nqScoreType Query
nqQuery Maybe InnerHits
nqInnerHits) =
    [Pair] -> Value
omitNulls [ Key
"path"       Key -> QueryPath -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= QueryPath
nqPath
              , Key
"score_mode" Key -> ScoreType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= ScoreType
nqScoreType
              , Key
"query"      Key -> Query -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Query
nqQuery
              , Key
"inner_hits" Key -> Maybe InnerHits -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe InnerHits
nqInnerHits
              ]

instance FromJSON NestedQuery where
  parseJSON :: Value -> Parser NestedQuery
parseJSON = String
-> (Object -> Parser NestedQuery) -> Value -> Parser NestedQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"NestedQuery" Object -> Parser NestedQuery
parse
    where parse :: Object -> Parser NestedQuery
parse Object
o = QueryPath -> ScoreType -> Query -> Maybe InnerHits -> NestedQuery
NestedQuery
                    (QueryPath -> ScoreType -> Query -> Maybe InnerHits -> NestedQuery)
-> Parser QueryPath
-> Parser (ScoreType -> Query -> Maybe InnerHits -> NestedQuery)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser QueryPath
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"path"
                    Parser (ScoreType -> Query -> Maybe InnerHits -> NestedQuery)
-> Parser ScoreType
-> Parser (Query -> Maybe InnerHits -> NestedQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser ScoreType
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"score_mode"
                    Parser (Query -> Maybe InnerHits -> NestedQuery)
-> Parser Query -> Parser (Maybe InnerHits -> NestedQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Query
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"query"
                    Parser (Maybe InnerHits -> NestedQuery)
-> Parser (Maybe InnerHits) -> Parser NestedQuery
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe InnerHits)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"inner_hits"

data MoreLikeThisFieldQuery =
  MoreLikeThisFieldQuery
  { MoreLikeThisFieldQuery -> Text
moreLikeThisFieldText            :: Text
  , MoreLikeThisFieldQuery -> FieldName
moreLikeThisFieldFields          :: FieldName
                                        -- default 0.3 (30%)
  , MoreLikeThisFieldQuery -> Maybe PercentMatch
moreLikeThisFieldPercentMatch    :: Maybe PercentMatch
  , MoreLikeThisFieldQuery -> Maybe MinimumTermFrequency
moreLikeThisFieldMinimumTermFreq :: Maybe MinimumTermFrequency
  , MoreLikeThisFieldQuery -> Maybe MaxQueryTerms
moreLikeThisFieldMaxQueryTerms   :: Maybe MaxQueryTerms
  , MoreLikeThisFieldQuery -> Maybe (NonEmpty StopWord)
moreLikeThisFieldStopWords       :: Maybe (NonEmpty StopWord)
  , MoreLikeThisFieldQuery -> Maybe MinDocFrequency
moreLikeThisFieldMinDocFrequency :: Maybe MinDocFrequency
  , MoreLikeThisFieldQuery -> Maybe MaxDocFrequency
moreLikeThisFieldMaxDocFrequency :: Maybe MaxDocFrequency
  , MoreLikeThisFieldQuery -> Maybe MinWordLength
moreLikeThisFieldMinWordLength   :: Maybe MinWordLength
  , MoreLikeThisFieldQuery -> Maybe MaxWordLength
moreLikeThisFieldMaxWordLength   :: Maybe MaxWordLength
  , MoreLikeThisFieldQuery -> Maybe BoostTerms
moreLikeThisFieldBoostTerms      :: Maybe BoostTerms
  , MoreLikeThisFieldQuery -> Maybe Boost
moreLikeThisFieldBoost           :: Maybe Boost
  , MoreLikeThisFieldQuery -> Maybe Analyzer
moreLikeThisFieldAnalyzer        :: Maybe Analyzer
  } deriving (MoreLikeThisFieldQuery -> MoreLikeThisFieldQuery -> Bool
(MoreLikeThisFieldQuery -> MoreLikeThisFieldQuery -> Bool)
-> (MoreLikeThisFieldQuery -> MoreLikeThisFieldQuery -> Bool)
-> Eq MoreLikeThisFieldQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MoreLikeThisFieldQuery -> MoreLikeThisFieldQuery -> Bool
$c/= :: MoreLikeThisFieldQuery -> MoreLikeThisFieldQuery -> Bool
== :: MoreLikeThisFieldQuery -> MoreLikeThisFieldQuery -> Bool
$c== :: MoreLikeThisFieldQuery -> MoreLikeThisFieldQuery -> Bool
Eq, Int -> MoreLikeThisFieldQuery -> ShowS
[MoreLikeThisFieldQuery] -> ShowS
MoreLikeThisFieldQuery -> String
(Int -> MoreLikeThisFieldQuery -> ShowS)
-> (MoreLikeThisFieldQuery -> String)
-> ([MoreLikeThisFieldQuery] -> ShowS)
-> Show MoreLikeThisFieldQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MoreLikeThisFieldQuery] -> ShowS
$cshowList :: [MoreLikeThisFieldQuery] -> ShowS
show :: MoreLikeThisFieldQuery -> String
$cshow :: MoreLikeThisFieldQuery -> String
showsPrec :: Int -> MoreLikeThisFieldQuery -> ShowS
$cshowsPrec :: Int -> MoreLikeThisFieldQuery -> ShowS
Show)


instance ToJSON MoreLikeThisFieldQuery where
  toJSON :: MoreLikeThisFieldQuery -> Value
toJSON (MoreLikeThisFieldQuery Text
text (FieldName Text
fieldName)
          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) =
    [Pair] -> Value
object [ Text -> Key
fromText Text
fieldName Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Pair] -> Value
omitNulls [Pair]
base ]
    where base :: [Pair]
base = [ Key
"like_text" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
text
                 , Key
"percent_terms_to_match" Key -> Maybe PercentMatch -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe PercentMatch
percent
                 , Key
"min_term_freq" Key -> Maybe MinimumTermFrequency -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe MinimumTermFrequency
mtf
                 , Key
"max_query_terms" Key -> Maybe MaxQueryTerms -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe MaxQueryTerms
mqt
                 , Key
"stop_words" Key -> Maybe (NonEmpty StopWord) -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe (NonEmpty StopWord)
stopwords
                 , Key
"min_doc_freq" Key -> Maybe MinDocFrequency -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe MinDocFrequency
mindf
                 , Key
"max_doc_freq" Key -> Maybe MaxDocFrequency -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe MaxDocFrequency
maxdf
                 , Key
"min_word_length" Key -> Maybe MinWordLength -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe MinWordLength
minwl
                 , Key
"max_word_length" Key -> Maybe MaxWordLength -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe MaxWordLength
maxwl
                 , Key
"boost_terms" Key -> Maybe BoostTerms -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe BoostTerms
boostTerms
                 , Key
"boost" Key -> Maybe Boost -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Boost
boost
                 , Key
"analyzer" Key -> Maybe Analyzer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Analyzer
analyzer ]

instance FromJSON MoreLikeThisFieldQuery where
  parseJSON :: Value -> Parser MoreLikeThisFieldQuery
parseJSON = String
-> (Object -> Parser MoreLikeThisFieldQuery)
-> Value
-> Parser MoreLikeThisFieldQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"MoreLikeThisFieldQuery" Object -> Parser MoreLikeThisFieldQuery
parse
    where parse :: Object -> Parser MoreLikeThisFieldQuery
parse = (FieldName -> Object -> Parser MoreLikeThisFieldQuery)
-> Object -> Parser MoreLikeThisFieldQuery
forall (m :: * -> *) a.
(Monad m, MonadFail m) =>
(FieldName -> Object -> m a) -> Object -> m a
fieldTagged ((FieldName -> Object -> Parser MoreLikeThisFieldQuery)
 -> Object -> Parser MoreLikeThisFieldQuery)
-> (FieldName -> Object -> Parser MoreLikeThisFieldQuery)
-> Object
-> Parser MoreLikeThisFieldQuery
forall a b. (a -> b) -> a -> b
$ \FieldName
fn Object
o ->
                    Text
-> FieldName
-> Maybe PercentMatch
-> Maybe MinimumTermFrequency
-> Maybe MaxQueryTerms
-> Maybe (NonEmpty StopWord)
-> Maybe MinDocFrequency
-> Maybe MaxDocFrequency
-> Maybe MinWordLength
-> Maybe MaxWordLength
-> Maybe BoostTerms
-> Maybe Boost
-> Maybe Analyzer
-> MoreLikeThisFieldQuery
MoreLikeThisFieldQuery
                    (Text
 -> FieldName
 -> Maybe PercentMatch
 -> Maybe MinimumTermFrequency
 -> Maybe MaxQueryTerms
 -> Maybe (NonEmpty StopWord)
 -> Maybe MinDocFrequency
 -> Maybe MaxDocFrequency
 -> Maybe MinWordLength
 -> Maybe MaxWordLength
 -> Maybe BoostTerms
 -> Maybe Boost
 -> Maybe Analyzer
 -> MoreLikeThisFieldQuery)
-> Parser Text
-> Parser
     (FieldName
      -> Maybe PercentMatch
      -> Maybe MinimumTermFrequency
      -> Maybe MaxQueryTerms
      -> Maybe (NonEmpty StopWord)
      -> Maybe MinDocFrequency
      -> Maybe MaxDocFrequency
      -> Maybe MinWordLength
      -> Maybe MaxWordLength
      -> Maybe BoostTerms
      -> Maybe Boost
      -> Maybe Analyzer
      -> MoreLikeThisFieldQuery)
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
  (FieldName
   -> Maybe PercentMatch
   -> Maybe MinimumTermFrequency
   -> Maybe MaxQueryTerms
   -> Maybe (NonEmpty StopWord)
   -> Maybe MinDocFrequency
   -> Maybe MaxDocFrequency
   -> Maybe MinWordLength
   -> Maybe MaxWordLength
   -> Maybe BoostTerms
   -> Maybe Boost
   -> Maybe Analyzer
   -> MoreLikeThisFieldQuery)
-> Parser 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
      -> MoreLikeThisFieldQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FieldName -> Parser FieldName
forall (f :: * -> *) a. Applicative f => a -> f a
pure FieldName
fn
                    Parser
  (Maybe PercentMatch
   -> Maybe MinimumTermFrequency
   -> Maybe MaxQueryTerms
   -> Maybe (NonEmpty StopWord)
   -> Maybe MinDocFrequency
   -> Maybe MaxDocFrequency
   -> Maybe MinWordLength
   -> Maybe MaxWordLength
   -> Maybe BoostTerms
   -> Maybe Boost
   -> Maybe Analyzer
   -> MoreLikeThisFieldQuery)
-> 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
      -> MoreLikeThisFieldQuery)
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
   -> MoreLikeThisFieldQuery)
-> Parser (Maybe MinimumTermFrequency)
-> Parser
     (Maybe MaxQueryTerms
      -> Maybe (NonEmpty StopWord)
      -> Maybe MinDocFrequency
      -> Maybe MaxDocFrequency
      -> Maybe MinWordLength
      -> Maybe MaxWordLength
      -> Maybe BoostTerms
      -> Maybe Boost
      -> Maybe Analyzer
      -> MoreLikeThisFieldQuery)
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
   -> MoreLikeThisFieldQuery)
-> Parser (Maybe MaxQueryTerms)
-> Parser
     (Maybe (NonEmpty StopWord)
      -> Maybe MinDocFrequency
      -> Maybe MaxDocFrequency
      -> Maybe MinWordLength
      -> Maybe MaxWordLength
      -> Maybe BoostTerms
      -> Maybe Boost
      -> Maybe Analyzer
      -> MoreLikeThisFieldQuery)
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"
                    -- <*> (optionalNE =<< o .:? "stop_words")
                    Parser
  (Maybe (NonEmpty StopWord)
   -> Maybe MinDocFrequency
   -> Maybe MaxDocFrequency
   -> Maybe MinWordLength
   -> Maybe MaxWordLength
   -> Maybe BoostTerms
   -> Maybe Boost
   -> Maybe Analyzer
   -> MoreLikeThisFieldQuery)
-> Parser (Maybe (NonEmpty StopWord))
-> Parser
     (Maybe MinDocFrequency
      -> Maybe MaxDocFrequency
      -> Maybe MinWordLength
      -> Maybe MaxWordLength
      -> Maybe BoostTerms
      -> Maybe Boost
      -> Maybe Analyzer
      -> MoreLikeThisFieldQuery)
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
   -> MoreLikeThisFieldQuery)
-> Parser (Maybe MinDocFrequency)
-> Parser
     (Maybe MaxDocFrequency
      -> Maybe MinWordLength
      -> Maybe MaxWordLength
      -> Maybe BoostTerms
      -> Maybe Boost
      -> Maybe Analyzer
      -> MoreLikeThisFieldQuery)
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
   -> MoreLikeThisFieldQuery)
-> Parser (Maybe MaxDocFrequency)
-> Parser
     (Maybe MinWordLength
      -> Maybe MaxWordLength
      -> Maybe BoostTerms
      -> Maybe Boost
      -> Maybe Analyzer
      -> MoreLikeThisFieldQuery)
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
   -> MoreLikeThisFieldQuery)
-> Parser (Maybe MinWordLength)
-> Parser
     (Maybe MaxWordLength
      -> Maybe BoostTerms
      -> Maybe Boost
      -> Maybe Analyzer
      -> MoreLikeThisFieldQuery)
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
   -> MoreLikeThisFieldQuery)
-> Parser (Maybe MaxWordLength)
-> Parser
     (Maybe BoostTerms
      -> Maybe Boost -> Maybe Analyzer -> MoreLikeThisFieldQuery)
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 -> MoreLikeThisFieldQuery)
-> Parser (Maybe BoostTerms)
-> Parser (Maybe Boost -> Maybe Analyzer -> MoreLikeThisFieldQuery)
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 -> MoreLikeThisFieldQuery)
-> Parser (Maybe Boost)
-> Parser (Maybe Analyzer -> MoreLikeThisFieldQuery)
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 -> MoreLikeThisFieldQuery)
-> Parser (Maybe Analyzer) -> Parser MoreLikeThisFieldQuery
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"
          -- optionalNE = maybe (pure Nothing) (fmap Just . parseNEJSON)

data MoreLikeThisQuery =
  MoreLikeThisQuery
  { MoreLikeThisQuery -> Text
moreLikeThisText            :: Text
  , MoreLikeThisQuery -> Maybe (NonEmpty FieldName)
moreLikeThisFields          :: Maybe (NonEmpty FieldName)
    -- default 0.3 (30%)
  , 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 (MoreLikeThisQuery -> MoreLikeThisQuery -> Bool
(MoreLikeThisQuery -> MoreLikeThisQuery -> Bool)
-> (MoreLikeThisQuery -> MoreLikeThisQuery -> Bool)
-> Eq MoreLikeThisQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MoreLikeThisQuery -> MoreLikeThisQuery -> Bool
$c/= :: MoreLikeThisQuery -> MoreLikeThisQuery -> Bool
== :: MoreLikeThisQuery -> MoreLikeThisQuery -> Bool
$c== :: 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
showList :: [MoreLikeThisQuery] -> ShowS
$cshowList :: [MoreLikeThisQuery] -> ShowS
show :: MoreLikeThisQuery -> String
$cshow :: MoreLikeThisQuery -> String
showsPrec :: Int -> MoreLikeThisQuery -> ShowS
$cshowsPrec :: Int -> MoreLikeThisQuery -> ShowS
Show)


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) =
    [Pair] -> Value
omitNulls [Pair]
base
    where base :: [Pair]
base = [ Key
"like_text" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
text
                 , Key
"fields" Key -> Maybe (NonEmpty FieldName) -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe (NonEmpty FieldName)
fields
                 , Key
"percent_terms_to_match" Key -> Maybe PercentMatch -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe PercentMatch
percent
                 , Key
"min_term_freq" Key -> Maybe MinimumTermFrequency -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe MinimumTermFrequency
mtf
                 , Key
"max_query_terms" Key -> Maybe MaxQueryTerms -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe MaxQueryTerms
mqt
                 , Key
"stop_words" Key -> Maybe (NonEmpty StopWord) -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe (NonEmpty StopWord)
stopwords
                 , Key
"min_doc_freq" Key -> Maybe MinDocFrequency -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe MinDocFrequency
mindf
                 , Key
"max_doc_freq" Key -> Maybe MaxDocFrequency -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe MaxDocFrequency
maxdf
                 , Key
"min_word_length" Key -> Maybe MinWordLength -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe MinWordLength
minwl
                 , Key
"max_word_length" Key -> Maybe MaxWordLength -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe MaxWordLength
maxwl
                 , Key
"boost_terms" Key -> Maybe BoostTerms -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe BoostTerms
boostTerms
                 , Key
"boost" Key -> Maybe Boost -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Boost
boost
                 , Key
"analyzer" Key -> Maybe Analyzer -> Pair
forall kv v. (KeyValue 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"
                    -- <*> (optionalNE =<< o .:? "fields")
                    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 (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 (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 (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 (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"
                    -- <*> (optionalNE =<< o .:? "stop_words")
                    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 (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 (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 (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 (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 (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 (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 (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 (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"
          -- optionalNE = maybe (pure Nothing) (fmap Just . parseNEJSON)

data IndicesQuery =
  IndicesQuery
  { IndicesQuery -> [IndexName]
indicesQueryIndices :: [IndexName]
  , IndicesQuery -> Query
indicesQuery        :: Query
    -- default "all"
  , IndicesQuery -> Maybe Query
indicesQueryNoMatch :: Maybe Query } deriving (IndicesQuery -> IndicesQuery -> Bool
(IndicesQuery -> IndicesQuery -> Bool)
-> (IndicesQuery -> IndicesQuery -> Bool) -> Eq IndicesQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IndicesQuery -> IndicesQuery -> Bool
$c/= :: IndicesQuery -> IndicesQuery -> Bool
== :: IndicesQuery -> IndicesQuery -> Bool
$c== :: IndicesQuery -> IndicesQuery -> Bool
Eq, Int -> IndicesQuery -> ShowS
[IndicesQuery] -> ShowS
IndicesQuery -> String
(Int -> IndicesQuery -> ShowS)
-> (IndicesQuery -> String)
-> ([IndicesQuery] -> ShowS)
-> Show IndicesQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IndicesQuery] -> ShowS
$cshowList :: [IndicesQuery] -> ShowS
show :: IndicesQuery -> String
$cshow :: IndicesQuery -> String
showsPrec :: Int -> IndicesQuery -> ShowS
$cshowsPrec :: Int -> IndicesQuery -> ShowS
Show)


instance ToJSON IndicesQuery where
  toJSON :: IndicesQuery -> Value
toJSON (IndicesQuery [IndexName]
indices Query
query Maybe Query
noMatch) =
    [Pair] -> Value
omitNulls [ Key
"indices" Key -> [IndexName] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [IndexName]
indices
              , Key
"no_match_query" Key -> Maybe Query -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Query
noMatch
              , Key
"query" Key -> Query -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Query
query ]

instance FromJSON IndicesQuery where
  parseJSON :: Value -> Parser IndicesQuery
parseJSON = String
-> (Object -> Parser IndicesQuery) -> Value -> Parser IndicesQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"IndicesQuery" Object -> Parser IndicesQuery
parse
    where parse :: Object -> Parser IndicesQuery
parse Object
o = [IndexName] -> Query -> Maybe Query -> IndicesQuery
IndicesQuery
                    ([IndexName] -> Query -> Maybe Query -> IndicesQuery)
-> Parser [IndexName]
-> Parser (Query -> Maybe Query -> IndicesQuery)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe [IndexName])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"indices" Parser (Maybe [IndexName]) -> [IndexName] -> Parser [IndexName]
forall a. Parser (Maybe a) -> a -> Parser a
.!= []
                    Parser (Query -> Maybe Query -> IndicesQuery)
-> Parser Query -> Parser (Maybe Query -> IndicesQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Query
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"query"
                    Parser (Maybe Query -> IndicesQuery)
-> Parser (Maybe Query) -> Parser IndicesQuery
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Query)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"no_match_query"

data HasParentQuery =
  HasParentQuery
  { HasParentQuery -> RelationName
hasParentQueryType      :: RelationName
  , HasParentQuery -> Query
hasParentQuery          :: Query
  , HasParentQuery -> Maybe AggregateParentScore
hasParentQueryScore     :: Maybe AggregateParentScore
  , HasParentQuery -> Maybe IgnoreUnmapped
hasParentIgnoreUnmapped :: Maybe IgnoreUnmapped
  } deriving (HasParentQuery -> HasParentQuery -> Bool
(HasParentQuery -> HasParentQuery -> Bool)
-> (HasParentQuery -> HasParentQuery -> Bool) -> Eq HasParentQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HasParentQuery -> HasParentQuery -> Bool
$c/= :: HasParentQuery -> HasParentQuery -> Bool
== :: HasParentQuery -> HasParentQuery -> Bool
$c== :: HasParentQuery -> HasParentQuery -> Bool
Eq, Int -> HasParentQuery -> ShowS
[HasParentQuery] -> ShowS
HasParentQuery -> String
(Int -> HasParentQuery -> ShowS)
-> (HasParentQuery -> String)
-> ([HasParentQuery] -> ShowS)
-> Show HasParentQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HasParentQuery] -> ShowS
$cshowList :: [HasParentQuery] -> ShowS
show :: HasParentQuery -> String
$cshow :: HasParentQuery -> String
showsPrec :: Int -> HasParentQuery -> ShowS
$cshowsPrec :: Int -> HasParentQuery -> ShowS
Show)

instance ToJSON HasParentQuery where
  toJSON :: HasParentQuery -> Value
toJSON (HasParentQuery RelationName
queryType Query
query Maybe AggregateParentScore
scoreType Maybe IgnoreUnmapped
ignoreUnmapped) =
    [Pair] -> Value
omitNulls [ Key
"parent_type" Key -> RelationName -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= RelationName
queryType
              , Key
"score" Key -> Maybe AggregateParentScore -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe AggregateParentScore
scoreType
              , Key
"query" Key -> Query -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Query
query
              , Key
"ignore_unmapped" Key -> Maybe IgnoreUnmapped -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe IgnoreUnmapped
ignoreUnmapped
              ]

instance FromJSON HasParentQuery where
  parseJSON :: Value -> Parser HasParentQuery
parseJSON = String
-> (Object -> Parser HasParentQuery)
-> Value
-> Parser HasParentQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"HasParentQuery" Object -> Parser HasParentQuery
parse
    where parse :: Object -> Parser HasParentQuery
parse Object
o = RelationName
-> Query
-> Maybe AggregateParentScore
-> Maybe IgnoreUnmapped
-> HasParentQuery
HasParentQuery
                    (RelationName
 -> Query
 -> Maybe AggregateParentScore
 -> Maybe IgnoreUnmapped
 -> HasParentQuery)
-> Parser RelationName
-> Parser
     (Query
      -> Maybe AggregateParentScore
      -> Maybe IgnoreUnmapped
      -> HasParentQuery)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser RelationName
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"parent_type"
                    Parser
  (Query
   -> Maybe AggregateParentScore
   -> Maybe IgnoreUnmapped
   -> HasParentQuery)
-> Parser Query
-> Parser
     (Maybe AggregateParentScore
      -> Maybe IgnoreUnmapped -> HasParentQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Query
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"query"
                    Parser
  (Maybe AggregateParentScore
   -> Maybe IgnoreUnmapped -> HasParentQuery)
-> Parser (Maybe AggregateParentScore)
-> Parser (Maybe IgnoreUnmapped -> HasParentQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe AggregateParentScore)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"score"
                    Parser (Maybe IgnoreUnmapped -> HasParentQuery)
-> Parser (Maybe IgnoreUnmapped) -> Parser HasParentQuery
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe IgnoreUnmapped)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"ignore_unmapped"

data HasChildQuery =
  HasChildQuery
  { HasChildQuery -> RelationName
hasChildQueryType       :: RelationName
  , HasChildQuery -> Query
hasChildQuery           :: Query
  , HasChildQuery -> Maybe ScoreType
hasChildQueryScoreType  :: Maybe ScoreType
  , HasChildQuery -> Maybe IgnoreUnmapped
hasChildIgnoreUnmappped :: Maybe IgnoreUnmapped
  , HasChildQuery -> Maybe MinChildren
hasChildMinChildren     :: Maybe MinChildren
  , HasChildQuery -> Maybe MaxChildren
hasChildMaxChildren     :: Maybe MaxChildren
  } deriving (HasChildQuery -> HasChildQuery -> Bool
(HasChildQuery -> HasChildQuery -> Bool)
-> (HasChildQuery -> HasChildQuery -> Bool) -> Eq HasChildQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HasChildQuery -> HasChildQuery -> Bool
$c/= :: HasChildQuery -> HasChildQuery -> Bool
== :: HasChildQuery -> HasChildQuery -> Bool
$c== :: HasChildQuery -> HasChildQuery -> Bool
Eq, Int -> HasChildQuery -> ShowS
[HasChildQuery] -> ShowS
HasChildQuery -> String
(Int -> HasChildQuery -> ShowS)
-> (HasChildQuery -> String)
-> ([HasChildQuery] -> ShowS)
-> Show HasChildQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HasChildQuery] -> ShowS
$cshowList :: [HasChildQuery] -> ShowS
show :: HasChildQuery -> String
$cshow :: HasChildQuery -> String
showsPrec :: Int -> HasChildQuery -> ShowS
$cshowsPrec :: Int -> HasChildQuery -> ShowS
Show)

instance ToJSON HasChildQuery where
  toJSON :: HasChildQuery -> Value
toJSON (HasChildQuery RelationName
queryType Query
query Maybe ScoreType
scoreType Maybe IgnoreUnmapped
ignoreUnmapped Maybe MinChildren
minChildren Maybe MaxChildren
maxChildren) =
    [Pair] -> Value
omitNulls [ Key
"query" Key -> Query -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Query
query
              , Key
"score_mode" Key -> Maybe ScoreType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe ScoreType
scoreType
              , Key
"type"  Key -> RelationName -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= RelationName
queryType
              , Key
"min_children" Key -> Maybe MinChildren -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe MinChildren
minChildren
              , Key
"max_children" Key -> Maybe MaxChildren -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe MaxChildren
maxChildren
              , Key
"ignore_unmapped" Key -> Maybe IgnoreUnmapped -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe IgnoreUnmapped
ignoreUnmapped
              ]

instance FromJSON HasChildQuery where
  parseJSON :: Value -> Parser HasChildQuery
parseJSON = String
-> (Object -> Parser HasChildQuery)
-> Value
-> Parser HasChildQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"HasChildQuery" Object -> Parser HasChildQuery
parse
    where parse :: Object -> Parser HasChildQuery
parse Object
o = RelationName
-> Query
-> Maybe ScoreType
-> Maybe IgnoreUnmapped
-> Maybe MinChildren
-> Maybe MaxChildren
-> HasChildQuery
HasChildQuery
                    (RelationName
 -> Query
 -> Maybe ScoreType
 -> Maybe IgnoreUnmapped
 -> Maybe MinChildren
 -> Maybe MaxChildren
 -> HasChildQuery)
-> Parser RelationName
-> Parser
     (Query
      -> Maybe ScoreType
      -> Maybe IgnoreUnmapped
      -> Maybe MinChildren
      -> Maybe MaxChildren
      -> HasChildQuery)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser RelationName
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type"
                    Parser
  (Query
   -> Maybe ScoreType
   -> Maybe IgnoreUnmapped
   -> Maybe MinChildren
   -> Maybe MaxChildren
   -> HasChildQuery)
-> Parser Query
-> Parser
     (Maybe ScoreType
      -> Maybe IgnoreUnmapped
      -> Maybe MinChildren
      -> Maybe MaxChildren
      -> HasChildQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Query
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"query"
                    Parser
  (Maybe ScoreType
   -> Maybe IgnoreUnmapped
   -> Maybe MinChildren
   -> Maybe MaxChildren
   -> HasChildQuery)
-> Parser (Maybe ScoreType)
-> Parser
     (Maybe IgnoreUnmapped
      -> Maybe MinChildren -> Maybe MaxChildren -> HasChildQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe ScoreType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"score_mode"
                    Parser
  (Maybe IgnoreUnmapped
   -> Maybe MinChildren -> Maybe MaxChildren -> HasChildQuery)
-> Parser (Maybe IgnoreUnmapped)
-> Parser (Maybe MinChildren -> Maybe MaxChildren -> HasChildQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe IgnoreUnmapped)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"ignore_unmapped"
                    Parser (Maybe MinChildren -> Maybe MaxChildren -> HasChildQuery)
-> Parser (Maybe MinChildren)
-> Parser (Maybe MaxChildren -> HasChildQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe MinChildren)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"min_children"
                    Parser (Maybe MaxChildren -> HasChildQuery)
-> Parser (Maybe MaxChildren) -> Parser HasChildQuery
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe MaxChildren)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"max_children"

data ScoreType =
    ScoreTypeMax
  | ScoreTypeSum
  | ScoreTypeAvg
  | ScoreTypeNone deriving (ScoreType -> ScoreType -> Bool
(ScoreType -> ScoreType -> Bool)
-> (ScoreType -> ScoreType -> Bool) -> Eq ScoreType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ScoreType -> ScoreType -> Bool
$c/= :: ScoreType -> ScoreType -> Bool
== :: ScoreType -> ScoreType -> Bool
$c== :: ScoreType -> ScoreType -> Bool
Eq, Int -> ScoreType -> ShowS
[ScoreType] -> ShowS
ScoreType -> String
(Int -> ScoreType -> ShowS)
-> (ScoreType -> String)
-> ([ScoreType] -> ShowS)
-> Show ScoreType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ScoreType] -> ShowS
$cshowList :: [ScoreType] -> ShowS
show :: ScoreType -> String
$cshow :: ScoreType -> String
showsPrec :: Int -> ScoreType -> ShowS
$cshowsPrec :: Int -> ScoreType -> ShowS
Show)

instance ToJSON ScoreType where
  toJSON :: ScoreType -> Value
toJSON ScoreType
ScoreTypeMax  = Value
"max"
  toJSON ScoreType
ScoreTypeAvg  = Value
"avg"
  toJSON ScoreType
ScoreTypeSum  = Value
"sum"
  toJSON ScoreType
ScoreTypeNone = Value
"none"

instance FromJSON ScoreType where
  parseJSON :: Value -> Parser ScoreType
parseJSON = String -> (Text -> Parser ScoreType) -> Value -> Parser ScoreType
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"ScoreType" Text -> Parser ScoreType
forall a (f :: * -> *).
(Eq a, IsString a, MonadFail f, Show a) =>
a -> f ScoreType
parse
    where parse :: a -> f ScoreType
parse a
"max"  = ScoreType -> f ScoreType
forall (f :: * -> *) a. Applicative f => a -> f a
pure ScoreType
ScoreTypeMax
          parse a
"avg"  = ScoreType -> f ScoreType
forall (f :: * -> *) a. Applicative f => a -> f a
pure ScoreType
ScoreTypeAvg
          parse a
"sum"  = ScoreType -> f ScoreType
forall (f :: * -> *) a. Applicative f => a -> f a
pure ScoreType
ScoreTypeSum
          parse a
"none" = ScoreType -> f ScoreType
forall (f :: * -> *) a. Applicative f => a -> f a
pure ScoreType
ScoreTypeNone
          parse a
t      = String -> f ScoreType
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"Unexpected ScoreType: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> a -> String
forall a. Show a => a -> String
show a
t)

data FuzzyQuery =
  FuzzyQuery { FuzzyQuery -> FieldName
fuzzyQueryField         :: FieldName
             , FuzzyQuery -> Text
fuzzyQueryValue         :: Text
             , FuzzyQuery -> PrefixLength
fuzzyQueryPrefixLength  :: PrefixLength
             , FuzzyQuery -> MaxExpansions
fuzzyQueryMaxExpansions :: MaxExpansions
             , FuzzyQuery -> Fuzziness
fuzzyQueryFuzziness     :: Fuzziness
             , FuzzyQuery -> Maybe Boost
fuzzyQueryBoost         :: Maybe Boost
             } deriving (FuzzyQuery -> FuzzyQuery -> Bool
(FuzzyQuery -> FuzzyQuery -> Bool)
-> (FuzzyQuery -> FuzzyQuery -> Bool) -> Eq FuzzyQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FuzzyQuery -> FuzzyQuery -> Bool
$c/= :: FuzzyQuery -> FuzzyQuery -> Bool
== :: FuzzyQuery -> FuzzyQuery -> Bool
$c== :: FuzzyQuery -> FuzzyQuery -> Bool
Eq, Int -> FuzzyQuery -> ShowS
[FuzzyQuery] -> ShowS
FuzzyQuery -> String
(Int -> FuzzyQuery -> ShowS)
-> (FuzzyQuery -> String)
-> ([FuzzyQuery] -> ShowS)
-> Show FuzzyQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FuzzyQuery] -> ShowS
$cshowList :: [FuzzyQuery] -> ShowS
show :: FuzzyQuery -> String
$cshow :: FuzzyQuery -> String
showsPrec :: Int -> FuzzyQuery -> ShowS
$cshowsPrec :: Int -> FuzzyQuery -> ShowS
Show)


instance ToJSON FuzzyQuery where
  toJSON :: FuzzyQuery -> Value
toJSON (FuzzyQuery (FieldName Text
fieldName) Text
queryText
          PrefixLength
prefixLength MaxExpansions
maxEx Fuzziness
fuzziness Maybe Boost
boost) =
    [Pair] -> Value
object [ Text -> Key
fromText Text
fieldName Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Pair] -> Value
omitNulls [Pair]
base ]
    where base :: [Pair]
base = [ Key
"value"          Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
queryText
                 , Key
"fuzziness"      Key -> Fuzziness -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Fuzziness
fuzziness
                 , Key
"prefix_length"  Key -> PrefixLength -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= PrefixLength
prefixLength
                 , Key
"boost" Key -> Maybe Boost -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Boost
boost
                 , Key
"max_expansions" Key -> MaxExpansions -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= MaxExpansions
maxEx ]

instance FromJSON FuzzyQuery where
  parseJSON :: Value -> Parser FuzzyQuery
parseJSON = String
-> (Object -> Parser FuzzyQuery) -> Value -> Parser FuzzyQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"FuzzyQuery" Object -> Parser FuzzyQuery
parse
    where parse :: Object -> Parser FuzzyQuery
parse = (FieldName -> Object -> Parser FuzzyQuery)
-> Object -> Parser FuzzyQuery
forall (m :: * -> *) a.
(Monad m, MonadFail m) =>
(FieldName -> Object -> m a) -> Object -> m a
fieldTagged ((FieldName -> Object -> Parser FuzzyQuery)
 -> Object -> Parser FuzzyQuery)
-> (FieldName -> Object -> Parser FuzzyQuery)
-> Object
-> Parser FuzzyQuery
forall a b. (a -> b) -> a -> b
$ \FieldName
fn Object
o ->
                    FieldName
-> Text
-> PrefixLength
-> MaxExpansions
-> Fuzziness
-> Maybe Boost
-> FuzzyQuery
FuzzyQuery FieldName
fn
                    (Text
 -> PrefixLength
 -> MaxExpansions
 -> Fuzziness
 -> Maybe Boost
 -> FuzzyQuery)
-> Parser Text
-> Parser
     (PrefixLength
      -> MaxExpansions -> Fuzziness -> Maybe Boost -> FuzzyQuery)
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
"value"
                    Parser
  (PrefixLength
   -> MaxExpansions -> Fuzziness -> Maybe Boost -> FuzzyQuery)
-> Parser PrefixLength
-> Parser (MaxExpansions -> Fuzziness -> Maybe Boost -> FuzzyQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser PrefixLength
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"prefix_length"
                    Parser (MaxExpansions -> Fuzziness -> Maybe Boost -> FuzzyQuery)
-> Parser MaxExpansions
-> Parser (Fuzziness -> Maybe Boost -> FuzzyQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser MaxExpansions
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"max_expansions"
                    Parser (Fuzziness -> Maybe Boost -> FuzzyQuery)
-> Parser Fuzziness -> Parser (Maybe Boost -> FuzzyQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Fuzziness
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"fuzziness"
                    Parser (Maybe Boost -> FuzzyQuery)
-> Parser (Maybe Boost) -> Parser FuzzyQuery
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"

data FuzzyLikeFieldQuery =
  FuzzyLikeFieldQuery
  { FuzzyLikeFieldQuery -> FieldName
fuzzyLikeField                    :: FieldName
    -- anaphora is good for the soul.
  , FuzzyLikeFieldQuery -> Text
fuzzyLikeFieldText                :: Text
  , FuzzyLikeFieldQuery -> MaxQueryTerms
fuzzyLikeFieldMaxQueryTerms       :: MaxQueryTerms
  , FuzzyLikeFieldQuery -> IgnoreTermFrequency
fuzzyLikeFieldIgnoreTermFrequency :: IgnoreTermFrequency
  , FuzzyLikeFieldQuery -> Fuzziness
fuzzyLikeFieldFuzziness           :: Fuzziness
  , FuzzyLikeFieldQuery -> PrefixLength
fuzzyLikeFieldPrefixLength        :: PrefixLength
  , FuzzyLikeFieldQuery -> Boost
fuzzyLikeFieldBoost               :: Boost
  , FuzzyLikeFieldQuery -> Maybe Analyzer
fuzzyLikeFieldAnalyzer            :: Maybe Analyzer
  } deriving (FuzzyLikeFieldQuery -> FuzzyLikeFieldQuery -> Bool
(FuzzyLikeFieldQuery -> FuzzyLikeFieldQuery -> Bool)
-> (FuzzyLikeFieldQuery -> FuzzyLikeFieldQuery -> Bool)
-> Eq FuzzyLikeFieldQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FuzzyLikeFieldQuery -> FuzzyLikeFieldQuery -> Bool
$c/= :: FuzzyLikeFieldQuery -> FuzzyLikeFieldQuery -> Bool
== :: FuzzyLikeFieldQuery -> FuzzyLikeFieldQuery -> Bool
$c== :: FuzzyLikeFieldQuery -> FuzzyLikeFieldQuery -> Bool
Eq, Int -> FuzzyLikeFieldQuery -> ShowS
[FuzzyLikeFieldQuery] -> ShowS
FuzzyLikeFieldQuery -> String
(Int -> FuzzyLikeFieldQuery -> ShowS)
-> (FuzzyLikeFieldQuery -> String)
-> ([FuzzyLikeFieldQuery] -> ShowS)
-> Show FuzzyLikeFieldQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FuzzyLikeFieldQuery] -> ShowS
$cshowList :: [FuzzyLikeFieldQuery] -> ShowS
show :: FuzzyLikeFieldQuery -> String
$cshow :: FuzzyLikeFieldQuery -> String
showsPrec :: Int -> FuzzyLikeFieldQuery -> ShowS
$cshowsPrec :: Int -> FuzzyLikeFieldQuery -> ShowS
Show)


instance ToJSON FuzzyLikeFieldQuery where
  toJSON :: FuzzyLikeFieldQuery -> Value
toJSON (FuzzyLikeFieldQuery (FieldName Text
fieldName)
          Text
fieldText MaxQueryTerms
maxTerms IgnoreTermFrequency
ignoreFreq Fuzziness
fuzziness PrefixLength
prefixLength
          Boost
boost Maybe Analyzer
analyzer) =
    [Pair] -> Value
object [ Text -> Key
fromText Text
fieldName Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.=
             [Pair] -> Value
omitNulls [ Key
"like_text"       Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
fieldText
                       , Key
"max_query_terms" Key -> MaxQueryTerms -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= MaxQueryTerms
maxTerms
                       , Key
"ignore_tf"       Key -> IgnoreTermFrequency -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= IgnoreTermFrequency
ignoreFreq
                       , Key
"fuzziness"       Key -> Fuzziness -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Fuzziness
fuzziness
                       , Key
"prefix_length"   Key -> PrefixLength -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= PrefixLength
prefixLength
                       , Key
"analyzer" Key -> Maybe Analyzer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Analyzer
analyzer
                       , Key
"boost"           Key -> Boost -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Boost
boost ]]

instance FromJSON FuzzyLikeFieldQuery where
  parseJSON :: Value -> Parser FuzzyLikeFieldQuery
parseJSON = String
-> (Object -> Parser FuzzyLikeFieldQuery)
-> Value
-> Parser FuzzyLikeFieldQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"FuzzyLikeFieldQuery" Object -> Parser FuzzyLikeFieldQuery
parse
    where parse :: Object -> Parser FuzzyLikeFieldQuery
parse = (FieldName -> Object -> Parser FuzzyLikeFieldQuery)
-> Object -> Parser FuzzyLikeFieldQuery
forall (m :: * -> *) a.
(Monad m, MonadFail m) =>
(FieldName -> Object -> m a) -> Object -> m a
fieldTagged ((FieldName -> Object -> Parser FuzzyLikeFieldQuery)
 -> Object -> Parser FuzzyLikeFieldQuery)
-> (FieldName -> Object -> Parser FuzzyLikeFieldQuery)
-> Object
-> Parser FuzzyLikeFieldQuery
forall a b. (a -> b) -> a -> b
$ \FieldName
fn Object
o ->
                    FieldName
-> Text
-> MaxQueryTerms
-> IgnoreTermFrequency
-> Fuzziness
-> PrefixLength
-> Boost
-> Maybe Analyzer
-> FuzzyLikeFieldQuery
FuzzyLikeFieldQuery FieldName
fn
                    (Text
 -> MaxQueryTerms
 -> IgnoreTermFrequency
 -> Fuzziness
 -> PrefixLength
 -> Boost
 -> Maybe Analyzer
 -> FuzzyLikeFieldQuery)
-> Parser Text
-> Parser
     (MaxQueryTerms
      -> IgnoreTermFrequency
      -> Fuzziness
      -> PrefixLength
      -> Boost
      -> Maybe Analyzer
      -> FuzzyLikeFieldQuery)
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
  (MaxQueryTerms
   -> IgnoreTermFrequency
   -> Fuzziness
   -> PrefixLength
   -> Boost
   -> Maybe Analyzer
   -> FuzzyLikeFieldQuery)
-> Parser MaxQueryTerms
-> Parser
     (IgnoreTermFrequency
      -> Fuzziness
      -> PrefixLength
      -> Boost
      -> Maybe Analyzer
      -> FuzzyLikeFieldQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser MaxQueryTerms
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"max_query_terms"
                    Parser
  (IgnoreTermFrequency
   -> Fuzziness
   -> PrefixLength
   -> Boost
   -> Maybe Analyzer
   -> FuzzyLikeFieldQuery)
-> Parser IgnoreTermFrequency
-> Parser
     (Fuzziness
      -> PrefixLength -> Boost -> Maybe Analyzer -> FuzzyLikeFieldQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser IgnoreTermFrequency
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"ignore_tf"
                    Parser
  (Fuzziness
   -> PrefixLength -> Boost -> Maybe Analyzer -> FuzzyLikeFieldQuery)
-> Parser Fuzziness
-> Parser
     (PrefixLength -> Boost -> Maybe Analyzer -> FuzzyLikeFieldQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Fuzziness
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"fuzziness"
                    Parser
  (PrefixLength -> Boost -> Maybe Analyzer -> FuzzyLikeFieldQuery)
-> Parser PrefixLength
-> Parser (Boost -> Maybe Analyzer -> FuzzyLikeFieldQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser PrefixLength
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"prefix_length"
                    Parser (Boost -> Maybe Analyzer -> FuzzyLikeFieldQuery)
-> Parser Boost -> Parser (Maybe Analyzer -> FuzzyLikeFieldQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Boost
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"boost"
                    Parser (Maybe Analyzer -> FuzzyLikeFieldQuery)
-> Parser (Maybe Analyzer) -> Parser FuzzyLikeFieldQuery
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"

data FuzzyLikeThisQuery =
  FuzzyLikeThisQuery
  { FuzzyLikeThisQuery -> [FieldName]
fuzzyLikeFields              :: [FieldName]
  , FuzzyLikeThisQuery -> Text
fuzzyLikeText                :: Text
  , FuzzyLikeThisQuery -> MaxQueryTerms
fuzzyLikeMaxQueryTerms       :: MaxQueryTerms
  , FuzzyLikeThisQuery -> IgnoreTermFrequency
fuzzyLikeIgnoreTermFrequency :: IgnoreTermFrequency
  , FuzzyLikeThisQuery -> Fuzziness
fuzzyLikeFuzziness           :: Fuzziness
  , FuzzyLikeThisQuery -> PrefixLength
fuzzyLikePrefixLength        :: PrefixLength
  , FuzzyLikeThisQuery -> Boost
fuzzyLikeBoost               :: Boost
  , FuzzyLikeThisQuery -> Maybe Analyzer
fuzzyLikeAnalyzer            :: Maybe Analyzer
  } deriving (FuzzyLikeThisQuery -> FuzzyLikeThisQuery -> Bool
(FuzzyLikeThisQuery -> FuzzyLikeThisQuery -> Bool)
-> (FuzzyLikeThisQuery -> FuzzyLikeThisQuery -> Bool)
-> Eq FuzzyLikeThisQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FuzzyLikeThisQuery -> FuzzyLikeThisQuery -> Bool
$c/= :: FuzzyLikeThisQuery -> FuzzyLikeThisQuery -> Bool
== :: FuzzyLikeThisQuery -> FuzzyLikeThisQuery -> Bool
$c== :: FuzzyLikeThisQuery -> FuzzyLikeThisQuery -> Bool
Eq, Int -> FuzzyLikeThisQuery -> ShowS
[FuzzyLikeThisQuery] -> ShowS
FuzzyLikeThisQuery -> String
(Int -> FuzzyLikeThisQuery -> ShowS)
-> (FuzzyLikeThisQuery -> String)
-> ([FuzzyLikeThisQuery] -> ShowS)
-> Show FuzzyLikeThisQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FuzzyLikeThisQuery] -> ShowS
$cshowList :: [FuzzyLikeThisQuery] -> ShowS
show :: FuzzyLikeThisQuery -> String
$cshow :: FuzzyLikeThisQuery -> String
showsPrec :: Int -> FuzzyLikeThisQuery -> ShowS
$cshowsPrec :: Int -> FuzzyLikeThisQuery -> ShowS
Show)


instance ToJSON FuzzyLikeThisQuery where
  toJSON :: FuzzyLikeThisQuery -> Value
toJSON (FuzzyLikeThisQuery [FieldName]
fields Text
text MaxQueryTerms
maxTerms
          IgnoreTermFrequency
ignoreFreq Fuzziness
fuzziness PrefixLength
prefixLength Boost
boost Maybe Analyzer
analyzer) =
    [Pair] -> Value
omitNulls [Pair]
base
    where base :: [Pair]
base = [ Key
"fields"          Key -> [FieldName] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [FieldName]
fields
                 , Key
"like_text"       Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
text
                 , Key
"max_query_terms" Key -> MaxQueryTerms -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= MaxQueryTerms
maxTerms
                 , Key
"ignore_tf"       Key -> IgnoreTermFrequency -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= IgnoreTermFrequency
ignoreFreq
                 , Key
"fuzziness"       Key -> Fuzziness -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Fuzziness
fuzziness
                 , Key
"prefix_length"   Key -> PrefixLength -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= PrefixLength
prefixLength
                 , Key
"analyzer"        Key -> Maybe Analyzer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Analyzer
analyzer
                 , Key
"boost"           Key -> Boost -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Boost
boost ]

instance FromJSON FuzzyLikeThisQuery where
  parseJSON :: Value -> Parser FuzzyLikeThisQuery
parseJSON = String
-> (Object -> Parser FuzzyLikeThisQuery)
-> Value
-> Parser FuzzyLikeThisQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"FuzzyLikeThisQuery" Object -> Parser FuzzyLikeThisQuery
parse
    where parse :: Object -> Parser FuzzyLikeThisQuery
parse Object
o = [FieldName]
-> Text
-> MaxQueryTerms
-> IgnoreTermFrequency
-> Fuzziness
-> PrefixLength
-> Boost
-> Maybe Analyzer
-> FuzzyLikeThisQuery
FuzzyLikeThisQuery
                    ([FieldName]
 -> Text
 -> MaxQueryTerms
 -> IgnoreTermFrequency
 -> Fuzziness
 -> PrefixLength
 -> Boost
 -> Maybe Analyzer
 -> FuzzyLikeThisQuery)
-> Parser [FieldName]
-> Parser
     (Text
      -> MaxQueryTerms
      -> IgnoreTermFrequency
      -> Fuzziness
      -> PrefixLength
      -> Boost
      -> Maybe Analyzer
      -> FuzzyLikeThisQuery)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe [FieldName])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"fields" Parser (Maybe [FieldName]) -> [FieldName] -> Parser [FieldName]
forall a. Parser (Maybe a) -> a -> Parser a
.!= []
                    Parser
  (Text
   -> MaxQueryTerms
   -> IgnoreTermFrequency
   -> Fuzziness
   -> PrefixLength
   -> Boost
   -> Maybe Analyzer
   -> FuzzyLikeThisQuery)
-> Parser Text
-> Parser
     (MaxQueryTerms
      -> IgnoreTermFrequency
      -> Fuzziness
      -> PrefixLength
      -> Boost
      -> Maybe Analyzer
      -> FuzzyLikeThisQuery)
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
"like_text"
                    Parser
  (MaxQueryTerms
   -> IgnoreTermFrequency
   -> Fuzziness
   -> PrefixLength
   -> Boost
   -> Maybe Analyzer
   -> FuzzyLikeThisQuery)
-> Parser MaxQueryTerms
-> Parser
     (IgnoreTermFrequency
      -> Fuzziness
      -> PrefixLength
      -> Boost
      -> Maybe Analyzer
      -> FuzzyLikeThisQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser MaxQueryTerms
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"max_query_terms"
                    Parser
  (IgnoreTermFrequency
   -> Fuzziness
   -> PrefixLength
   -> Boost
   -> Maybe Analyzer
   -> FuzzyLikeThisQuery)
-> Parser IgnoreTermFrequency
-> Parser
     (Fuzziness
      -> PrefixLength -> Boost -> Maybe Analyzer -> FuzzyLikeThisQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser IgnoreTermFrequency
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"ignore_tf"
                    Parser
  (Fuzziness
   -> PrefixLength -> Boost -> Maybe Analyzer -> FuzzyLikeThisQuery)
-> Parser Fuzziness
-> Parser
     (PrefixLength -> Boost -> Maybe Analyzer -> FuzzyLikeThisQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Fuzziness
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"fuzziness"
                    Parser
  (PrefixLength -> Boost -> Maybe Analyzer -> FuzzyLikeThisQuery)
-> Parser PrefixLength
-> Parser (Boost -> Maybe Analyzer -> FuzzyLikeThisQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser PrefixLength
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"prefix_length"
                    Parser (Boost -> Maybe Analyzer -> FuzzyLikeThisQuery)
-> Parser Boost -> Parser (Maybe Analyzer -> FuzzyLikeThisQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Boost
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"boost"
                    Parser (Maybe Analyzer -> FuzzyLikeThisQuery)
-> Parser (Maybe Analyzer) -> Parser FuzzyLikeThisQuery
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"

data DisMaxQuery =
  DisMaxQuery { DisMaxQuery -> [Query]
disMaxQueries    :: [Query]
                -- default 0.0
              , DisMaxQuery -> Tiebreaker
disMaxTiebreaker :: Tiebreaker
              , DisMaxQuery -> Maybe Boost
disMaxBoost      :: Maybe Boost
              } deriving (DisMaxQuery -> DisMaxQuery -> Bool
(DisMaxQuery -> DisMaxQuery -> Bool)
-> (DisMaxQuery -> DisMaxQuery -> Bool) -> Eq DisMaxQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DisMaxQuery -> DisMaxQuery -> Bool
$c/= :: DisMaxQuery -> DisMaxQuery -> Bool
== :: DisMaxQuery -> DisMaxQuery -> Bool
$c== :: DisMaxQuery -> DisMaxQuery -> Bool
Eq, Int -> DisMaxQuery -> ShowS
[DisMaxQuery] -> ShowS
DisMaxQuery -> String
(Int -> DisMaxQuery -> ShowS)
-> (DisMaxQuery -> String)
-> ([DisMaxQuery] -> ShowS)
-> Show DisMaxQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DisMaxQuery] -> ShowS
$cshowList :: [DisMaxQuery] -> ShowS
show :: DisMaxQuery -> String
$cshow :: DisMaxQuery -> String
showsPrec :: Int -> DisMaxQuery -> ShowS
$cshowsPrec :: Int -> DisMaxQuery -> ShowS
Show)


instance ToJSON DisMaxQuery where
  toJSON :: DisMaxQuery -> Value
toJSON (DisMaxQuery [Query]
queries Tiebreaker
tiebreaker Maybe Boost
boost) =
    [Pair] -> Value
omitNulls [Pair]
base
    where base :: [Pair]
base = [ Key
"queries"     Key -> [Query] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Query]
queries
                 , Key
"boost"       Key -> Maybe Boost -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Boost
boost
                 , Key
"tie_breaker" Key -> Tiebreaker -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Tiebreaker
tiebreaker ]

instance FromJSON DisMaxQuery where
  parseJSON :: Value -> Parser DisMaxQuery
parseJSON = String
-> (Object -> Parser DisMaxQuery) -> Value -> Parser DisMaxQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"DisMaxQuery" Object -> Parser DisMaxQuery
parse
    where parse :: Object -> Parser DisMaxQuery
parse Object
o = [Query] -> Tiebreaker -> Maybe Boost -> DisMaxQuery
DisMaxQuery
                    ([Query] -> Tiebreaker -> Maybe Boost -> DisMaxQuery)
-> Parser [Query]
-> Parser (Tiebreaker -> Maybe Boost -> DisMaxQuery)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe [Query])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"queries" Parser (Maybe [Query]) -> [Query] -> Parser [Query]
forall a. Parser (Maybe a) -> a -> Parser a
.!= []
                    Parser (Tiebreaker -> Maybe Boost -> DisMaxQuery)
-> Parser Tiebreaker -> Parser (Maybe Boost -> DisMaxQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Tiebreaker
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"tie_breaker"
                    Parser (Maybe Boost -> DisMaxQuery)
-> Parser (Maybe Boost) -> Parser DisMaxQuery
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"

data MatchQuery = MatchQuery
  { MatchQuery -> FieldName
matchQueryField              :: FieldName
  , MatchQuery -> QueryString
matchQueryQueryString        :: QueryString
  , MatchQuery -> BooleanOperator
matchQueryOperator           :: BooleanOperator
  , MatchQuery -> ZeroTermsQuery
matchQueryZeroTerms          :: ZeroTermsQuery
  , MatchQuery -> Maybe CutoffFrequency
matchQueryCutoffFrequency    :: Maybe CutoffFrequency
  , MatchQuery -> Maybe MatchQueryType
matchQueryMatchType          :: Maybe MatchQueryType
  , MatchQuery -> Maybe Analyzer
matchQueryAnalyzer           :: Maybe Analyzer
  , MatchQuery -> Maybe MaxExpansions
matchQueryMaxExpansions      :: Maybe MaxExpansions
  , MatchQuery -> Maybe Lenient
matchQueryLenient            :: Maybe Lenient
  , MatchQuery -> Maybe Boost
matchQueryBoost              :: Maybe Boost
  , MatchQuery -> Maybe Text
matchQueryMinimumShouldMatch :: Maybe Text
  , MatchQuery -> Maybe Fuzziness
matchQueryFuzziness          :: Maybe Fuzziness
  } deriving (MatchQuery -> MatchQuery -> Bool
(MatchQuery -> MatchQuery -> Bool)
-> (MatchQuery -> MatchQuery -> Bool) -> Eq MatchQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MatchQuery -> MatchQuery -> Bool
$c/= :: MatchQuery -> MatchQuery -> Bool
== :: MatchQuery -> MatchQuery -> Bool
$c== :: MatchQuery -> MatchQuery -> Bool
Eq, Int -> MatchQuery -> ShowS
[MatchQuery] -> ShowS
MatchQuery -> String
(Int -> MatchQuery -> ShowS)
-> (MatchQuery -> String)
-> ([MatchQuery] -> ShowS)
-> Show MatchQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MatchQuery] -> ShowS
$cshowList :: [MatchQuery] -> ShowS
show :: MatchQuery -> String
$cshow :: MatchQuery -> String
showsPrec :: Int -> MatchQuery -> ShowS
$cshowsPrec :: Int -> MatchQuery -> ShowS
Show)


instance ToJSON MatchQuery where
  toJSON :: MatchQuery -> Value
toJSON (MatchQuery (FieldName Text
fieldName)
          (QueryString Text
mqQueryString) BooleanOperator
booleanOperator
          ZeroTermsQuery
zeroTermsQuery Maybe CutoffFrequency
cutoffFrequency Maybe MatchQueryType
matchQueryType
          Maybe Analyzer
analyzer Maybe MaxExpansions
maxExpansions Maybe Lenient
lenient Maybe Boost
boost
          Maybe Text
minShouldMatch Maybe Fuzziness
mqFuzziness
         ) =
    [Pair] -> Value
object [ Text -> Key
fromText Text
fieldName Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Pair] -> Value
omitNulls [Pair]
base ]
    where base :: [Pair]
base = [ Key
"query" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
mqQueryString
                 , Key
"operator" Key -> BooleanOperator -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= BooleanOperator
booleanOperator
                 , Key
"zero_terms_query" Key -> ZeroTermsQuery -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= ZeroTermsQuery
zeroTermsQuery
                 , Key
"cutoff_frequency" Key -> Maybe CutoffFrequency -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe CutoffFrequency
cutoffFrequency
                 , Key
"type" Key -> Maybe MatchQueryType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe MatchQueryType
matchQueryType
                 , Key
"analyzer" Key -> Maybe Analyzer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Analyzer
analyzer
                 , Key
"max_expansions" Key -> Maybe MaxExpansions -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe MaxExpansions
maxExpansions
                 , Key
"lenient" Key -> Maybe Lenient -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Lenient
lenient
                 , Key
"boost" Key -> Maybe Boost -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Boost
boost
                 , Key
"minimum_should_match" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Text
minShouldMatch
                 , Key
"fuzziness" Key -> Maybe Fuzziness -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Fuzziness
mqFuzziness
                 ]

instance FromJSON MatchQuery where
  parseJSON :: Value -> Parser MatchQuery
parseJSON = String
-> (Object -> Parser MatchQuery) -> Value -> Parser MatchQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"MatchQuery" Object -> Parser MatchQuery
parse
    where parse :: Object -> Parser MatchQuery
parse = (FieldName -> Object -> Parser MatchQuery)
-> Object -> Parser MatchQuery
forall (m :: * -> *) a.
(Monad m, MonadFail m) =>
(FieldName -> Object -> m a) -> Object -> m a
fieldTagged ((FieldName -> Object -> Parser MatchQuery)
 -> Object -> Parser MatchQuery)
-> (FieldName -> Object -> Parser MatchQuery)
-> Object
-> Parser MatchQuery
forall a b. (a -> b) -> a -> b
$ \FieldName
fn Object
o ->
                    FieldName
-> QueryString
-> BooleanOperator
-> ZeroTermsQuery
-> Maybe CutoffFrequency
-> Maybe MatchQueryType
-> Maybe Analyzer
-> Maybe MaxExpansions
-> Maybe Lenient
-> Maybe Boost
-> Maybe Text
-> Maybe Fuzziness
-> MatchQuery
MatchQuery FieldName
fn
                    (QueryString
 -> BooleanOperator
 -> ZeroTermsQuery
 -> Maybe CutoffFrequency
 -> Maybe MatchQueryType
 -> Maybe Analyzer
 -> Maybe MaxExpansions
 -> Maybe Lenient
 -> Maybe Boost
 -> Maybe Text
 -> Maybe Fuzziness
 -> MatchQuery)
-> Parser QueryString
-> Parser
     (BooleanOperator
      -> ZeroTermsQuery
      -> Maybe CutoffFrequency
      -> Maybe MatchQueryType
      -> Maybe Analyzer
      -> Maybe MaxExpansions
      -> Maybe Lenient
      -> Maybe Boost
      -> Maybe Text
      -> Maybe Fuzziness
      -> MatchQuery)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser QueryString
forall a. FromJSON a => Object -> Key -> Parser a
.:  Key
"query"
                    Parser
  (BooleanOperator
   -> ZeroTermsQuery
   -> Maybe CutoffFrequency
   -> Maybe MatchQueryType
   -> Maybe Analyzer
   -> Maybe MaxExpansions
   -> Maybe Lenient
   -> Maybe Boost
   -> Maybe Text
   -> Maybe Fuzziness
   -> MatchQuery)
-> Parser BooleanOperator
-> Parser
     (ZeroTermsQuery
      -> Maybe CutoffFrequency
      -> Maybe MatchQueryType
      -> Maybe Analyzer
      -> Maybe MaxExpansions
      -> Maybe Lenient
      -> Maybe Boost
      -> Maybe Text
      -> Maybe Fuzziness
      -> MatchQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser BooleanOperator
forall a. FromJSON a => Object -> Key -> Parser a
.:  Key
"operator"
                    Parser
  (ZeroTermsQuery
   -> Maybe CutoffFrequency
   -> Maybe MatchQueryType
   -> Maybe Analyzer
   -> Maybe MaxExpansions
   -> Maybe Lenient
   -> Maybe Boost
   -> Maybe Text
   -> Maybe Fuzziness
   -> MatchQuery)
-> Parser ZeroTermsQuery
-> Parser
     (Maybe CutoffFrequency
      -> Maybe MatchQueryType
      -> Maybe Analyzer
      -> Maybe MaxExpansions
      -> Maybe Lenient
      -> Maybe Boost
      -> Maybe Text
      -> Maybe Fuzziness
      -> MatchQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser ZeroTermsQuery
forall a. FromJSON a => Object -> Key -> Parser a
.:  Key
"zero_terms_query"
                    Parser
  (Maybe CutoffFrequency
   -> Maybe MatchQueryType
   -> Maybe Analyzer
   -> Maybe MaxExpansions
   -> Maybe Lenient
   -> Maybe Boost
   -> Maybe Text
   -> Maybe Fuzziness
   -> MatchQuery)
-> Parser (Maybe CutoffFrequency)
-> Parser
     (Maybe MatchQueryType
      -> Maybe Analyzer
      -> Maybe MaxExpansions
      -> Maybe Lenient
      -> Maybe Boost
      -> Maybe Text
      -> Maybe Fuzziness
      -> MatchQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe CutoffFrequency)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"cutoff_frequency"
                    Parser
  (Maybe MatchQueryType
   -> Maybe Analyzer
   -> Maybe MaxExpansions
   -> Maybe Lenient
   -> Maybe Boost
   -> Maybe Text
   -> Maybe Fuzziness
   -> MatchQuery)
-> Parser (Maybe MatchQueryType)
-> Parser
     (Maybe Analyzer
      -> Maybe MaxExpansions
      -> Maybe Lenient
      -> Maybe Boost
      -> Maybe Text
      -> Maybe Fuzziness
      -> MatchQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe MatchQueryType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"type"
                    Parser
  (Maybe Analyzer
   -> Maybe MaxExpansions
   -> Maybe Lenient
   -> Maybe Boost
   -> Maybe Text
   -> Maybe Fuzziness
   -> MatchQuery)
-> Parser (Maybe Analyzer)
-> Parser
     (Maybe MaxExpansions
      -> Maybe Lenient
      -> Maybe Boost
      -> Maybe Text
      -> Maybe Fuzziness
      -> MatchQuery)
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 MaxExpansions
   -> Maybe Lenient
   -> Maybe Boost
   -> Maybe Text
   -> Maybe Fuzziness
   -> MatchQuery)
-> Parser (Maybe MaxExpansions)
-> Parser
     (Maybe Lenient
      -> Maybe Boost -> Maybe Text -> Maybe Fuzziness -> MatchQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe MaxExpansions)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"max_expansions"
                    Parser
  (Maybe Lenient
   -> Maybe Boost -> Maybe Text -> Maybe Fuzziness -> MatchQuery)
-> Parser (Maybe Lenient)
-> Parser
     (Maybe Boost -> Maybe Text -> Maybe Fuzziness -> MatchQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Lenient)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"lenient"
                    Parser (Maybe Boost -> Maybe Text -> Maybe Fuzziness -> MatchQuery)
-> Parser (Maybe Boost)
-> Parser (Maybe Text -> Maybe Fuzziness -> MatchQuery)
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 Text -> Maybe Fuzziness -> MatchQuery)
-> Parser (Maybe Text) -> Parser (Maybe Fuzziness -> MatchQuery)
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
"minimum_should_match"
                    Parser (Maybe Fuzziness -> MatchQuery)
-> Parser (Maybe Fuzziness) -> Parser MatchQuery
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Fuzziness)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"fuzziness"

{-| 'mkMatchQuery' is a convenience function that defaults the less common parameters,
    enabling you to provide only the 'FieldName' and 'QueryString' to make a 'MatchQuery'
-}
mkMatchQuery :: FieldName -> QueryString -> MatchQuery
mkMatchQuery :: FieldName -> QueryString -> MatchQuery
mkMatchQuery FieldName
field QueryString
query = FieldName
-> QueryString
-> BooleanOperator
-> ZeroTermsQuery
-> Maybe CutoffFrequency
-> Maybe MatchQueryType
-> Maybe Analyzer
-> Maybe MaxExpansions
-> Maybe Lenient
-> Maybe Boost
-> Maybe Text
-> Maybe Fuzziness
-> MatchQuery
MatchQuery FieldName
field QueryString
query BooleanOperator
Or ZeroTermsQuery
ZeroTermsNone Maybe CutoffFrequency
forall a. Maybe a
Nothing Maybe MatchQueryType
forall a. Maybe a
Nothing Maybe Analyzer
forall a. Maybe a
Nothing Maybe MaxExpansions
forall a. Maybe a
Nothing Maybe Lenient
forall a. Maybe a
Nothing Maybe Boost
forall a. Maybe a
Nothing Maybe Text
forall a. Maybe a
Nothing Maybe Fuzziness
forall a. Maybe a
Nothing

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

instance ToJSON MatchQueryType where
  toJSON :: MatchQueryType -> Value
toJSON MatchQueryType
MatchPhrase       = Value
"phrase"
  toJSON MatchQueryType
MatchPhrasePrefix = Value
"phrase_prefix"

instance FromJSON MatchQueryType where
  parseJSON :: Value -> Parser MatchQueryType
parseJSON = String
-> (Text -> Parser MatchQueryType)
-> Value
-> Parser MatchQueryType
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"MatchQueryType" Text -> Parser MatchQueryType
forall a (f :: * -> *).
(Eq a, IsString a, MonadFail f, Show a) =>
a -> f MatchQueryType
parse
    where parse :: a -> f MatchQueryType
parse a
"phrase"        = MatchQueryType -> f MatchQueryType
forall (f :: * -> *) a. Applicative f => a -> f a
pure MatchQueryType
MatchPhrase
          parse a
"phrase_prefix" = MatchQueryType -> f MatchQueryType
forall (f :: * -> *) a. Applicative f => a -> f a
pure MatchQueryType
MatchPhrasePrefix
          parse a
t               = String -> f MatchQueryType
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"Unexpected MatchQueryType: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> a -> String
forall a. Show a => a -> String
show a
t)

data MultiMatchQuery = MultiMatchQuery
  { MultiMatchQuery -> [FieldName]
multiMatchQueryFields          :: [FieldName]
  , MultiMatchQuery -> QueryString
multiMatchQueryString          :: QueryString
  , MultiMatchQuery -> BooleanOperator
multiMatchQueryOperator        :: BooleanOperator
  , MultiMatchQuery -> ZeroTermsQuery
multiMatchQueryZeroTerms       :: ZeroTermsQuery
  , MultiMatchQuery -> Maybe Tiebreaker
multiMatchQueryTiebreaker      :: Maybe Tiebreaker
  , MultiMatchQuery -> Maybe MultiMatchQueryType
multiMatchQueryType            :: Maybe MultiMatchQueryType
  , MultiMatchQuery -> Maybe CutoffFrequency
multiMatchQueryCutoffFrequency :: Maybe CutoffFrequency
  , MultiMatchQuery -> Maybe Analyzer
multiMatchQueryAnalyzer        :: Maybe Analyzer
  , MultiMatchQuery -> Maybe MaxExpansions
multiMatchQueryMaxExpansions   :: Maybe MaxExpansions
  , MultiMatchQuery -> Maybe Lenient
multiMatchQueryLenient         :: Maybe Lenient
  } deriving (MultiMatchQuery -> MultiMatchQuery -> Bool
(MultiMatchQuery -> MultiMatchQuery -> Bool)
-> (MultiMatchQuery -> MultiMatchQuery -> Bool)
-> Eq MultiMatchQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MultiMatchQuery -> MultiMatchQuery -> Bool
$c/= :: MultiMatchQuery -> MultiMatchQuery -> Bool
== :: MultiMatchQuery -> MultiMatchQuery -> Bool
$c== :: MultiMatchQuery -> MultiMatchQuery -> Bool
Eq, Int -> MultiMatchQuery -> ShowS
[MultiMatchQuery] -> ShowS
MultiMatchQuery -> String
(Int -> MultiMatchQuery -> ShowS)
-> (MultiMatchQuery -> String)
-> ([MultiMatchQuery] -> ShowS)
-> Show MultiMatchQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MultiMatchQuery] -> ShowS
$cshowList :: [MultiMatchQuery] -> ShowS
show :: MultiMatchQuery -> String
$cshow :: MultiMatchQuery -> String
showsPrec :: Int -> MultiMatchQuery -> ShowS
$cshowsPrec :: Int -> MultiMatchQuery -> ShowS
Show)

instance ToJSON MultiMatchQuery where
  toJSON :: MultiMatchQuery -> Value
toJSON (MultiMatchQuery [FieldName]
fields (QueryString Text
query) BooleanOperator
boolOp
          ZeroTermsQuery
ztQ Maybe Tiebreaker
tb Maybe MultiMatchQueryType
mmqt Maybe CutoffFrequency
cf Maybe Analyzer
analyzer Maybe MaxExpansions
maxEx Maybe Lenient
lenient) =
    [Pair] -> Value
object [Key
"multi_match" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Pair] -> Value
omitNulls [Pair]
base]
    where base :: [Pair]
base = [ Key
"fields" Key -> [Value] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= (FieldName -> Value) -> [FieldName] -> [Value]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap FieldName -> Value
forall a. ToJSON a => a -> Value
toJSON [FieldName]
fields
                 , Key
"query" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
query
                 , Key
"operator" Key -> BooleanOperator -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= BooleanOperator
boolOp
                 , Key
"zero_terms_query" Key -> ZeroTermsQuery -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= ZeroTermsQuery
ztQ
                 , Key
"tie_breaker" Key -> Maybe Tiebreaker -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Tiebreaker
tb
                 , Key
"type" Key -> Maybe MultiMatchQueryType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe MultiMatchQueryType
mmqt
                 , Key
"cutoff_frequency" Key -> Maybe CutoffFrequency -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe CutoffFrequency
cf
                 , Key
"analyzer" Key -> Maybe Analyzer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Analyzer
analyzer
                 , Key
"max_expansions" Key -> Maybe MaxExpansions -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe MaxExpansions
maxEx
                 , Key
"lenient" Key -> Maybe Lenient -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Lenient
lenient ]

instance FromJSON MultiMatchQuery where
  parseJSON :: Value -> Parser MultiMatchQuery
parseJSON = String
-> (Object -> Parser MultiMatchQuery)
-> Value
-> Parser MultiMatchQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"MultiMatchQuery" Object -> Parser MultiMatchQuery
parse
    where parse :: Object -> Parser MultiMatchQuery
parse Object
raw = do Object
o <- Object
raw Object -> Key -> Parser Object
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"multi_match"
                         [FieldName]
-> QueryString
-> BooleanOperator
-> ZeroTermsQuery
-> Maybe Tiebreaker
-> Maybe MultiMatchQueryType
-> Maybe CutoffFrequency
-> Maybe Analyzer
-> Maybe MaxExpansions
-> Maybe Lenient
-> MultiMatchQuery
MultiMatchQuery
                           ([FieldName]
 -> QueryString
 -> BooleanOperator
 -> ZeroTermsQuery
 -> Maybe Tiebreaker
 -> Maybe MultiMatchQueryType
 -> Maybe CutoffFrequency
 -> Maybe Analyzer
 -> Maybe MaxExpansions
 -> Maybe Lenient
 -> MultiMatchQuery)
-> Parser [FieldName]
-> Parser
     (QueryString
      -> BooleanOperator
      -> ZeroTermsQuery
      -> Maybe Tiebreaker
      -> Maybe MultiMatchQueryType
      -> Maybe CutoffFrequency
      -> Maybe Analyzer
      -> Maybe MaxExpansions
      -> Maybe Lenient
      -> MultiMatchQuery)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe [FieldName])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"fields" Parser (Maybe [FieldName]) -> [FieldName] -> Parser [FieldName]
forall a. Parser (Maybe a) -> a -> Parser a
.!= []
                           Parser
  (QueryString
   -> BooleanOperator
   -> ZeroTermsQuery
   -> Maybe Tiebreaker
   -> Maybe MultiMatchQueryType
   -> Maybe CutoffFrequency
   -> Maybe Analyzer
   -> Maybe MaxExpansions
   -> Maybe Lenient
   -> MultiMatchQuery)
-> Parser QueryString
-> Parser
     (BooleanOperator
      -> ZeroTermsQuery
      -> Maybe Tiebreaker
      -> Maybe MultiMatchQueryType
      -> Maybe CutoffFrequency
      -> Maybe Analyzer
      -> Maybe MaxExpansions
      -> Maybe Lenient
      -> MultiMatchQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser QueryString
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"query"
                           Parser
  (BooleanOperator
   -> ZeroTermsQuery
   -> Maybe Tiebreaker
   -> Maybe MultiMatchQueryType
   -> Maybe CutoffFrequency
   -> Maybe Analyzer
   -> Maybe MaxExpansions
   -> Maybe Lenient
   -> MultiMatchQuery)
-> Parser BooleanOperator
-> Parser
     (ZeroTermsQuery
      -> Maybe Tiebreaker
      -> Maybe MultiMatchQueryType
      -> Maybe CutoffFrequency
      -> Maybe Analyzer
      -> Maybe MaxExpansions
      -> Maybe Lenient
      -> MultiMatchQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser BooleanOperator
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"operator"
                           Parser
  (ZeroTermsQuery
   -> Maybe Tiebreaker
   -> Maybe MultiMatchQueryType
   -> Maybe CutoffFrequency
   -> Maybe Analyzer
   -> Maybe MaxExpansions
   -> Maybe Lenient
   -> MultiMatchQuery)
-> Parser ZeroTermsQuery
-> Parser
     (Maybe Tiebreaker
      -> Maybe MultiMatchQueryType
      -> Maybe CutoffFrequency
      -> Maybe Analyzer
      -> Maybe MaxExpansions
      -> Maybe Lenient
      -> MultiMatchQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser ZeroTermsQuery
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"zero_terms_query"
                           Parser
  (Maybe Tiebreaker
   -> Maybe MultiMatchQueryType
   -> Maybe CutoffFrequency
   -> Maybe Analyzer
   -> Maybe MaxExpansions
   -> Maybe Lenient
   -> MultiMatchQuery)
-> Parser (Maybe Tiebreaker)
-> Parser
     (Maybe MultiMatchQueryType
      -> Maybe CutoffFrequency
      -> Maybe Analyzer
      -> Maybe MaxExpansions
      -> Maybe Lenient
      -> MultiMatchQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Tiebreaker)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"tie_breaker"
                           Parser
  (Maybe MultiMatchQueryType
   -> Maybe CutoffFrequency
   -> Maybe Analyzer
   -> Maybe MaxExpansions
   -> Maybe Lenient
   -> MultiMatchQuery)
-> Parser (Maybe MultiMatchQueryType)
-> Parser
     (Maybe CutoffFrequency
      -> Maybe Analyzer
      -> Maybe MaxExpansions
      -> Maybe Lenient
      -> MultiMatchQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe MultiMatchQueryType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"type"
                           Parser
  (Maybe CutoffFrequency
   -> Maybe Analyzer
   -> Maybe MaxExpansions
   -> Maybe Lenient
   -> MultiMatchQuery)
-> Parser (Maybe CutoffFrequency)
-> Parser
     (Maybe Analyzer
      -> Maybe MaxExpansions -> Maybe Lenient -> MultiMatchQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe CutoffFrequency)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"cutoff_frequency"
                           Parser
  (Maybe Analyzer
   -> Maybe MaxExpansions -> Maybe Lenient -> MultiMatchQuery)
-> Parser (Maybe Analyzer)
-> Parser (Maybe MaxExpansions -> Maybe Lenient -> MultiMatchQuery)
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 MaxExpansions -> Maybe Lenient -> MultiMatchQuery)
-> Parser (Maybe MaxExpansions)
-> Parser (Maybe Lenient -> MultiMatchQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe MaxExpansions)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"max_expansions"
                           Parser (Maybe Lenient -> MultiMatchQuery)
-> Parser (Maybe Lenient) -> Parser MultiMatchQuery
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Lenient)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"lenient"

{-| 'mkMultiMatchQuery' is a convenience function that defaults the less common parameters,
    enabling you to provide only the list of 'FieldName's and 'QueryString' to
    make a 'MultiMatchQuery'.
-}

mkMultiMatchQuery :: [FieldName] -> QueryString -> MultiMatchQuery
mkMultiMatchQuery :: [FieldName] -> QueryString -> MultiMatchQuery
mkMultiMatchQuery [FieldName]
matchFields QueryString
query =
  [FieldName]
-> QueryString
-> BooleanOperator
-> ZeroTermsQuery
-> Maybe Tiebreaker
-> Maybe MultiMatchQueryType
-> Maybe CutoffFrequency
-> Maybe Analyzer
-> Maybe MaxExpansions
-> Maybe Lenient
-> MultiMatchQuery
MultiMatchQuery [FieldName]
matchFields QueryString
query
  BooleanOperator
Or ZeroTermsQuery
ZeroTermsNone Maybe Tiebreaker
forall a. Maybe a
Nothing Maybe MultiMatchQueryType
forall a. Maybe a
Nothing Maybe CutoffFrequency
forall a. Maybe a
Nothing Maybe Analyzer
forall a. Maybe a
Nothing Maybe MaxExpansions
forall a. Maybe a
Nothing Maybe Lenient
forall a. Maybe a
Nothing

data MultiMatchQueryType =
    MultiMatchBestFields
  | MultiMatchMostFields
  | MultiMatchCrossFields
  | MultiMatchPhrase
  | MultiMatchPhrasePrefix deriving (MultiMatchQueryType -> MultiMatchQueryType -> Bool
(MultiMatchQueryType -> MultiMatchQueryType -> Bool)
-> (MultiMatchQueryType -> MultiMatchQueryType -> Bool)
-> Eq MultiMatchQueryType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MultiMatchQueryType -> MultiMatchQueryType -> Bool
$c/= :: MultiMatchQueryType -> MultiMatchQueryType -> Bool
== :: MultiMatchQueryType -> MultiMatchQueryType -> Bool
$c== :: MultiMatchQueryType -> MultiMatchQueryType -> Bool
Eq, Int -> MultiMatchQueryType -> ShowS
[MultiMatchQueryType] -> ShowS
MultiMatchQueryType -> String
(Int -> MultiMatchQueryType -> ShowS)
-> (MultiMatchQueryType -> String)
-> ([MultiMatchQueryType] -> ShowS)
-> Show MultiMatchQueryType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MultiMatchQueryType] -> ShowS
$cshowList :: [MultiMatchQueryType] -> ShowS
show :: MultiMatchQueryType -> String
$cshow :: MultiMatchQueryType -> String
showsPrec :: Int -> MultiMatchQueryType -> ShowS
$cshowsPrec :: Int -> MultiMatchQueryType -> ShowS
Show)

instance ToJSON MultiMatchQueryType where
  toJSON :: MultiMatchQueryType -> Value
toJSON MultiMatchQueryType
MultiMatchBestFields   = Value
"best_fields"
  toJSON MultiMatchQueryType
MultiMatchMostFields   = Value
"most_fields"
  toJSON MultiMatchQueryType
MultiMatchCrossFields  = Value
"cross_fields"
  toJSON MultiMatchQueryType
MultiMatchPhrase       = Value
"phrase"
  toJSON MultiMatchQueryType
MultiMatchPhrasePrefix = Value
"phrase_prefix"

instance FromJSON MultiMatchQueryType where
  parseJSON :: Value -> Parser MultiMatchQueryType
parseJSON = String
-> (Text -> Parser MultiMatchQueryType)
-> Value
-> Parser MultiMatchQueryType
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"MultiMatchPhrasePrefix" Text -> Parser MultiMatchQueryType
forall a (f :: * -> *).
(Eq a, IsString a, MonadFail f, Show a) =>
a -> f MultiMatchQueryType
parse
    where parse :: a -> f MultiMatchQueryType
parse a
"best_fields"   = MultiMatchQueryType -> f MultiMatchQueryType
forall (f :: * -> *) a. Applicative f => a -> f a
pure MultiMatchQueryType
MultiMatchBestFields
          parse a
"most_fields"   = MultiMatchQueryType -> f MultiMatchQueryType
forall (f :: * -> *) a. Applicative f => a -> f a
pure MultiMatchQueryType
MultiMatchMostFields
          parse a
"cross_fields"  = MultiMatchQueryType -> f MultiMatchQueryType
forall (f :: * -> *) a. Applicative f => a -> f a
pure MultiMatchQueryType
MultiMatchCrossFields
          parse a
"phrase"        = MultiMatchQueryType -> f MultiMatchQueryType
forall (f :: * -> *) a. Applicative f => a -> f a
pure MultiMatchQueryType
MultiMatchPhrase
          parse a
"phrase_prefix" = MultiMatchQueryType -> f MultiMatchQueryType
forall (f :: * -> *) a. Applicative f => a -> f a
pure MultiMatchQueryType
MultiMatchPhrasePrefix
          parse a
t = String -> f MultiMatchQueryType
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"Unexpected MultiMatchPhrasePrefix: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> a -> String
forall a. Show a => a -> String
show a
t)

data BoolQuery =
  BoolQuery { BoolQuery -> [Query]
boolQueryMustMatch          :: [Query]
            , BoolQuery -> [Filter]
boolQueryFilter             :: [Filter]
            , BoolQuery -> [Query]
boolQueryMustNotMatch       :: [Query]
            , BoolQuery -> [Query]
boolQueryShouldMatch        :: [Query]
            , BoolQuery -> Maybe MinimumMatch
boolQueryMinimumShouldMatch :: Maybe MinimumMatch
            , BoolQuery -> Maybe Boost
boolQueryBoost              :: Maybe Boost
            , BoolQuery -> Maybe DisableCoord
boolQueryDisableCoord       :: Maybe DisableCoord
            } deriving (BoolQuery -> BoolQuery -> Bool
(BoolQuery -> BoolQuery -> Bool)
-> (BoolQuery -> BoolQuery -> Bool) -> Eq BoolQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BoolQuery -> BoolQuery -> Bool
$c/= :: BoolQuery -> BoolQuery -> Bool
== :: BoolQuery -> BoolQuery -> Bool
$c== :: BoolQuery -> BoolQuery -> Bool
Eq, Int -> BoolQuery -> ShowS
[BoolQuery] -> ShowS
BoolQuery -> String
(Int -> BoolQuery -> ShowS)
-> (BoolQuery -> String)
-> ([BoolQuery] -> ShowS)
-> Show BoolQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BoolQuery] -> ShowS
$cshowList :: [BoolQuery] -> ShowS
show :: BoolQuery -> String
$cshow :: BoolQuery -> String
showsPrec :: Int -> BoolQuery -> ShowS
$cshowsPrec :: Int -> BoolQuery -> ShowS
Show)


instance ToJSON BoolQuery where
  toJSON :: BoolQuery -> Value
toJSON (BoolQuery [Query]
mustM [Filter]
filterM' [Query]
notM [Query]
shouldM Maybe MinimumMatch
bqMin Maybe Boost
boost Maybe DisableCoord
disableCoord) =
    [Pair] -> Value
omitNulls [Pair]
base
    where base :: [Pair]
base = [ Key
"must" Key -> [Query] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Query]
mustM
                 , Key
"filter" Key -> [Filter] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Filter]
filterM'
                 , Key
"must_not" Key -> [Query] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Query]
notM
                 , Key
"should" Key -> [Query] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Query]
shouldM
                 , Key
"minimum_should_match" Key -> Maybe MinimumMatch -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe MinimumMatch
bqMin
                 , Key
"boost" Key -> Maybe Boost -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Boost
boost
                 , Key
"disable_coord" Key -> Maybe DisableCoord -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe DisableCoord
disableCoord ]

instance FromJSON BoolQuery where
  parseJSON :: Value -> Parser BoolQuery
parseJSON = String -> (Object -> Parser BoolQuery) -> Value -> Parser BoolQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"BoolQuery" Object -> Parser BoolQuery
parse
    where parse :: Object -> Parser BoolQuery
parse Object
o = [Query]
-> [Filter]
-> [Query]
-> [Query]
-> Maybe MinimumMatch
-> Maybe Boost
-> Maybe DisableCoord
-> BoolQuery
BoolQuery
                    ([Query]
 -> [Filter]
 -> [Query]
 -> [Query]
 -> Maybe MinimumMatch
 -> Maybe Boost
 -> Maybe DisableCoord
 -> BoolQuery)
-> Parser [Query]
-> Parser
     ([Filter]
      -> [Query]
      -> [Query]
      -> Maybe MinimumMatch
      -> Maybe Boost
      -> Maybe DisableCoord
      -> BoolQuery)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe [Query])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"must" Parser (Maybe [Query]) -> [Query] -> Parser [Query]
forall a. Parser (Maybe a) -> a -> Parser a
.!= []
                    Parser
  ([Filter]
   -> [Query]
   -> [Query]
   -> Maybe MinimumMatch
   -> Maybe Boost
   -> Maybe DisableCoord
   -> BoolQuery)
-> Parser [Filter]
-> Parser
     ([Query]
      -> [Query]
      -> Maybe MinimumMatch
      -> Maybe Boost
      -> Maybe DisableCoord
      -> BoolQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe [Filter])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"filter" Parser (Maybe [Filter]) -> [Filter] -> Parser [Filter]
forall a. Parser (Maybe a) -> a -> Parser a
.!= []
                    Parser
  ([Query]
   -> [Query]
   -> Maybe MinimumMatch
   -> Maybe Boost
   -> Maybe DisableCoord
   -> BoolQuery)
-> Parser [Query]
-> Parser
     ([Query]
      -> Maybe MinimumMatch
      -> Maybe Boost
      -> Maybe DisableCoord
      -> BoolQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe [Query])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"must_not" Parser (Maybe [Query]) -> [Query] -> Parser [Query]
forall a. Parser (Maybe a) -> a -> Parser a
.!= []
                    Parser
  ([Query]
   -> Maybe MinimumMatch
   -> Maybe Boost
   -> Maybe DisableCoord
   -> BoolQuery)
-> Parser [Query]
-> Parser
     (Maybe MinimumMatch
      -> Maybe Boost -> Maybe DisableCoord -> BoolQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe [Query])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"should" Parser (Maybe [Query]) -> [Query] -> Parser [Query]
forall a. Parser (Maybe a) -> a -> Parser a
.!= []
                    Parser
  (Maybe MinimumMatch
   -> Maybe Boost -> Maybe DisableCoord -> BoolQuery)
-> Parser (Maybe MinimumMatch)
-> Parser (Maybe Boost -> Maybe DisableCoord -> BoolQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe MinimumMatch)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"minimum_should_match"
                    Parser (Maybe Boost -> Maybe DisableCoord -> BoolQuery)
-> Parser (Maybe Boost) -> Parser (Maybe DisableCoord -> BoolQuery)
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 DisableCoord -> BoolQuery)
-> Parser (Maybe DisableCoord) -> Parser BoolQuery
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe DisableCoord)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"disable_coord"

mkBoolQuery :: [Query] -> [Filter] -> [Query] -> [Query] -> BoolQuery
mkBoolQuery :: [Query] -> [Filter] -> [Query] -> [Query] -> BoolQuery
mkBoolQuery [Query]
must [Filter]
filt [Query]
mustNot [Query]
should =
  [Query]
-> [Filter]
-> [Query]
-> [Query]
-> Maybe MinimumMatch
-> Maybe Boost
-> Maybe DisableCoord
-> BoolQuery
BoolQuery [Query]
must [Filter]
filt [Query]
mustNot [Query]
should Maybe MinimumMatch
forall a. Maybe a
Nothing Maybe Boost
forall a. Maybe a
Nothing Maybe DisableCoord
forall a. Maybe a
Nothing

data BoostingQuery =
  BoostingQuery { BoostingQuery -> Query
positiveQuery :: Query
                , BoostingQuery -> Query
negativeQuery :: Query
                , BoostingQuery -> Boost
negativeBoost :: Boost } deriving (BoostingQuery -> BoostingQuery -> Bool
(BoostingQuery -> BoostingQuery -> Bool)
-> (BoostingQuery -> BoostingQuery -> Bool) -> Eq BoostingQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BoostingQuery -> BoostingQuery -> Bool
$c/= :: BoostingQuery -> BoostingQuery -> Bool
== :: BoostingQuery -> BoostingQuery -> Bool
$c== :: BoostingQuery -> BoostingQuery -> Bool
Eq, Int -> BoostingQuery -> ShowS
[BoostingQuery] -> ShowS
BoostingQuery -> String
(Int -> BoostingQuery -> ShowS)
-> (BoostingQuery -> String)
-> ([BoostingQuery] -> ShowS)
-> Show BoostingQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BoostingQuery] -> ShowS
$cshowList :: [BoostingQuery] -> ShowS
show :: BoostingQuery -> String
$cshow :: BoostingQuery -> String
showsPrec :: Int -> BoostingQuery -> ShowS
$cshowsPrec :: Int -> BoostingQuery -> ShowS
Show)

instance ToJSON BoostingQuery where
  toJSON :: BoostingQuery -> Value
toJSON (BoostingQuery Query
bqPositiveQuery Query
bqNegativeQuery Boost
bqNegativeBoost) =
    [Pair] -> Value
object [ Key
"positive"       Key -> Query -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Query
bqPositiveQuery
           , Key
"negative"       Key -> Query -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Query
bqNegativeQuery
           , Key
"negative_boost" Key -> Boost -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Boost
bqNegativeBoost ]

instance FromJSON BoostingQuery where
  parseJSON :: Value -> Parser BoostingQuery
parseJSON = String
-> (Object -> Parser BoostingQuery)
-> Value
-> Parser BoostingQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"BoostingQuery" Object -> Parser BoostingQuery
parse
    where parse :: Object -> Parser BoostingQuery
parse Object
o = Query -> Query -> Boost -> BoostingQuery
BoostingQuery
                    (Query -> Query -> Boost -> BoostingQuery)
-> Parser Query -> Parser (Query -> Boost -> BoostingQuery)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Query
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"positive"
                    Parser (Query -> Boost -> BoostingQuery)
-> Parser Query -> Parser (Boost -> BoostingQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Query
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"negative"
                    Parser (Boost -> BoostingQuery)
-> Parser Boost -> Parser BoostingQuery
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Boost
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"negative_boost"

data CommonTermsQuery =
  CommonTermsQuery { CommonTermsQuery -> FieldName
commonField              :: FieldName
                   , CommonTermsQuery -> QueryString
commonQuery              :: QueryString
                   , CommonTermsQuery -> CutoffFrequency
commonCutoffFrequency    :: CutoffFrequency
                   , CommonTermsQuery -> BooleanOperator
commonLowFreqOperator    :: BooleanOperator
                   , CommonTermsQuery -> BooleanOperator
commonHighFreqOperator   :: BooleanOperator
                   , CommonTermsQuery -> Maybe CommonMinimumMatch
commonMinimumShouldMatch :: Maybe CommonMinimumMatch
                   , CommonTermsQuery -> Maybe Boost
commonBoost              :: Maybe Boost
                   , CommonTermsQuery -> Maybe Analyzer
commonAnalyzer           :: Maybe Analyzer
                   , CommonTermsQuery -> Maybe DisableCoord
commonDisableCoord       :: Maybe DisableCoord
                   } deriving (CommonTermsQuery -> CommonTermsQuery -> Bool
(CommonTermsQuery -> CommonTermsQuery -> Bool)
-> (CommonTermsQuery -> CommonTermsQuery -> Bool)
-> Eq CommonTermsQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CommonTermsQuery -> CommonTermsQuery -> Bool
$c/= :: CommonTermsQuery -> CommonTermsQuery -> Bool
== :: CommonTermsQuery -> CommonTermsQuery -> Bool
$c== :: CommonTermsQuery -> CommonTermsQuery -> Bool
Eq, Int -> CommonTermsQuery -> ShowS
[CommonTermsQuery] -> ShowS
CommonTermsQuery -> String
(Int -> CommonTermsQuery -> ShowS)
-> (CommonTermsQuery -> String)
-> ([CommonTermsQuery] -> ShowS)
-> Show CommonTermsQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CommonTermsQuery] -> ShowS
$cshowList :: [CommonTermsQuery] -> ShowS
show :: CommonTermsQuery -> String
$cshow :: CommonTermsQuery -> String
showsPrec :: Int -> CommonTermsQuery -> ShowS
$cshowsPrec :: Int -> CommonTermsQuery -> ShowS
Show)


instance ToJSON CommonTermsQuery where
  toJSON :: CommonTermsQuery -> Value
toJSON (CommonTermsQuery (FieldName Text
fieldName)
          (QueryString Text
query) CutoffFrequency
cf BooleanOperator
lfo BooleanOperator
hfo Maybe CommonMinimumMatch
msm
          Maybe Boost
boost Maybe Analyzer
analyzer Maybe DisableCoord
disableCoord) =
    [Pair] -> Value
object [Text -> Key
fromText Text
fieldName Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Pair] -> Value
omitNulls [Pair]
base ]
    where base :: [Pair]
base = [ Key
"query"              Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
query
                 , Key
"cutoff_frequency"   Key -> CutoffFrequency -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= CutoffFrequency
cf
                 , Key
"low_freq_operator"  Key -> BooleanOperator -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= BooleanOperator
lfo
                 , Key
"minimum_should_match" Key -> Maybe CommonMinimumMatch -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe CommonMinimumMatch
msm
                 , Key
"boost" Key -> Maybe Boost -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Boost
boost
                 , Key
"analyzer" Key -> Maybe Analyzer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Analyzer
analyzer
                 , Key
"disable_coord" Key -> Maybe DisableCoord -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe DisableCoord
disableCoord
                 , Key
"high_freq_operator" Key -> BooleanOperator -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= BooleanOperator
hfo ]

instance FromJSON CommonTermsQuery where
  parseJSON :: Value -> Parser CommonTermsQuery
parseJSON = String
-> (Object -> Parser CommonTermsQuery)
-> Value
-> Parser CommonTermsQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"CommonTermsQuery" Object -> Parser CommonTermsQuery
parse
    where parse :: Object -> Parser CommonTermsQuery
parse = (FieldName -> Object -> Parser CommonTermsQuery)
-> Object -> Parser CommonTermsQuery
forall (m :: * -> *) a.
(Monad m, MonadFail m) =>
(FieldName -> Object -> m a) -> Object -> m a
fieldTagged ((FieldName -> Object -> Parser CommonTermsQuery)
 -> Object -> Parser CommonTermsQuery)
-> (FieldName -> Object -> Parser CommonTermsQuery)
-> Object
-> Parser CommonTermsQuery
forall a b. (a -> b) -> a -> b
$ \FieldName
fn Object
o ->
                    FieldName
-> QueryString
-> CutoffFrequency
-> BooleanOperator
-> BooleanOperator
-> Maybe CommonMinimumMatch
-> Maybe Boost
-> Maybe Analyzer
-> Maybe DisableCoord
-> CommonTermsQuery
CommonTermsQuery FieldName
fn
                    (QueryString
 -> CutoffFrequency
 -> BooleanOperator
 -> BooleanOperator
 -> Maybe CommonMinimumMatch
 -> Maybe Boost
 -> Maybe Analyzer
 -> Maybe DisableCoord
 -> CommonTermsQuery)
-> Parser QueryString
-> Parser
     (CutoffFrequency
      -> BooleanOperator
      -> BooleanOperator
      -> Maybe CommonMinimumMatch
      -> Maybe Boost
      -> Maybe Analyzer
      -> Maybe DisableCoord
      -> CommonTermsQuery)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser QueryString
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"query"
                    Parser
  (CutoffFrequency
   -> BooleanOperator
   -> BooleanOperator
   -> Maybe CommonMinimumMatch
   -> Maybe Boost
   -> Maybe Analyzer
   -> Maybe DisableCoord
   -> CommonTermsQuery)
-> Parser CutoffFrequency
-> Parser
     (BooleanOperator
      -> BooleanOperator
      -> Maybe CommonMinimumMatch
      -> Maybe Boost
      -> Maybe Analyzer
      -> Maybe DisableCoord
      -> CommonTermsQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser CutoffFrequency
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"cutoff_frequency"
                    Parser
  (BooleanOperator
   -> BooleanOperator
   -> Maybe CommonMinimumMatch
   -> Maybe Boost
   -> Maybe Analyzer
   -> Maybe DisableCoord
   -> CommonTermsQuery)
-> Parser BooleanOperator
-> Parser
     (BooleanOperator
      -> Maybe CommonMinimumMatch
      -> Maybe Boost
      -> Maybe Analyzer
      -> Maybe DisableCoord
      -> CommonTermsQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser BooleanOperator
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"low_freq_operator"
                    Parser
  (BooleanOperator
   -> Maybe CommonMinimumMatch
   -> Maybe Boost
   -> Maybe Analyzer
   -> Maybe DisableCoord
   -> CommonTermsQuery)
-> Parser BooleanOperator
-> Parser
     (Maybe CommonMinimumMatch
      -> Maybe Boost
      -> Maybe Analyzer
      -> Maybe DisableCoord
      -> CommonTermsQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser BooleanOperator
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"high_freq_operator"
                    Parser
  (Maybe CommonMinimumMatch
   -> Maybe Boost
   -> Maybe Analyzer
   -> Maybe DisableCoord
   -> CommonTermsQuery)
-> Parser (Maybe CommonMinimumMatch)
-> Parser
     (Maybe Boost
      -> Maybe Analyzer -> Maybe DisableCoord -> CommonTermsQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe CommonMinimumMatch)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"minimum_should_match"
                    Parser
  (Maybe Boost
   -> Maybe Analyzer -> Maybe DisableCoord -> CommonTermsQuery)
-> Parser (Maybe Boost)
-> Parser
     (Maybe Analyzer -> Maybe DisableCoord -> CommonTermsQuery)
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 -> Maybe DisableCoord -> CommonTermsQuery)
-> Parser (Maybe Analyzer)
-> Parser (Maybe DisableCoord -> CommonTermsQuery)
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 DisableCoord -> CommonTermsQuery)
-> Parser (Maybe DisableCoord) -> Parser CommonTermsQuery
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe DisableCoord)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"disable_coord"

data CommonMinimumMatch =
    CommonMinimumMatchHighLow MinimumMatchHighLow
  | CommonMinimumMatch        MinimumMatch
  deriving (CommonMinimumMatch -> CommonMinimumMatch -> Bool
(CommonMinimumMatch -> CommonMinimumMatch -> Bool)
-> (CommonMinimumMatch -> CommonMinimumMatch -> Bool)
-> Eq CommonMinimumMatch
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CommonMinimumMatch -> CommonMinimumMatch -> Bool
$c/= :: CommonMinimumMatch -> CommonMinimumMatch -> Bool
== :: CommonMinimumMatch -> CommonMinimumMatch -> Bool
$c== :: CommonMinimumMatch -> CommonMinimumMatch -> Bool
Eq, Int -> CommonMinimumMatch -> ShowS
[CommonMinimumMatch] -> ShowS
CommonMinimumMatch -> String
(Int -> CommonMinimumMatch -> ShowS)
-> (CommonMinimumMatch -> String)
-> ([CommonMinimumMatch] -> ShowS)
-> Show CommonMinimumMatch
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CommonMinimumMatch] -> ShowS
$cshowList :: [CommonMinimumMatch] -> ShowS
show :: CommonMinimumMatch -> String
$cshow :: CommonMinimumMatch -> String
showsPrec :: Int -> CommonMinimumMatch -> ShowS
$cshowsPrec :: Int -> CommonMinimumMatch -> ShowS
Show)


instance ToJSON CommonMinimumMatch where
  toJSON :: CommonMinimumMatch -> Value
toJSON (CommonMinimumMatch MinimumMatch
mm) = MinimumMatch -> Value
forall a. ToJSON a => a -> Value
toJSON MinimumMatch
mm
  toJSON (CommonMinimumMatchHighLow (MinimumMatchHighLow MinimumMatch
lowF MinimumMatch
highF)) =
    [Pair] -> Value
object [ Key
"low_freq"  Key -> MinimumMatch -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= MinimumMatch
lowF
           , Key
"high_freq" Key -> MinimumMatch -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= MinimumMatch
highF ]

instance FromJSON CommonMinimumMatch where
  parseJSON :: Value -> Parser CommonMinimumMatch
parseJSON Value
v = Value -> Parser CommonMinimumMatch
parseMinimum Value
v
            Parser CommonMinimumMatch
-> Parser CommonMinimumMatch -> Parser CommonMinimumMatch
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Value -> Parser CommonMinimumMatch
parseMinimumHighLow Value
v
    where parseMinimum :: Value -> Parser CommonMinimumMatch
parseMinimum = (MinimumMatch -> CommonMinimumMatch)
-> Parser MinimumMatch -> Parser CommonMinimumMatch
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MinimumMatch -> CommonMinimumMatch
CommonMinimumMatch (Parser MinimumMatch -> Parser CommonMinimumMatch)
-> (Value -> Parser MinimumMatch)
-> Value
-> Parser CommonMinimumMatch
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value -> Parser MinimumMatch
forall a. FromJSON a => Value -> Parser a
parseJSON
          parseMinimumHighLow :: Value -> Parser CommonMinimumMatch
parseMinimumHighLow = (MinimumMatchHighLow -> CommonMinimumMatch)
-> Parser MinimumMatchHighLow -> Parser CommonMinimumMatch
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MinimumMatchHighLow -> CommonMinimumMatch
CommonMinimumMatchHighLow (Parser MinimumMatchHighLow -> Parser CommonMinimumMatch)
-> (Value -> Parser MinimumMatchHighLow)
-> Value
-> Parser CommonMinimumMatch
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String
-> (Object -> Parser MinimumMatchHighLow)
-> Value
-> Parser MinimumMatchHighLow
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"CommonMinimumMatchHighLow" (\Object
o ->
                                  MinimumMatch -> MinimumMatch -> MinimumMatchHighLow
MinimumMatchHighLow
                                  (MinimumMatch -> MinimumMatch -> MinimumMatchHighLow)
-> Parser MinimumMatch
-> Parser (MinimumMatch -> MinimumMatchHighLow)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser MinimumMatch
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"low_freq"
                                  Parser (MinimumMatch -> MinimumMatchHighLow)
-> Parser MinimumMatch -> Parser MinimumMatchHighLow
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser MinimumMatch
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"high_freq")

data MinimumMatchHighLow =
  MinimumMatchHighLow { MinimumMatchHighLow -> MinimumMatch
lowFreq  :: MinimumMatch
                      , MinimumMatchHighLow -> MinimumMatch
highFreq :: MinimumMatch } deriving (MinimumMatchHighLow -> MinimumMatchHighLow -> Bool
(MinimumMatchHighLow -> MinimumMatchHighLow -> Bool)
-> (MinimumMatchHighLow -> MinimumMatchHighLow -> Bool)
-> Eq MinimumMatchHighLow
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MinimumMatchHighLow -> MinimumMatchHighLow -> Bool
$c/= :: MinimumMatchHighLow -> MinimumMatchHighLow -> Bool
== :: MinimumMatchHighLow -> MinimumMatchHighLow -> Bool
$c== :: MinimumMatchHighLow -> MinimumMatchHighLow -> Bool
Eq, Int -> MinimumMatchHighLow -> ShowS
[MinimumMatchHighLow] -> ShowS
MinimumMatchHighLow -> String
(Int -> MinimumMatchHighLow -> ShowS)
-> (MinimumMatchHighLow -> String)
-> ([MinimumMatchHighLow] -> ShowS)
-> Show MinimumMatchHighLow
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MinimumMatchHighLow] -> ShowS
$cshowList :: [MinimumMatchHighLow] -> ShowS
show :: MinimumMatchHighLow -> String
$cshow :: MinimumMatchHighLow -> String
showsPrec :: Int -> MinimumMatchHighLow -> ShowS
$cshowsPrec :: Int -> MinimumMatchHighLow -> ShowS
Show)

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

instance ToJSON ZeroTermsQuery where
  toJSON :: ZeroTermsQuery -> Value
toJSON ZeroTermsQuery
ZeroTermsNone = Text -> Value
String Text
"none"
  toJSON ZeroTermsQuery
ZeroTermsAll  = Text -> Value
String Text
"all"

instance FromJSON ZeroTermsQuery where
  parseJSON :: Value -> Parser ZeroTermsQuery
parseJSON = String
-> (Text -> Parser ZeroTermsQuery)
-> Value
-> Parser ZeroTermsQuery
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"ZeroTermsQuery" Text -> Parser ZeroTermsQuery
forall a (f :: * -> *).
(Eq a, IsString a, MonadFail f, Show a) =>
a -> f ZeroTermsQuery
parse
    where parse :: a -> f ZeroTermsQuery
parse a
"none" = ZeroTermsQuery -> f ZeroTermsQuery
forall (f :: * -> *) a. Applicative f => a -> f a
pure ZeroTermsQuery
ZeroTermsNone
          parse a
"all"  = ZeroTermsQuery -> f ZeroTermsQuery
forall (f :: * -> *) a. Applicative f => a -> f a
pure ZeroTermsQuery
ZeroTermsAll
          parse a
q      = String -> f ZeroTermsQuery
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"Unexpected ZeroTermsQuery: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> a -> String
forall a. Show a => a -> String
show a
q)

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

-- index for smaller ranges, fielddata for longer ranges
instance ToJSON RangeExecution where
  toJSON :: RangeExecution -> Value
toJSON RangeExecution
RangeExecutionIndex     = Value
"index"
  toJSON RangeExecution
RangeExecutionFielddata = Value
"fielddata"


instance FromJSON RangeExecution where
  parseJSON :: Value -> Parser RangeExecution
parseJSON = String
-> (Text -> Parser RangeExecution)
-> Value
-> Parser RangeExecution
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"RangeExecution" Text -> Parser RangeExecution
forall a (f :: * -> *).
(Eq a, IsString a, Applicative f, Show a) =>
a -> f RangeExecution
parse
    where parse :: a -> f RangeExecution
parse a
"index"     = RangeExecution -> f RangeExecution
forall (f :: * -> *) a. Applicative f => a -> f a
pure RangeExecution
RangeExecutionIndex
          parse a
"fielddata" = RangeExecution -> f RangeExecution
forall (f :: * -> *) a. Applicative f => a -> f a
pure RangeExecution
RangeExecutionFielddata
          parse a
t           = String -> f RangeExecution
forall a. HasCallStack => String -> a
error (String
"Unrecognized RangeExecution " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> a -> String
forall a. Show a => a -> String
show a
t)

newtype Regexp = Regexp Text deriving (Regexp -> Regexp -> Bool
(Regexp -> Regexp -> Bool)
-> (Regexp -> Regexp -> Bool) -> Eq Regexp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Regexp -> Regexp -> Bool
$c/= :: Regexp -> Regexp -> Bool
== :: Regexp -> Regexp -> Bool
$c== :: Regexp -> Regexp -> Bool
Eq, Int -> Regexp -> ShowS
[Regexp] -> ShowS
Regexp -> String
(Int -> Regexp -> ShowS)
-> (Regexp -> String) -> ([Regexp] -> ShowS) -> Show Regexp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Regexp] -> ShowS
$cshowList :: [Regexp] -> ShowS
show :: Regexp -> String
$cshow :: Regexp -> String
showsPrec :: Int -> Regexp -> ShowS
$cshowsPrec :: Int -> Regexp -> ShowS
Show, Value -> Parser [Regexp]
Value -> Parser Regexp
(Value -> Parser Regexp)
-> (Value -> Parser [Regexp]) -> FromJSON Regexp
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [Regexp]
$cparseJSONList :: Value -> Parser [Regexp]
parseJSON :: Value -> Parser Regexp
$cparseJSON :: Value -> Parser Regexp
FromJSON)

data RegexpFlags = AllRegexpFlags
                 | NoRegexpFlags
                 | SomeRegexpFlags (NonEmpty RegexpFlag) deriving (RegexpFlags -> RegexpFlags -> Bool
(RegexpFlags -> RegexpFlags -> Bool)
-> (RegexpFlags -> RegexpFlags -> Bool) -> Eq RegexpFlags
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegexpFlags -> RegexpFlags -> Bool
$c/= :: RegexpFlags -> RegexpFlags -> Bool
== :: RegexpFlags -> RegexpFlags -> Bool
$c== :: RegexpFlags -> RegexpFlags -> Bool
Eq, Int -> RegexpFlags -> ShowS
[RegexpFlags] -> ShowS
RegexpFlags -> String
(Int -> RegexpFlags -> ShowS)
-> (RegexpFlags -> String)
-> ([RegexpFlags] -> ShowS)
-> Show RegexpFlags
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegexpFlags] -> ShowS
$cshowList :: [RegexpFlags] -> ShowS
show :: RegexpFlags -> String
$cshow :: RegexpFlags -> String
showsPrec :: Int -> RegexpFlags -> ShowS
$cshowsPrec :: Int -> RegexpFlags -> ShowS
Show)

instance ToJSON RegexpFlags where
  toJSON :: RegexpFlags -> Value
toJSON RegexpFlags
AllRegexpFlags              = Text -> Value
String Text
"ALL"
  toJSON RegexpFlags
NoRegexpFlags               = Text -> Value
String Text
"NONE"
  toJSON (SomeRegexpFlags (RegexpFlag
h :| [RegexpFlag]
fs)) = Text -> Value
String (Text -> Value) -> Text -> Value
forall a b. (a -> b) -> a -> b
$ Text -> [Text] -> Text
T.intercalate Text
"|" [Text]
flagStrs
    where flagStrs :: [Text]
flagStrs             = (RegexpFlag -> Text) -> [RegexpFlag] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map RegexpFlag -> Text
forall p. IsString p => RegexpFlag -> p
flagStr ([RegexpFlag] -> [Text])
-> ([RegexpFlag] -> [RegexpFlag]) -> [RegexpFlag] -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [RegexpFlag] -> [RegexpFlag]
forall a. Eq a => [a] -> [a]
nub ([RegexpFlag] -> [Text]) -> [RegexpFlag] -> [Text]
forall a b. (a -> b) -> a -> b
$ RegexpFlag
hRegexpFlag -> [RegexpFlag] -> [RegexpFlag]
forall a. a -> [a] -> [a]
:[RegexpFlag]
fs
          flagStr :: RegexpFlag -> p
flagStr RegexpFlag
AnyString    = p
"ANYSTRING"
          flagStr RegexpFlag
Automaton    = p
"AUTOMATON"
          flagStr RegexpFlag
Complement   = p
"COMPLEMENT"
          flagStr RegexpFlag
Empty        = p
"EMPTY"
          flagStr RegexpFlag
Intersection = p
"INTERSECTION"
          flagStr RegexpFlag
Interval     = p
"INTERVAL"

instance FromJSON RegexpFlags where
  parseJSON :: Value -> Parser RegexpFlags
parseJSON = String
-> (Text -> Parser RegexpFlags) -> Value -> Parser RegexpFlags
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"RegexpFlags" Text -> Parser RegexpFlags
parse
    where parse :: Text -> Parser RegexpFlags
parse Text
"ALL" = RegexpFlags -> Parser RegexpFlags
forall (f :: * -> *) a. Applicative f => a -> f a
pure RegexpFlags
AllRegexpFlags
          parse Text
"NONE" = RegexpFlags -> Parser RegexpFlags
forall (f :: * -> *) a. Applicative f => a -> f a
pure RegexpFlags
NoRegexpFlags
          parse Text
t = NonEmpty RegexpFlag -> RegexpFlags
SomeRegexpFlags (NonEmpty RegexpFlag -> RegexpFlags)
-> Parser (NonEmpty RegexpFlag) -> Parser RegexpFlags
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Value] -> Parser (NonEmpty RegexpFlag)
forall a. FromJSON a => [Value] -> Parser (NonEmpty a)
parseNEJSON (Text -> Value
String (Text -> Value) -> [Text] -> [Value]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> Text -> [Text]
T.splitOn Text
"|" Text
t)

data RegexpFlag = AnyString
                | Automaton
                | Complement
                | Empty
                | Intersection
                | Interval deriving (RegexpFlag -> RegexpFlag -> Bool
(RegexpFlag -> RegexpFlag -> Bool)
-> (RegexpFlag -> RegexpFlag -> Bool) -> Eq RegexpFlag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegexpFlag -> RegexpFlag -> Bool
$c/= :: RegexpFlag -> RegexpFlag -> Bool
== :: RegexpFlag -> RegexpFlag -> Bool
$c== :: RegexpFlag -> RegexpFlag -> Bool
Eq, Int -> RegexpFlag -> ShowS
[RegexpFlag] -> ShowS
RegexpFlag -> String
(Int -> RegexpFlag -> ShowS)
-> (RegexpFlag -> String)
-> ([RegexpFlag] -> ShowS)
-> Show RegexpFlag
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegexpFlag] -> ShowS
$cshowList :: [RegexpFlag] -> ShowS
show :: RegexpFlag -> String
$cshow :: RegexpFlag -> String
showsPrec :: Int -> RegexpFlag -> ShowS
$cshowsPrec :: Int -> RegexpFlag -> ShowS
Show)

instance FromJSON RegexpFlag where
  parseJSON :: Value -> Parser RegexpFlag
parseJSON = String -> (Text -> Parser RegexpFlag) -> Value -> Parser RegexpFlag
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"RegexpFlag" Text -> Parser RegexpFlag
forall a (f :: * -> *).
(Eq a, IsString a, MonadFail f, Show a) =>
a -> f RegexpFlag
parse
    where parse :: a -> f RegexpFlag
parse a
"ANYSTRING"    = RegexpFlag -> f RegexpFlag
forall (f :: * -> *) a. Applicative f => a -> f a
pure RegexpFlag
AnyString
          parse a
"AUTOMATON"    = RegexpFlag -> f RegexpFlag
forall (f :: * -> *) a. Applicative f => a -> f a
pure RegexpFlag
Automaton
          parse a
"COMPLEMENT"   = RegexpFlag -> f RegexpFlag
forall (f :: * -> *) a. Applicative f => a -> f a
pure RegexpFlag
Complement
          parse a
"EMPTY"        = RegexpFlag -> f RegexpFlag
forall (f :: * -> *) a. Applicative f => a -> f a
pure RegexpFlag
Empty
          parse a
"INTERSECTION" = RegexpFlag -> f RegexpFlag
forall (f :: * -> *) a. Applicative f => a -> f a
pure RegexpFlag
Intersection
          parse a
"INTERVAL"     = RegexpFlag -> f RegexpFlag
forall (f :: * -> *) a. Applicative f => a -> f a
pure RegexpFlag
Interval
          parse a
f              = String -> f RegexpFlag
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"Unknown RegexpFlag: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> a -> String
forall a. Show a => a -> String
show a
f)

newtype LessThan = LessThan Double deriving (LessThan -> LessThan -> Bool
(LessThan -> LessThan -> Bool)
-> (LessThan -> LessThan -> Bool) -> Eq LessThan
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LessThan -> LessThan -> Bool
$c/= :: LessThan -> LessThan -> Bool
== :: LessThan -> LessThan -> Bool
$c== :: LessThan -> LessThan -> Bool
Eq, Int -> LessThan -> ShowS
[LessThan] -> ShowS
LessThan -> String
(Int -> LessThan -> ShowS)
-> (LessThan -> String) -> ([LessThan] -> ShowS) -> Show LessThan
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LessThan] -> ShowS
$cshowList :: [LessThan] -> ShowS
show :: LessThan -> String
$cshow :: LessThan -> String
showsPrec :: Int -> LessThan -> ShowS
$cshowsPrec :: Int -> LessThan -> ShowS
Show)
newtype LessThanEq = LessThanEq Double deriving (LessThanEq -> LessThanEq -> Bool
(LessThanEq -> LessThanEq -> Bool)
-> (LessThanEq -> LessThanEq -> Bool) -> Eq LessThanEq
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LessThanEq -> LessThanEq -> Bool
$c/= :: LessThanEq -> LessThanEq -> Bool
== :: LessThanEq -> LessThanEq -> Bool
$c== :: LessThanEq -> LessThanEq -> Bool
Eq, Int -> LessThanEq -> ShowS
[LessThanEq] -> ShowS
LessThanEq -> String
(Int -> LessThanEq -> ShowS)
-> (LessThanEq -> String)
-> ([LessThanEq] -> ShowS)
-> Show LessThanEq
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LessThanEq] -> ShowS
$cshowList :: [LessThanEq] -> ShowS
show :: LessThanEq -> String
$cshow :: LessThanEq -> String
showsPrec :: Int -> LessThanEq -> ShowS
$cshowsPrec :: Int -> LessThanEq -> ShowS
Show)
newtype GreaterThan = GreaterThan Double deriving (GreaterThan -> GreaterThan -> Bool
(GreaterThan -> GreaterThan -> Bool)
-> (GreaterThan -> GreaterThan -> Bool) -> Eq GreaterThan
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GreaterThan -> GreaterThan -> Bool
$c/= :: GreaterThan -> GreaterThan -> Bool
== :: GreaterThan -> GreaterThan -> Bool
$c== :: GreaterThan -> GreaterThan -> Bool
Eq, Int -> GreaterThan -> ShowS
[GreaterThan] -> ShowS
GreaterThan -> String
(Int -> GreaterThan -> ShowS)
-> (GreaterThan -> String)
-> ([GreaterThan] -> ShowS)
-> Show GreaterThan
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GreaterThan] -> ShowS
$cshowList :: [GreaterThan] -> ShowS
show :: GreaterThan -> String
$cshow :: GreaterThan -> String
showsPrec :: Int -> GreaterThan -> ShowS
$cshowsPrec :: Int -> GreaterThan -> ShowS
Show)
newtype GreaterThanEq = GreaterThanEq Double deriving (GreaterThanEq -> GreaterThanEq -> Bool
(GreaterThanEq -> GreaterThanEq -> Bool)
-> (GreaterThanEq -> GreaterThanEq -> Bool) -> Eq GreaterThanEq
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GreaterThanEq -> GreaterThanEq -> Bool
$c/= :: GreaterThanEq -> GreaterThanEq -> Bool
== :: GreaterThanEq -> GreaterThanEq -> Bool
$c== :: GreaterThanEq -> GreaterThanEq -> Bool
Eq, Int -> GreaterThanEq -> ShowS
[GreaterThanEq] -> ShowS
GreaterThanEq -> String
(Int -> GreaterThanEq -> ShowS)
-> (GreaterThanEq -> String)
-> ([GreaterThanEq] -> ShowS)
-> Show GreaterThanEq
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GreaterThanEq] -> ShowS
$cshowList :: [GreaterThanEq] -> ShowS
show :: GreaterThanEq -> String
$cshow :: GreaterThanEq -> String
showsPrec :: Int -> GreaterThanEq -> ShowS
$cshowsPrec :: Int -> GreaterThanEq -> ShowS
Show)

newtype LessThanD = LessThanD UTCTime deriving (LessThanD -> LessThanD -> Bool
(LessThanD -> LessThanD -> Bool)
-> (LessThanD -> LessThanD -> Bool) -> Eq LessThanD
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LessThanD -> LessThanD -> Bool
$c/= :: LessThanD -> LessThanD -> Bool
== :: LessThanD -> LessThanD -> Bool
$c== :: LessThanD -> LessThanD -> Bool
Eq, Int -> LessThanD -> ShowS
[LessThanD] -> ShowS
LessThanD -> String
(Int -> LessThanD -> ShowS)
-> (LessThanD -> String)
-> ([LessThanD] -> ShowS)
-> Show LessThanD
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LessThanD] -> ShowS
$cshowList :: [LessThanD] -> ShowS
show :: LessThanD -> String
$cshow :: LessThanD -> String
showsPrec :: Int -> LessThanD -> ShowS
$cshowsPrec :: Int -> LessThanD -> ShowS
Show)
newtype LessThanEqD = LessThanEqD UTCTime deriving (LessThanEqD -> LessThanEqD -> Bool
(LessThanEqD -> LessThanEqD -> Bool)
-> (LessThanEqD -> LessThanEqD -> Bool) -> Eq LessThanEqD
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LessThanEqD -> LessThanEqD -> Bool
$c/= :: LessThanEqD -> LessThanEqD -> Bool
== :: LessThanEqD -> LessThanEqD -> Bool
$c== :: LessThanEqD -> LessThanEqD -> Bool
Eq, Int -> LessThanEqD -> ShowS
[LessThanEqD] -> ShowS
LessThanEqD -> String
(Int -> LessThanEqD -> ShowS)
-> (LessThanEqD -> String)
-> ([LessThanEqD] -> ShowS)
-> Show LessThanEqD
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LessThanEqD] -> ShowS
$cshowList :: [LessThanEqD] -> ShowS
show :: LessThanEqD -> String
$cshow :: LessThanEqD -> String
showsPrec :: Int -> LessThanEqD -> ShowS
$cshowsPrec :: Int -> LessThanEqD -> ShowS
Show)
newtype GreaterThanD = GreaterThanD UTCTime deriving (GreaterThanD -> GreaterThanD -> Bool
(GreaterThanD -> GreaterThanD -> Bool)
-> (GreaterThanD -> GreaterThanD -> Bool) -> Eq GreaterThanD
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GreaterThanD -> GreaterThanD -> Bool
$c/= :: GreaterThanD -> GreaterThanD -> Bool
== :: GreaterThanD -> GreaterThanD -> Bool
$c== :: GreaterThanD -> GreaterThanD -> Bool
Eq, Int -> GreaterThanD -> ShowS
[GreaterThanD] -> ShowS
GreaterThanD -> String
(Int -> GreaterThanD -> ShowS)
-> (GreaterThanD -> String)
-> ([GreaterThanD] -> ShowS)
-> Show GreaterThanD
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GreaterThanD] -> ShowS
$cshowList :: [GreaterThanD] -> ShowS
show :: GreaterThanD -> String
$cshow :: GreaterThanD -> String
showsPrec :: Int -> GreaterThanD -> ShowS
$cshowsPrec :: Int -> GreaterThanD -> ShowS
Show)
newtype GreaterThanEqD = GreaterThanEqD UTCTime deriving (GreaterThanEqD -> GreaterThanEqD -> Bool
(GreaterThanEqD -> GreaterThanEqD -> Bool)
-> (GreaterThanEqD -> GreaterThanEqD -> Bool) -> Eq GreaterThanEqD
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GreaterThanEqD -> GreaterThanEqD -> Bool
$c/= :: GreaterThanEqD -> GreaterThanEqD -> Bool
== :: GreaterThanEqD -> GreaterThanEqD -> Bool
$c== :: GreaterThanEqD -> GreaterThanEqD -> Bool
Eq, Int -> GreaterThanEqD -> ShowS
[GreaterThanEqD] -> ShowS
GreaterThanEqD -> String
(Int -> GreaterThanEqD -> ShowS)
-> (GreaterThanEqD -> String)
-> ([GreaterThanEqD] -> ShowS)
-> Show GreaterThanEqD
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GreaterThanEqD] -> ShowS
$cshowList :: [GreaterThanEqD] -> ShowS
show :: GreaterThanEqD -> String
$cshow :: GreaterThanEqD -> String
showsPrec :: Int -> GreaterThanEqD -> ShowS
$cshowsPrec :: Int -> GreaterThanEqD -> ShowS
Show)

data RangeValue = RangeDateLte LessThanEqD
                | RangeDateLt LessThanD
                | RangeDateGte GreaterThanEqD
                | RangeDateGt GreaterThanD
                | RangeDateGtLt GreaterThanD LessThanD
                | RangeDateGteLte GreaterThanEqD LessThanEqD
                | RangeDateGteLt GreaterThanEqD LessThanD
                | RangeDateGtLte GreaterThanD LessThanEqD
                | RangeDoubleLte LessThanEq
                | RangeDoubleLt LessThan
                | RangeDoubleGte GreaterThanEq
                | RangeDoubleGt GreaterThan
                | RangeDoubleGtLt GreaterThan LessThan
                | RangeDoubleGteLte GreaterThanEq LessThanEq
                | RangeDoubleGteLt GreaterThanEq LessThan
                | RangeDoubleGtLte GreaterThan LessThanEq
                deriving (RangeValue -> RangeValue -> Bool
(RangeValue -> RangeValue -> Bool)
-> (RangeValue -> RangeValue -> Bool) -> Eq RangeValue
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RangeValue -> RangeValue -> Bool
$c/= :: RangeValue -> RangeValue -> Bool
== :: RangeValue -> RangeValue -> Bool
$c== :: RangeValue -> RangeValue -> Bool
Eq, Int -> RangeValue -> ShowS
[RangeValue] -> ShowS
RangeValue -> String
(Int -> RangeValue -> ShowS)
-> (RangeValue -> String)
-> ([RangeValue] -> ShowS)
-> Show RangeValue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RangeValue] -> ShowS
$cshowList :: [RangeValue] -> ShowS
show :: RangeValue -> String
$cshow :: RangeValue -> String
showsPrec :: Int -> RangeValue -> ShowS
$cshowsPrec :: Int -> RangeValue -> ShowS
Show)


parseRangeValue :: ( FromJSON t4
                   , FromJSON t3
                   , FromJSON t2
                   , FromJSON t1
                   )
                => (t3 -> t5)
                -> (t1 -> t6)
                -> (t4 -> t7)
                -> (t2 -> t8)
                -> (t5 -> t6 -> b)
                -> (t7 -> t6 -> b)
                -> (t5 -> t8 -> b)
                -> (t7 -> t8 -> b)
                -> (t5 -> b)
                -> (t6 -> b)
                -> (t7 -> b)
                -> (t8 -> b)
                -> Parser b
                -> Object
                -> Parser b
parseRangeValue :: (t3 -> t5)
-> (t1 -> t6)
-> (t4 -> t7)
-> (t2 -> t8)
-> (t5 -> t6 -> b)
-> (t7 -> t6 -> b)
-> (t5 -> t8 -> b)
-> (t7 -> t8 -> b)
-> (t5 -> b)
-> (t6 -> b)
-> (t7 -> b)
-> (t8 -> b)
-> Parser b
-> Object
-> Parser b
parseRangeValue t3 -> t5
mkGt t1 -> t6
mkLt t4 -> t7
mkGte t2 -> t8
mkLte
                t5 -> t6 -> b
fGtLt t7 -> t6 -> b
fGteLt t5 -> t8 -> b
fGtLte t7 -> t8 -> b
fGteLte
                t5 -> b
fGt t6 -> b
fLt t7 -> b
fGte t8 -> b
fLte Parser b
nada Object
o = do
  Maybe t1
lt <- Object
o Object -> Key -> Parser (Maybe t1)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"lt"
  Maybe t2
lte <- Object
o Object -> Key -> Parser (Maybe t2)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"lte"
  Maybe t3
gt <- Object
o Object -> Key -> Parser (Maybe t3)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"gt"
  Maybe t4
gte <- Object
o Object -> Key -> Parser (Maybe t4)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"gte"
  case (Maybe t1
lt, Maybe t2
lte, Maybe t3
gt, Maybe t4
gte) of
    (Just t1
a, Maybe t2
_, Just t3
b, Maybe t4
_) ->
      b -> Parser b
forall (m :: * -> *) a. Monad m => a -> m a
return (t5 -> t6 -> b
fGtLt (t3 -> t5
mkGt t3
b) (t1 -> t6
mkLt t1
a))
    (Just t1
a, Maybe t2
_, Maybe t3
_, Just t4
b) ->
      b -> Parser b
forall (m :: * -> *) a. Monad m => a -> m a
return (t7 -> t6 -> b
fGteLt (t4 -> t7
mkGte t4
b) (t1 -> t6
mkLt t1
a))
    (Maybe t1
_, Just t2
a, Just t3
b, Maybe t4
_) ->
      b -> Parser b
forall (m :: * -> *) a. Monad m => a -> m a
return (t5 -> t8 -> b
fGtLte (t3 -> t5
mkGt t3
b) (t2 -> t8
mkLte t2
a))
    (Maybe t1
_, Just t2
a, Maybe t3
_, Just t4
b) ->
      b -> Parser b
forall (m :: * -> *) a. Monad m => a -> m a
return (t7 -> t8 -> b
fGteLte (t4 -> t7
mkGte t4
b) (t2 -> t8
mkLte t2
a))
    (Maybe t1
_, Maybe t2
_, Just t3
a, Maybe t4
_) ->
      b -> Parser b
forall (m :: * -> *) a. Monad m => a -> m a
return (t5 -> b
fGt (t3 -> t5
mkGt t3
a))
    (Just t1
a, Maybe t2
_, Maybe t3
_, Maybe t4
_) ->
      b -> Parser b
forall (m :: * -> *) a. Monad m => a -> m a
return (t6 -> b
fLt (t1 -> t6
mkLt t1
a))
    (Maybe t1
_, Maybe t2
_, Maybe t3
_, Just t4
a) ->
      b -> Parser b
forall (m :: * -> *) a. Monad m => a -> m a
return (t7 -> b
fGte (t4 -> t7
mkGte t4
a))
    (Maybe t1
_, Just t2
a, Maybe t3
_, Maybe t4
_) ->
      b -> Parser b
forall (m :: * -> *) a. Monad m => a -> m a
return (t8 -> b
fLte (t2 -> t8
mkLte t2
a))
    (Maybe t1
Nothing, Maybe t2
Nothing, Maybe t3
Nothing, Maybe t4
Nothing) ->
      Parser b
nada


instance FromJSON RangeValue where
  parseJSON :: Value -> Parser RangeValue
parseJSON = String
-> (Object -> Parser RangeValue) -> Value -> Parser RangeValue
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"RangeValue" Object -> Parser RangeValue
parse
    where parse :: Object -> Parser RangeValue
parse Object
o = Object -> Parser RangeValue
parseDate Object
o
                Parser RangeValue -> Parser RangeValue -> Parser RangeValue
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Object -> Parser RangeValue
parseDouble Object
o
          parseDate :: Object -> Parser RangeValue
parseDate Object
o =
            (UTCTime -> GreaterThanD)
-> (UTCTime -> LessThanD)
-> (UTCTime -> GreaterThanEqD)
-> (UTCTime -> LessThanEqD)
-> (GreaterThanD -> LessThanD -> RangeValue)
-> (GreaterThanEqD -> LessThanD -> RangeValue)
-> (GreaterThanD -> LessThanEqD -> RangeValue)
-> (GreaterThanEqD -> LessThanEqD -> RangeValue)
-> (GreaterThanD -> RangeValue)
-> (LessThanD -> RangeValue)
-> (GreaterThanEqD -> RangeValue)
-> (LessThanEqD -> RangeValue)
-> Parser RangeValue
-> Object
-> Parser RangeValue
forall t4 t3 t2 t1 t5 t6 t7 t8 b.
(FromJSON t4, FromJSON t3, FromJSON t2, FromJSON t1) =>
(t3 -> t5)
-> (t1 -> t6)
-> (t4 -> t7)
-> (t2 -> t8)
-> (t5 -> t6 -> b)
-> (t7 -> t6 -> b)
-> (t5 -> t8 -> b)
-> (t7 -> t8 -> b)
-> (t5 -> b)
-> (t6 -> b)
-> (t7 -> b)
-> (t8 -> b)
-> Parser b
-> Object
-> Parser b
parseRangeValue
            UTCTime -> GreaterThanD
GreaterThanD UTCTime -> LessThanD
LessThanD
            UTCTime -> GreaterThanEqD
GreaterThanEqD UTCTime -> LessThanEqD
LessThanEqD
            GreaterThanD -> LessThanD -> RangeValue
RangeDateGtLt GreaterThanEqD -> LessThanD -> RangeValue
RangeDateGteLt
            GreaterThanD -> LessThanEqD -> RangeValue
RangeDateGtLte GreaterThanEqD -> LessThanEqD -> RangeValue
RangeDateGteLte
            GreaterThanD -> RangeValue
RangeDateGt LessThanD -> RangeValue
RangeDateLt
            GreaterThanEqD -> RangeValue
RangeDateGte LessThanEqD -> RangeValue
RangeDateLte
            Parser RangeValue
forall (m :: * -> *) a. MonadPlus m => m a
mzero Object
o
          parseDouble :: Object -> Parser RangeValue
parseDouble Object
o =
            (Double -> GreaterThan)
-> (Double -> LessThan)
-> (Double -> GreaterThanEq)
-> (Double -> LessThanEq)
-> (GreaterThan -> LessThan -> RangeValue)
-> (GreaterThanEq -> LessThan -> RangeValue)
-> (GreaterThan -> LessThanEq -> RangeValue)
-> (GreaterThanEq -> LessThanEq -> RangeValue)
-> (GreaterThan -> RangeValue)
-> (LessThan -> RangeValue)
-> (GreaterThanEq -> RangeValue)
-> (LessThanEq -> RangeValue)
-> Parser RangeValue
-> Object
-> Parser RangeValue
forall t4 t3 t2 t1 t5 t6 t7 t8 b.
(FromJSON t4, FromJSON t3, FromJSON t2, FromJSON t1) =>
(t3 -> t5)
-> (t1 -> t6)
-> (t4 -> t7)
-> (t2 -> t8)
-> (t5 -> t6 -> b)
-> (t7 -> t6 -> b)
-> (t5 -> t8 -> b)
-> (t7 -> t8 -> b)
-> (t5 -> b)
-> (t6 -> b)
-> (t7 -> b)
-> (t8 -> b)
-> Parser b
-> Object
-> Parser b
parseRangeValue
            Double -> GreaterThan
GreaterThan Double -> LessThan
LessThan
            Double -> GreaterThanEq
GreaterThanEq Double -> LessThanEq
LessThanEq
            GreaterThan -> LessThan -> RangeValue
RangeDoubleGtLt GreaterThanEq -> LessThan -> RangeValue
RangeDoubleGteLt
            GreaterThan -> LessThanEq -> RangeValue
RangeDoubleGtLte GreaterThanEq -> LessThanEq -> RangeValue
RangeDoubleGteLte
            GreaterThan -> RangeValue
RangeDoubleGt LessThan -> RangeValue
RangeDoubleLt
            GreaterThanEq -> RangeValue
RangeDoubleGte LessThanEq -> RangeValue
RangeDoubleLte
            Parser RangeValue
forall (m :: * -> *) a. MonadPlus m => m a
mzero Object
o

rangeValueToPair :: RangeValue -> [Pair]
rangeValueToPair :: RangeValue -> [Pair]
rangeValueToPair RangeValue
rv = case RangeValue
rv of
  RangeDateLte (LessThanEqD UTCTime
t)                       -> [Key
"lte" Key -> UTCTime -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= UTCTime
t]
  RangeDateGte (GreaterThanEqD UTCTime
t)                    -> [Key
"gte" Key -> UTCTime -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= UTCTime
t]
  RangeDateLt (LessThanD UTCTime
t)                          -> [Key
"lt"  Key -> UTCTime -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= UTCTime
t]
  RangeDateGt (GreaterThanD UTCTime
t)                       -> [Key
"gt"  Key -> UTCTime -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= UTCTime
t]
  RangeDateGteLte (GreaterThanEqD UTCTime
l) (LessThanEqD UTCTime
g) -> [Key
"gte" Key -> UTCTime -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= UTCTime
l, Key
"lte" Key -> UTCTime -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= UTCTime
g]
  RangeDateGtLte (GreaterThanD UTCTime
l) (LessThanEqD UTCTime
g)    -> [Key
"gt"  Key -> UTCTime -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= UTCTime
l, Key
"lte" Key -> UTCTime -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= UTCTime
g]
  RangeDateGteLt (GreaterThanEqD UTCTime
l) (LessThanD UTCTime
g)    -> [Key
"gte" Key -> UTCTime -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= UTCTime
l, Key
"lt"  Key -> UTCTime -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= UTCTime
g]
  RangeDateGtLt (GreaterThanD UTCTime
l) (LessThanD UTCTime
g)       -> [Key
"gt"  Key -> UTCTime -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= UTCTime
l, Key
"lt"  Key -> UTCTime -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= UTCTime
g]
  RangeDoubleLte (LessThanEq Double
t)                      -> [Key
"lte" Key -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Double
t]
  RangeDoubleGte (GreaterThanEq Double
t)                   -> [Key
"gte" Key -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Double
t]
  RangeDoubleLt (LessThan Double
t)                         -> [Key
"lt"  Key -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Double
t]
  RangeDoubleGt (GreaterThan Double
t)                      -> [Key
"gt"  Key -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Double
t]
  RangeDoubleGteLte (GreaterThanEq Double
l) (LessThanEq Double
g) -> [Key
"gte" Key -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Double
l, Key
"lte" Key -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Double
g]
  RangeDoubleGtLte (GreaterThan Double
l) (LessThanEq Double
g)    -> [Key
"gt"  Key -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Double
l, Key
"lte" Key -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Double
g]
  RangeDoubleGteLt (GreaterThanEq Double
l) (LessThan Double
g)    -> [Key
"gte" Key -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Double
l, Key
"lt"  Key -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Double
g]
  RangeDoubleGtLt (GreaterThan Double
l) (LessThan Double
g)       -> [Key
"gt"  Key -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Double
l, Key
"lt"  Key -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Double
g]

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

instance ToJSON Term where
  toJSON :: Term -> Value
toJSON (Term Key
field Text
value) = [Pair] -> Value
object [Key
"term" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Pair] -> Value
object
                                      [Key
field Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
value]]

instance FromJSON Term where
  parseJSON :: Value -> Parser Term
parseJSON = String -> (Object -> Parser Term) -> Value -> Parser Term
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Term" Object -> Parser Term
parse
    where parse :: Object -> Parser Term
parse Object
o = do HashMap Key Value
termObj <- Object
o Object -> Key -> Parser (HashMap Key Value)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"term"
                       case HashMap Key Value -> [Pair]
forall k v. HashMap k v -> [(k, v)]
HM.toList HashMap Key Value
termObj of
                         [(Key
fn, Value
v)] -> Key -> Text -> Term
Term Key
fn (Text -> Term) -> Parser Text -> Parser Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser Text
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v
                         [Pair]
_ -> String -> Parser Term
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Expected object with 1 field-named key"

data BoolMatch = MustMatch    Term  Cache
               | MustNotMatch Term  Cache
               | ShouldMatch [Term] Cache deriving (BoolMatch -> BoolMatch -> Bool
(BoolMatch -> BoolMatch -> Bool)
-> (BoolMatch -> BoolMatch -> Bool) -> Eq BoolMatch
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BoolMatch -> BoolMatch -> Bool
$c/= :: BoolMatch -> BoolMatch -> Bool
== :: BoolMatch -> BoolMatch -> Bool
$c== :: BoolMatch -> BoolMatch -> Bool
Eq, Int -> BoolMatch -> ShowS
[BoolMatch] -> ShowS
BoolMatch -> String
(Int -> BoolMatch -> ShowS)
-> (BoolMatch -> String)
-> ([BoolMatch] -> ShowS)
-> Show BoolMatch
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BoolMatch] -> ShowS
$cshowList :: [BoolMatch] -> ShowS
show :: BoolMatch -> String
$cshow :: BoolMatch -> String
showsPrec :: Int -> BoolMatch -> ShowS
$cshowsPrec :: Int -> BoolMatch -> ShowS
Show)


instance ToJSON BoolMatch where
  toJSON :: BoolMatch -> Value
toJSON (MustMatch    Term
term  Bool
cache) = [Pair] -> Value
object [Key
"must"     Key -> Term -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Term
term,
                                              Key
"_cache" Key -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Bool
cache]
  toJSON (MustNotMatch Term
term  Bool
cache) = [Pair] -> Value
object [Key
"must_not" Key -> Term -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Term
term,
                                              Key
"_cache" Key -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Bool
cache]
  toJSON (ShouldMatch  [Term]
terms Bool
cache) = [Pair] -> Value
object [Key
"should"   Key -> [Value] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= (Term -> Value) -> [Term] -> [Value]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Term -> Value
forall a. ToJSON a => a -> Value
toJSON [Term]
terms,
                                              Key
"_cache" Key -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Bool
cache]

instance FromJSON BoolMatch where
  parseJSON :: Value -> Parser BoolMatch
parseJSON = String -> (Object -> Parser BoolMatch) -> Value -> Parser BoolMatch
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"BoolMatch" Object -> Parser BoolMatch
parse
    where parse :: Object -> Parser BoolMatch
parse Object
o = Term -> Parser BoolMatch
mustMatch (Term -> Parser BoolMatch) -> Key -> Parser BoolMatch
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"must"
                Parser BoolMatch -> Parser BoolMatch -> Parser BoolMatch
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Term -> Parser BoolMatch
mustNotMatch (Term -> Parser BoolMatch) -> Key -> Parser BoolMatch
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"must_not"
                Parser BoolMatch -> Parser BoolMatch -> Parser BoolMatch
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Term] -> Parser BoolMatch
shouldMatch ([Term] -> Parser BoolMatch) -> Key -> Parser BoolMatch
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"should"
            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
                  mustMatch :: Term -> Parser BoolMatch
mustMatch Term
t = Term -> Bool -> BoolMatch
MustMatch Term
t (Bool -> BoolMatch) -> Parser Bool -> Parser BoolMatch
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"_cache" Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= Bool
defaultCache
                  mustNotMatch :: Term -> Parser BoolMatch
mustNotMatch Term
t = Term -> Bool -> BoolMatch
MustNotMatch Term
t (Bool -> BoolMatch) -> Parser Bool -> Parser BoolMatch
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"_cache" Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= Bool
defaultCache
                  shouldMatch :: [Term] -> Parser BoolMatch
shouldMatch [Term]
t = [Term] -> Bool -> BoolMatch
ShouldMatch [Term]
t (Bool -> BoolMatch) -> Parser Bool -> Parser BoolMatch
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"_cache" Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= Bool
defaultCache

-- "memory" or "indexed"
data GeoFilterType = GeoFilterMemory
                   | GeoFilterIndexed deriving (GeoFilterType -> GeoFilterType -> Bool
(GeoFilterType -> GeoFilterType -> Bool)
-> (GeoFilterType -> GeoFilterType -> Bool) -> Eq GeoFilterType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GeoFilterType -> GeoFilterType -> Bool
$c/= :: GeoFilterType -> GeoFilterType -> Bool
== :: GeoFilterType -> GeoFilterType -> Bool
$c== :: GeoFilterType -> GeoFilterType -> Bool
Eq, Int -> GeoFilterType -> ShowS
[GeoFilterType] -> ShowS
GeoFilterType -> String
(Int -> GeoFilterType -> ShowS)
-> (GeoFilterType -> String)
-> ([GeoFilterType] -> ShowS)
-> Show GeoFilterType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GeoFilterType] -> ShowS
$cshowList :: [GeoFilterType] -> ShowS
show :: GeoFilterType -> String
$cshow :: GeoFilterType -> String
showsPrec :: Int -> GeoFilterType -> ShowS
$cshowsPrec :: Int -> GeoFilterType -> ShowS
Show)

instance ToJSON GeoFilterType where
  toJSON :: GeoFilterType -> Value
toJSON GeoFilterType
GeoFilterMemory  = Text -> Value
String Text
"memory"
  toJSON GeoFilterType
GeoFilterIndexed = Text -> Value
String Text
"indexed"

instance FromJSON GeoFilterType where
  parseJSON :: Value -> Parser GeoFilterType
parseJSON = String
-> (Text -> Parser GeoFilterType) -> Value -> Parser GeoFilterType
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"GeoFilterType" Text -> Parser GeoFilterType
forall a (f :: * -> *).
(Eq a, IsString a, MonadFail f, Show a) =>
a -> f GeoFilterType
parse
    where parse :: a -> f GeoFilterType
parse a
"memory"  = GeoFilterType -> f GeoFilterType
forall (f :: * -> *) a. Applicative f => a -> f a
pure GeoFilterType
GeoFilterMemory
          parse a
"indexed" = GeoFilterType -> f GeoFilterType
forall (f :: * -> *) a. Applicative f => a -> f a
pure GeoFilterType
GeoFilterIndexed
          parse a
t         = String -> f GeoFilterType
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"Unrecognized GeoFilterType: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> a -> String
forall a. Show a => a -> String
show a
t)

data LatLon = LatLon { LatLon -> Double
lat :: Double
                     , LatLon -> Double
lon :: Double } deriving (LatLon -> LatLon -> Bool
(LatLon -> LatLon -> Bool)
-> (LatLon -> LatLon -> Bool) -> Eq LatLon
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LatLon -> LatLon -> Bool
$c/= :: LatLon -> LatLon -> Bool
== :: LatLon -> LatLon -> Bool
$c== :: LatLon -> LatLon -> Bool
Eq, Int -> LatLon -> ShowS
[LatLon] -> ShowS
LatLon -> String
(Int -> LatLon -> ShowS)
-> (LatLon -> String) -> ([LatLon] -> ShowS) -> Show LatLon
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LatLon] -> ShowS
$cshowList :: [LatLon] -> ShowS
show :: LatLon -> String
$cshow :: LatLon -> String
showsPrec :: Int -> LatLon -> ShowS
$cshowsPrec :: Int -> LatLon -> ShowS
Show)

instance ToJSON LatLon where
  toJSON :: LatLon -> Value
toJSON (LatLon Double
lLat Double
lLon) =
    [Pair] -> Value
object [Key
"lat"  Key -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Double
lLat
           , Key
"lon" Key -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Double
lLon]

instance FromJSON LatLon where
  parseJSON :: Value -> Parser LatLon
parseJSON = String -> (Object -> Parser LatLon) -> Value -> Parser LatLon
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"LatLon" Object -> Parser LatLon
parse
    where parse :: Object -> Parser LatLon
parse Object
o = Double -> Double -> LatLon
LatLon (Double -> Double -> LatLon)
-> Parser Double -> Parser (Double -> LatLon)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Double
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"lat"
                           Parser (Double -> LatLon) -> Parser Double -> Parser LatLon
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
"lon"

data GeoBoundingBox =
  GeoBoundingBox { GeoBoundingBox -> LatLon
topLeft     :: LatLon
                 , GeoBoundingBox -> LatLon
bottomRight :: LatLon } deriving (GeoBoundingBox -> GeoBoundingBox -> Bool
(GeoBoundingBox -> GeoBoundingBox -> Bool)
-> (GeoBoundingBox -> GeoBoundingBox -> Bool) -> Eq GeoBoundingBox
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GeoBoundingBox -> GeoBoundingBox -> Bool
$c/= :: GeoBoundingBox -> GeoBoundingBox -> Bool
== :: GeoBoundingBox -> GeoBoundingBox -> Bool
$c== :: GeoBoundingBox -> GeoBoundingBox -> Bool
Eq, Int -> GeoBoundingBox -> ShowS
[GeoBoundingBox] -> ShowS
GeoBoundingBox -> String
(Int -> GeoBoundingBox -> ShowS)
-> (GeoBoundingBox -> String)
-> ([GeoBoundingBox] -> ShowS)
-> Show GeoBoundingBox
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GeoBoundingBox] -> ShowS
$cshowList :: [GeoBoundingBox] -> ShowS
show :: GeoBoundingBox -> String
$cshow :: GeoBoundingBox -> String
showsPrec :: Int -> GeoBoundingBox -> ShowS
$cshowsPrec :: Int -> GeoBoundingBox -> ShowS
Show)

instance ToJSON GeoBoundingBox where
  toJSON :: GeoBoundingBox -> Value
toJSON (GeoBoundingBox LatLon
gbbTopLeft LatLon
gbbBottomRight) =
    [Pair] -> Value
object [Key
"top_left"      Key -> LatLon -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= LatLon
gbbTopLeft
           , Key
"bottom_right" Key -> LatLon -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= LatLon
gbbBottomRight]

instance FromJSON GeoBoundingBox where
  parseJSON :: Value -> Parser GeoBoundingBox
parseJSON = String
-> (Object -> Parser GeoBoundingBox)
-> Value
-> Parser GeoBoundingBox
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"GeoBoundingBox" Object -> Parser GeoBoundingBox
parse
    where parse :: Object -> Parser GeoBoundingBox
parse Object
o = LatLon -> LatLon -> GeoBoundingBox
GeoBoundingBox
                    (LatLon -> LatLon -> GeoBoundingBox)
-> Parser LatLon -> Parser (LatLon -> GeoBoundingBox)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser LatLon
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"top_left"
                    Parser (LatLon -> GeoBoundingBox)
-> Parser LatLon -> Parser GeoBoundingBox
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser LatLon
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"bottom_right"

data GeoBoundingBoxConstraint =
  GeoBoundingBoxConstraint { GeoBoundingBoxConstraint -> FieldName
geoBBField        :: FieldName
                           , GeoBoundingBoxConstraint -> GeoBoundingBox
constraintBox     :: GeoBoundingBox
                           , GeoBoundingBoxConstraint -> Bool
bbConstraintcache :: Cache
                           , GeoBoundingBoxConstraint -> GeoFilterType
geoType           :: GeoFilterType
                           } deriving (GeoBoundingBoxConstraint -> GeoBoundingBoxConstraint -> Bool
(GeoBoundingBoxConstraint -> GeoBoundingBoxConstraint -> Bool)
-> (GeoBoundingBoxConstraint -> GeoBoundingBoxConstraint -> Bool)
-> Eq GeoBoundingBoxConstraint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GeoBoundingBoxConstraint -> GeoBoundingBoxConstraint -> Bool
$c/= :: GeoBoundingBoxConstraint -> GeoBoundingBoxConstraint -> Bool
== :: GeoBoundingBoxConstraint -> GeoBoundingBoxConstraint -> Bool
$c== :: GeoBoundingBoxConstraint -> GeoBoundingBoxConstraint -> Bool
Eq, Int -> GeoBoundingBoxConstraint -> ShowS
[GeoBoundingBoxConstraint] -> ShowS
GeoBoundingBoxConstraint -> String
(Int -> GeoBoundingBoxConstraint -> ShowS)
-> (GeoBoundingBoxConstraint -> String)
-> ([GeoBoundingBoxConstraint] -> ShowS)
-> Show GeoBoundingBoxConstraint
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GeoBoundingBoxConstraint] -> ShowS
$cshowList :: [GeoBoundingBoxConstraint] -> ShowS
show :: GeoBoundingBoxConstraint -> String
$cshow :: GeoBoundingBoxConstraint -> String
showsPrec :: Int -> GeoBoundingBoxConstraint -> ShowS
$cshowsPrec :: Int -> GeoBoundingBoxConstraint -> ShowS
Show)

instance ToJSON GeoBoundingBoxConstraint where
  toJSON :: GeoBoundingBoxConstraint -> Value
toJSON (GeoBoundingBoxConstraint
          (FieldName Text
gbbcGeoBBField) GeoBoundingBox
gbbcConstraintBox Bool
cache GeoFilterType
type') =
    [Pair] -> Value
object [Text -> Key
fromText Text
gbbcGeoBBField Key -> GeoBoundingBox -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= GeoBoundingBox
gbbcConstraintBox
           , Key
"_cache"  Key -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Bool
cache
           , Key
"type" Key -> GeoFilterType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= GeoFilterType
type']

instance FromJSON GeoBoundingBoxConstraint where
  parseJSON :: Value -> Parser GeoBoundingBoxConstraint
parseJSON = String
-> (Object -> Parser GeoBoundingBoxConstraint)
-> Value
-> Parser GeoBoundingBoxConstraint
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"GeoBoundingBoxConstraint" Object -> Parser GeoBoundingBoxConstraint
parse
    where parse :: Object -> Parser GeoBoundingBoxConstraint
parse Object
o = case Object -> [Pair]
forall v. KeyMap v -> [(Key, v)]
X.toList ([Key] -> Object -> Object
forall v. [Key] -> KeyMap v -> KeyMap v
deleteSeveral [Key
"type", Key
"_cache"] Object
o) of
                      [(Key
fn, Value
v)] -> FieldName
-> GeoBoundingBox
-> Bool
-> GeoFilterType
-> GeoBoundingBoxConstraint
GeoBoundingBoxConstraint (Text -> FieldName
FieldName (Text -> FieldName) -> Text -> FieldName
forall a b. (a -> b) -> a -> b
$ Key -> Text
toText Key
fn)
                                   (GeoBoundingBox
 -> Bool -> GeoFilterType -> GeoBoundingBoxConstraint)
-> Parser GeoBoundingBox
-> Parser (Bool -> GeoFilterType -> GeoBoundingBoxConstraint)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser GeoBoundingBox
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v
                                   Parser (Bool -> GeoFilterType -> GeoBoundingBoxConstraint)
-> Parser Bool
-> Parser (GeoFilterType -> GeoBoundingBoxConstraint)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"_cache" Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= Bool
defaultCache
                                   Parser (GeoFilterType -> GeoBoundingBoxConstraint)
-> Parser GeoFilterType -> Parser GeoBoundingBoxConstraint
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser GeoFilterType
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type"
                      [Pair]
_ -> String -> Parser GeoBoundingBoxConstraint
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Could not find field name for GeoBoundingBoxConstraint"

data GeoPoint =
  GeoPoint { GeoPoint -> FieldName
geoField :: FieldName
           , GeoPoint -> LatLon
latLon   :: LatLon} deriving (GeoPoint -> GeoPoint -> Bool
(GeoPoint -> GeoPoint -> Bool)
-> (GeoPoint -> GeoPoint -> Bool) -> Eq GeoPoint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GeoPoint -> GeoPoint -> Bool
$c/= :: GeoPoint -> GeoPoint -> Bool
== :: GeoPoint -> GeoPoint -> Bool
$c== :: GeoPoint -> GeoPoint -> Bool
Eq, Int -> GeoPoint -> ShowS
[GeoPoint] -> ShowS
GeoPoint -> String
(Int -> GeoPoint -> ShowS)
-> (GeoPoint -> String) -> ([GeoPoint] -> ShowS) -> Show GeoPoint
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GeoPoint] -> ShowS
$cshowList :: [GeoPoint] -> ShowS
show :: GeoPoint -> String
$cshow :: GeoPoint -> String
showsPrec :: Int -> GeoPoint -> ShowS
$cshowsPrec :: Int -> GeoPoint -> ShowS
Show)

instance ToJSON GeoPoint where
  toJSON :: GeoPoint -> Value
toJSON (GeoPoint (FieldName Text
geoPointField) LatLon
geoPointLatLon) =
    [Pair] -> Value
object [ Text -> Key
fromText Text
geoPointField  Key -> LatLon -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= LatLon
geoPointLatLon ]

data DistanceUnit = Miles
                  | Yards
                  | Feet
                  | Inches
                  | Kilometers
                  | Meters
                  | Centimeters
                  | Millimeters
                  | NauticalMiles deriving (DistanceUnit -> DistanceUnit -> Bool
(DistanceUnit -> DistanceUnit -> Bool)
-> (DistanceUnit -> DistanceUnit -> Bool) -> Eq DistanceUnit
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DistanceUnit -> DistanceUnit -> Bool
$c/= :: DistanceUnit -> DistanceUnit -> Bool
== :: DistanceUnit -> DistanceUnit -> Bool
$c== :: DistanceUnit -> DistanceUnit -> Bool
Eq, Int -> DistanceUnit -> ShowS
[DistanceUnit] -> ShowS
DistanceUnit -> String
(Int -> DistanceUnit -> ShowS)
-> (DistanceUnit -> String)
-> ([DistanceUnit] -> ShowS)
-> Show DistanceUnit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DistanceUnit] -> ShowS
$cshowList :: [DistanceUnit] -> ShowS
show :: DistanceUnit -> String
$cshow :: DistanceUnit -> String
showsPrec :: Int -> DistanceUnit -> ShowS
$cshowsPrec :: Int -> DistanceUnit -> ShowS
Show)

instance ToJSON DistanceUnit where
  toJSON :: DistanceUnit -> Value
toJSON DistanceUnit
Miles         = Text -> Value
String Text
"mi"
  toJSON DistanceUnit
Yards         = Text -> Value
String Text
"yd"
  toJSON DistanceUnit
Feet          = Text -> Value
String Text
"ft"
  toJSON DistanceUnit
Inches        = Text -> Value
String Text
"in"
  toJSON DistanceUnit
Kilometers    = Text -> Value
String Text
"km"
  toJSON DistanceUnit
Meters        = Text -> Value
String Text
"m"
  toJSON DistanceUnit
Centimeters   = Text -> Value
String Text
"cm"
  toJSON DistanceUnit
Millimeters   = Text -> Value
String Text
"mm"
  toJSON DistanceUnit
NauticalMiles = Text -> Value
String Text
"nmi"

instance FromJSON DistanceUnit where
  parseJSON :: Value -> Parser DistanceUnit
parseJSON = String
-> (Text -> Parser DistanceUnit) -> Value -> Parser DistanceUnit
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"DistanceUnit" Text -> Parser DistanceUnit
forall a (f :: * -> *).
(Eq a, IsString a, MonadFail f, Show a) =>
a -> f DistanceUnit
parse
    where parse :: a -> f DistanceUnit
parse a
"mi"  = DistanceUnit -> f DistanceUnit
forall (f :: * -> *) a. Applicative f => a -> f a
pure DistanceUnit
Miles
          parse a
"yd"  = DistanceUnit -> f DistanceUnit
forall (f :: * -> *) a. Applicative f => a -> f a
pure DistanceUnit
Yards
          parse a
"ft"  = DistanceUnit -> f DistanceUnit
forall (f :: * -> *) a. Applicative f => a -> f a
pure DistanceUnit
Feet
          parse a
"in"  = DistanceUnit -> f DistanceUnit
forall (f :: * -> *) a. Applicative f => a -> f a
pure DistanceUnit
Inches
          parse a
"km"  = DistanceUnit -> f DistanceUnit
forall (f :: * -> *) a. Applicative f => a -> f a
pure DistanceUnit
Kilometers
          parse a
"m"   = DistanceUnit -> f DistanceUnit
forall (f :: * -> *) a. Applicative f => a -> f a
pure DistanceUnit
Meters
          parse a
"cm"  = DistanceUnit -> f DistanceUnit
forall (f :: * -> *) a. Applicative f => a -> f a
pure DistanceUnit
Centimeters
          parse a
"mm"  = DistanceUnit -> f DistanceUnit
forall (f :: * -> *) a. Applicative f => a -> f a
pure DistanceUnit
Millimeters
          parse a
"nmi" = DistanceUnit -> f DistanceUnit
forall (f :: * -> *) a. Applicative f => a -> f a
pure DistanceUnit
NauticalMiles
          parse a
u     = String -> f DistanceUnit
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"Unrecognized DistanceUnit: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> a -> String
forall a. Show a => a -> String
show a
u)

data DistanceType = Arc
                  | SloppyArc -- doesn't exist <1.0
                  | Plane deriving (DistanceType -> DistanceType -> Bool
(DistanceType -> DistanceType -> Bool)
-> (DistanceType -> DistanceType -> Bool) -> Eq DistanceType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DistanceType -> DistanceType -> Bool
$c/= :: DistanceType -> DistanceType -> Bool
== :: DistanceType -> DistanceType -> Bool
$c== :: DistanceType -> DistanceType -> Bool
Eq, Int -> DistanceType -> ShowS
[DistanceType] -> ShowS
DistanceType -> String
(Int -> DistanceType -> ShowS)
-> (DistanceType -> String)
-> ([DistanceType] -> ShowS)
-> Show DistanceType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DistanceType] -> ShowS
$cshowList :: [DistanceType] -> ShowS
show :: DistanceType -> String
$cshow :: DistanceType -> String
showsPrec :: Int -> DistanceType -> ShowS
$cshowsPrec :: Int -> DistanceType -> ShowS
Show)

instance ToJSON DistanceType where
  toJSON :: DistanceType -> Value
toJSON DistanceType
Arc       = Text -> Value
String Text
"arc"
  toJSON DistanceType
SloppyArc = Text -> Value
String Text
"sloppy_arc"
  toJSON DistanceType
Plane     = Text -> Value
String Text
"plane"

instance FromJSON DistanceType where
  parseJSON :: Value -> Parser DistanceType
parseJSON = String
-> (Text -> Parser DistanceType) -> Value -> Parser DistanceType
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"DistanceType" Text -> Parser DistanceType
forall a (f :: * -> *).
(Eq a, IsString a, MonadFail f, Show a) =>
a -> f DistanceType
parse
    where parse :: a -> f DistanceType
parse a
"arc"        = DistanceType -> f DistanceType
forall (f :: * -> *) a. Applicative f => a -> f a
pure DistanceType
Arc
          parse a
"sloppy_arc" = DistanceType -> f DistanceType
forall (f :: * -> *) a. Applicative f => a -> f a
pure DistanceType
SloppyArc
          parse a
"plane"      = DistanceType -> f DistanceType
forall (f :: * -> *) a. Applicative f => a -> f a
pure DistanceType
Plane
          parse a
t            = String -> f DistanceType
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"Unrecognized DistanceType: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> a -> String
forall a. Show a => a -> String
show a
t)

data OptimizeBbox = OptimizeGeoFilterType GeoFilterType
                  | NoOptimizeBbox deriving (OptimizeBbox -> OptimizeBbox -> Bool
(OptimizeBbox -> OptimizeBbox -> Bool)
-> (OptimizeBbox -> OptimizeBbox -> Bool) -> Eq OptimizeBbox
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OptimizeBbox -> OptimizeBbox -> Bool
$c/= :: OptimizeBbox -> OptimizeBbox -> Bool
== :: OptimizeBbox -> OptimizeBbox -> Bool
$c== :: OptimizeBbox -> OptimizeBbox -> Bool
Eq, Int -> OptimizeBbox -> ShowS
[OptimizeBbox] -> ShowS
OptimizeBbox -> String
(Int -> OptimizeBbox -> ShowS)
-> (OptimizeBbox -> String)
-> ([OptimizeBbox] -> ShowS)
-> Show OptimizeBbox
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OptimizeBbox] -> ShowS
$cshowList :: [OptimizeBbox] -> ShowS
show :: OptimizeBbox -> String
$cshow :: OptimizeBbox -> String
showsPrec :: Int -> OptimizeBbox -> ShowS
$cshowsPrec :: Int -> OptimizeBbox -> ShowS
Show)


instance ToJSON OptimizeBbox where
  toJSON :: OptimizeBbox -> Value
toJSON OptimizeBbox
NoOptimizeBbox              = Text -> Value
String Text
"none"
  toJSON (OptimizeGeoFilterType GeoFilterType
gft) = GeoFilterType -> Value
forall a. ToJSON a => a -> Value
toJSON GeoFilterType
gft

instance FromJSON OptimizeBbox where
  parseJSON :: Value -> Parser OptimizeBbox
parseJSON Value
v = String
-> (Text -> Parser OptimizeBbox) -> Value -> Parser OptimizeBbox
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"NoOptimizeBbox" Text -> Parser OptimizeBbox
forall a (f :: * -> *).
(Eq a, IsString a, MonadPlus f) =>
a -> f OptimizeBbox
parseNoOptimize Value
v
            Parser OptimizeBbox -> Parser OptimizeBbox -> Parser OptimizeBbox
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Value -> Parser OptimizeBbox
parseOptimize Value
v
    where parseNoOptimize :: a -> f OptimizeBbox
parseNoOptimize a
"none" = OptimizeBbox -> f OptimizeBbox
forall (f :: * -> *) a. Applicative f => a -> f a
pure OptimizeBbox
NoOptimizeBbox
          parseNoOptimize a
_      = f OptimizeBbox
forall (m :: * -> *) a. MonadPlus m => m a
mzero
          parseOptimize :: Value -> Parser OptimizeBbox
parseOptimize = (GeoFilterType -> OptimizeBbox)
-> Parser GeoFilterType -> Parser OptimizeBbox
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap GeoFilterType -> OptimizeBbox
OptimizeGeoFilterType (Parser GeoFilterType -> Parser OptimizeBbox)
-> (Value -> Parser GeoFilterType) -> Value -> Parser OptimizeBbox
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value -> Parser GeoFilterType
forall a. FromJSON a => Value -> Parser a
parseJSON

data Distance =
  Distance { Distance -> Double
coefficient :: Double
           , Distance -> DistanceUnit
unit        :: DistanceUnit } deriving (Distance -> Distance -> Bool
(Distance -> Distance -> Bool)
-> (Distance -> Distance -> Bool) -> Eq Distance
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Distance -> Distance -> Bool
$c/= :: Distance -> Distance -> Bool
== :: Distance -> Distance -> Bool
$c== :: Distance -> Distance -> Bool
Eq, Int -> Distance -> ShowS
[Distance] -> ShowS
Distance -> String
(Int -> Distance -> ShowS)
-> (Distance -> String) -> ([Distance] -> ShowS) -> Show Distance
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Distance] -> ShowS
$cshowList :: [Distance] -> ShowS
show :: Distance -> String
$cshow :: Distance -> String
showsPrec :: Int -> Distance -> ShowS
$cshowsPrec :: Int -> Distance -> ShowS
Show)


instance ToJSON Distance where
  toJSON :: Distance -> Value
toJSON (Distance Double
dCoefficient DistanceUnit
dUnit) =
    Text -> Value
String Text
boltedTogether where
      coefText :: Text
coefText = Double -> Text
forall a. Show a => a -> Text
showText Double
dCoefficient
      (String Text
unitText) = DistanceUnit -> Value
forall a. ToJSON a => a -> Value
toJSON DistanceUnit
dUnit
      boltedTogether :: Text
boltedTogether = Text -> Text -> Text
forall a. Monoid a => a -> a -> a
mappend Text
coefText Text
unitText

instance FromJSON Distance where
  parseJSON :: Value -> Parser Distance
parseJSON = String -> (Text -> Parser Distance) -> Value -> Parser Distance
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"Distance" Text -> Parser Distance
parse
    where parse :: Text -> Parser Distance
parse Text
t = Double -> DistanceUnit -> Distance
Distance (Double -> DistanceUnit -> Distance)
-> Parser Double -> Parser (DistanceUnit -> Distance)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> Parser Double
forall (m :: * -> *) a. (MonadFail m, Read a) => Text -> m a
parseCoeff Text
nT
                             Parser (DistanceUnit -> Distance)
-> Parser DistanceUnit -> Parser Distance
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Value -> Parser DistanceUnit
forall a. FromJSON a => Value -> Parser a
parseJSON (Text -> Value
String Text
unitT)
            where (Text
nT, Text
unitT) = (Char -> Bool) -> Text -> (Text, Text)
T.span Char -> Bool
validForNumber Text
t
                  -- may be a better way to do this
                  validForNumber :: Char -> Bool
validForNumber Char
'-' = Bool
True
                  validForNumber Char
'.' = Bool
True
                  validForNumber Char
'e' = Bool
True
                  validForNumber Char
c   = Char -> Bool
isNumber Char
c
                  parseCoeff :: Text -> m a
parseCoeff Text
"" = String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Empty string cannot be parsed as number"
                  parseCoeff Text
s = a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> a
forall a. Read a => String -> a
read (Text -> String
T.unpack Text
s))

data DistanceRange =
  DistanceRange { DistanceRange -> Distance
distanceFrom :: Distance
                , DistanceRange -> Distance
distanceTo   :: Distance } deriving (DistanceRange -> DistanceRange -> Bool
(DistanceRange -> DistanceRange -> Bool)
-> (DistanceRange -> DistanceRange -> Bool) -> Eq DistanceRange
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DistanceRange -> DistanceRange -> Bool
$c/= :: DistanceRange -> DistanceRange -> Bool
== :: DistanceRange -> DistanceRange -> Bool
$c== :: DistanceRange -> DistanceRange -> Bool
Eq, Int -> DistanceRange -> ShowS
[DistanceRange] -> ShowS
DistanceRange -> String
(Int -> DistanceRange -> ShowS)
-> (DistanceRange -> String)
-> ([DistanceRange] -> ShowS)
-> Show DistanceRange
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DistanceRange] -> ShowS
$cshowList :: [DistanceRange] -> ShowS
show :: DistanceRange -> String
$cshow :: DistanceRange -> String
showsPrec :: Int -> DistanceRange -> ShowS
$cshowsPrec :: Int -> DistanceRange -> ShowS
Show)

type TemplateQueryValue = Text

newtype TemplateQueryKeyValuePairs =
  TemplateQueryKeyValuePairs (X.KeyMap TemplateQueryValue)
  deriving (TemplateQueryKeyValuePairs -> TemplateQueryKeyValuePairs -> Bool
(TemplateQueryKeyValuePairs -> TemplateQueryKeyValuePairs -> Bool)
-> (TemplateQueryKeyValuePairs
    -> TemplateQueryKeyValuePairs -> Bool)
-> Eq TemplateQueryKeyValuePairs
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TemplateQueryKeyValuePairs -> TemplateQueryKeyValuePairs -> Bool
$c/= :: TemplateQueryKeyValuePairs -> TemplateQueryKeyValuePairs -> Bool
== :: TemplateQueryKeyValuePairs -> TemplateQueryKeyValuePairs -> Bool
$c== :: TemplateQueryKeyValuePairs -> TemplateQueryKeyValuePairs -> Bool
Eq, Int -> TemplateQueryKeyValuePairs -> ShowS
[TemplateQueryKeyValuePairs] -> ShowS
TemplateQueryKeyValuePairs -> String
(Int -> TemplateQueryKeyValuePairs -> ShowS)
-> (TemplateQueryKeyValuePairs -> String)
-> ([TemplateQueryKeyValuePairs] -> ShowS)
-> Show TemplateQueryKeyValuePairs
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TemplateQueryKeyValuePairs] -> ShowS
$cshowList :: [TemplateQueryKeyValuePairs] -> ShowS
show :: TemplateQueryKeyValuePairs -> String
$cshow :: TemplateQueryKeyValuePairs -> String
showsPrec :: Int -> TemplateQueryKeyValuePairs -> ShowS
$cshowsPrec :: Int -> TemplateQueryKeyValuePairs -> ShowS
Show)

instance ToJSON TemplateQueryKeyValuePairs where
  toJSON :: TemplateQueryKeyValuePairs -> Value
toJSON (TemplateQueryKeyValuePairs KeyMap Text
x) = Object -> Value
Object (Object -> Value) -> Object -> Value
forall a b. (a -> b) -> a -> b
$ Text -> Value
String (Text -> Value) -> KeyMap Text -> Object
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> KeyMap Text
x

instance FromJSON TemplateQueryKeyValuePairs where
  parseJSON :: Value -> Parser TemplateQueryKeyValuePairs
parseJSON (Object Object
o) =
    TemplateQueryKeyValuePairs -> Parser TemplateQueryKeyValuePairs
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TemplateQueryKeyValuePairs -> Parser TemplateQueryKeyValuePairs)
-> (KeyMap Text -> TemplateQueryKeyValuePairs)
-> KeyMap Text
-> Parser TemplateQueryKeyValuePairs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. KeyMap Text -> TemplateQueryKeyValuePairs
TemplateQueryKeyValuePairs (KeyMap Text -> Parser TemplateQueryKeyValuePairs)
-> KeyMap Text -> Parser TemplateQueryKeyValuePairs
forall a b. (a -> b) -> a -> b
$ (Value -> Maybe Text) -> Object -> KeyMap Text
forall a b. (a -> Maybe b) -> KeyMap a -> KeyMap b
X.mapMaybe Value -> Maybe Text
getValue Object
o
    where getValue :: Value -> Maybe Text
getValue (String Text
x) = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
x
          getValue Value
_          = Maybe Text
forall a. Maybe a
Nothing
  parseJSON Value
_          =
    String -> Parser TemplateQueryKeyValuePairs
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"error parsing TemplateQueryKeyValuePairs"

{-| 'BooleanOperator' is the usual And/Or operators with an ES compatible
    JSON encoding baked in. Used all over the place.
-}
data BooleanOperator = And | Or deriving (BooleanOperator -> BooleanOperator -> Bool
(BooleanOperator -> BooleanOperator -> Bool)
-> (BooleanOperator -> BooleanOperator -> Bool)
-> Eq BooleanOperator
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BooleanOperator -> BooleanOperator -> Bool
$c/= :: BooleanOperator -> BooleanOperator -> Bool
== :: BooleanOperator -> BooleanOperator -> Bool
$c== :: BooleanOperator -> BooleanOperator -> Bool
Eq, Int -> BooleanOperator -> ShowS
[BooleanOperator] -> ShowS
BooleanOperator -> String
(Int -> BooleanOperator -> ShowS)
-> (BooleanOperator -> String)
-> ([BooleanOperator] -> ShowS)
-> Show BooleanOperator
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BooleanOperator] -> ShowS
$cshowList :: [BooleanOperator] -> ShowS
show :: BooleanOperator -> String
$cshow :: BooleanOperator -> String
showsPrec :: Int -> BooleanOperator -> ShowS
$cshowsPrec :: Int -> BooleanOperator -> ShowS
Show)

instance ToJSON BooleanOperator where
  toJSON :: BooleanOperator -> Value
toJSON BooleanOperator
And = Text -> Value
String Text
"and"
  toJSON BooleanOperator
Or  = Text -> Value
String Text
"or"

instance FromJSON BooleanOperator where
  parseJSON :: Value -> Parser BooleanOperator
parseJSON = String
-> (Text -> Parser BooleanOperator)
-> Value
-> Parser BooleanOperator
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"BooleanOperator" Text -> Parser BooleanOperator
forall a (f :: * -> *).
(Eq a, IsString a, MonadFail f, Show a) =>
a -> f BooleanOperator
parse
    where parse :: a -> f BooleanOperator
parse a
"and" = BooleanOperator -> f BooleanOperator
forall (f :: * -> *) a. Applicative f => a -> f a
pure BooleanOperator
And
          parse a
"or"  = BooleanOperator -> f BooleanOperator
forall (f :: * -> *) a. Applicative f => a -> f a
pure BooleanOperator
Or
          parse a
o     = String -> f BooleanOperator
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"Unexpected BooleanOperator: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> a -> String
forall a. Show a => a -> String
show a
o)

{-| 'Cache' is for telling ES whether it should cache a 'Filter' not.
    'Query's cannot be cached.
-}
type Cache   = Bool -- caching on/off
defaultCache :: Cache
defaultCache :: Bool
defaultCache = Bool
False


data FunctionScoreQuery =
  FunctionScoreQuery { FunctionScoreQuery -> Maybe Query
functionScoreQuery     :: Maybe Query
                     , FunctionScoreQuery -> Maybe Boost
functionScoreBoost     :: Maybe Boost
                     , FunctionScoreQuery -> FunctionScoreFunctions
functionScoreFunctions :: FunctionScoreFunctions
                     , FunctionScoreQuery -> Maybe Boost
functionScoreMaxBoost  :: Maybe Boost
                     , FunctionScoreQuery -> Maybe BoostMode
functionScoreBoostMode :: Maybe BoostMode
                     , FunctionScoreQuery -> Score
functionScoreMinScore  :: Score
                     , FunctionScoreQuery -> Maybe ScoreMode
functionScoreScoreMode :: Maybe ScoreMode
                     } deriving (FunctionScoreQuery -> FunctionScoreQuery -> Bool
(FunctionScoreQuery -> FunctionScoreQuery -> Bool)
-> (FunctionScoreQuery -> FunctionScoreQuery -> Bool)
-> Eq FunctionScoreQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FunctionScoreQuery -> FunctionScoreQuery -> Bool
$c/= :: FunctionScoreQuery -> FunctionScoreQuery -> Bool
== :: FunctionScoreQuery -> FunctionScoreQuery -> Bool
$c== :: FunctionScoreQuery -> FunctionScoreQuery -> Bool
Eq, Int -> FunctionScoreQuery -> ShowS
[FunctionScoreQuery] -> ShowS
FunctionScoreQuery -> String
(Int -> FunctionScoreQuery -> ShowS)
-> (FunctionScoreQuery -> String)
-> ([FunctionScoreQuery] -> ShowS)
-> Show FunctionScoreQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FunctionScoreQuery] -> ShowS
$cshowList :: [FunctionScoreQuery] -> ShowS
show :: FunctionScoreQuery -> String
$cshow :: FunctionScoreQuery -> String
showsPrec :: Int -> FunctionScoreQuery -> ShowS
$cshowsPrec :: Int -> FunctionScoreQuery -> ShowS
Show)

instance ToJSON FunctionScoreQuery where
  toJSON :: FunctionScoreQuery -> Value
toJSON (FunctionScoreQuery Maybe Query
query Maybe Boost
boost FunctionScoreFunctions
fns Maybe Boost
maxBoost Maybe BoostMode
boostMode Score
minScore Maybe ScoreMode
scoreMode) =
    [Pair] -> Value
omitNulls [Pair]
base
    where base :: [Pair]
base = FunctionScoreFunctions -> Pair
functionScoreFunctionsPair FunctionScoreFunctions
fns Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
:
                 [ Key
"query"      Key -> Maybe Query -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Query
query
                 , Key
"boost"      Key -> Maybe Boost -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Boost
boost
                 , Key
"max_boost"  Key -> Maybe Boost -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Boost
maxBoost
                 , Key
"boost_mode" Key -> Maybe BoostMode -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe BoostMode
boostMode
                 , Key
"min_score"  Key -> Score -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Score
minScore
                 , Key
"score_mode" Key -> Maybe ScoreMode -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe ScoreMode
scoreMode ]

instance FromJSON FunctionScoreQuery where
  parseJSON :: Value -> Parser FunctionScoreQuery
parseJSON = String
-> (Object -> Parser FunctionScoreQuery)
-> Value
-> Parser FunctionScoreQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"FunctionScoreQuery" Object -> Parser FunctionScoreQuery
parse
    where parse :: Object -> Parser FunctionScoreQuery
parse Object
o = Maybe Query
-> Maybe Boost
-> FunctionScoreFunctions
-> Maybe Boost
-> Maybe BoostMode
-> Score
-> Maybe ScoreMode
-> FunctionScoreQuery
FunctionScoreQuery
                    (Maybe Query
 -> Maybe Boost
 -> FunctionScoreFunctions
 -> Maybe Boost
 -> Maybe BoostMode
 -> Score
 -> Maybe ScoreMode
 -> FunctionScoreQuery)
-> Parser (Maybe Query)
-> Parser
     (Maybe Boost
      -> FunctionScoreFunctions
      -> Maybe Boost
      -> Maybe BoostMode
      -> Score
      -> Maybe ScoreMode
      -> FunctionScoreQuery)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe Query)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"query"
                    Parser
  (Maybe Boost
   -> FunctionScoreFunctions
   -> Maybe Boost
   -> Maybe BoostMode
   -> Score
   -> Maybe ScoreMode
   -> FunctionScoreQuery)
-> Parser (Maybe Boost)
-> Parser
     (FunctionScoreFunctions
      -> Maybe Boost
      -> Maybe BoostMode
      -> Score
      -> Maybe ScoreMode
      -> FunctionScoreQuery)
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
  (FunctionScoreFunctions
   -> Maybe Boost
   -> Maybe BoostMode
   -> Score
   -> Maybe ScoreMode
   -> FunctionScoreQuery)
-> Parser FunctionScoreFunctions
-> Parser
     (Maybe Boost
      -> Maybe BoostMode
      -> Score
      -> Maybe ScoreMode
      -> FunctionScoreQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Object -> Parser FunctionScoreFunctions
singleFunction Object
o
                          Parser FunctionScoreFunctions
-> Parser FunctionScoreFunctions -> Parser FunctionScoreFunctions
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> NonEmpty ComponentFunctionScoreFunction
-> Parser FunctionScoreFunctions
multipleFunctions (NonEmpty ComponentFunctionScoreFunction
 -> Parser FunctionScoreFunctions)
-> Key -> Parser FunctionScoreFunctions
forall a b. FromJSON a => (a -> Parser b) -> Key -> Parser b
`taggedWith` Key
"functions")
                    Parser
  (Maybe Boost
   -> Maybe BoostMode
   -> Score
   -> Maybe ScoreMode
   -> FunctionScoreQuery)
-> Parser (Maybe Boost)
-> Parser
     (Maybe BoostMode -> Score -> Maybe ScoreMode -> FunctionScoreQuery)
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
"max_boost"
                    Parser
  (Maybe BoostMode -> Score -> Maybe ScoreMode -> FunctionScoreQuery)
-> Parser (Maybe BoostMode)
-> Parser (Score -> Maybe ScoreMode -> FunctionScoreQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe BoostMode)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"boost_mode"
                    Parser (Score -> Maybe ScoreMode -> FunctionScoreQuery)
-> Parser Score -> Parser (Maybe ScoreMode -> FunctionScoreQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Score
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"min_score"
                    Parser (Maybe ScoreMode -> FunctionScoreQuery)
-> Parser (Maybe ScoreMode) -> Parser FunctionScoreQuery
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe ScoreMode)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"score_mode"
            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
          singleFunction :: Object -> Parser FunctionScoreFunctions
singleFunction = (FunctionScoreFunction -> FunctionScoreFunctions)
-> Parser FunctionScoreFunction -> Parser FunctionScoreFunctions
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap FunctionScoreFunction -> FunctionScoreFunctions
FunctionScoreSingle (Parser FunctionScoreFunction -> Parser FunctionScoreFunctions)
-> (Object -> Parser FunctionScoreFunction)
-> Object
-> Parser FunctionScoreFunctions
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Object -> Parser FunctionScoreFunction
parseFunctionScoreFunction
          multipleFunctions :: NonEmpty ComponentFunctionScoreFunction
-> Parser FunctionScoreFunctions
multipleFunctions = FunctionScoreFunctions -> Parser FunctionScoreFunctions
forall (f :: * -> *) a. Applicative f => a -> f a
pure (FunctionScoreFunctions -> Parser FunctionScoreFunctions)
-> (NonEmpty ComponentFunctionScoreFunction
    -> FunctionScoreFunctions)
-> NonEmpty ComponentFunctionScoreFunction
-> Parser FunctionScoreFunctions
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty ComponentFunctionScoreFunction -> FunctionScoreFunctions
FunctionScoreMultiple

data FunctionScoreFunctions =
  FunctionScoreSingle FunctionScoreFunction
  | FunctionScoreMultiple (NonEmpty ComponentFunctionScoreFunction) deriving (FunctionScoreFunctions -> FunctionScoreFunctions -> Bool
(FunctionScoreFunctions -> FunctionScoreFunctions -> Bool)
-> (FunctionScoreFunctions -> FunctionScoreFunctions -> Bool)
-> Eq FunctionScoreFunctions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FunctionScoreFunctions -> FunctionScoreFunctions -> Bool
$c/= :: FunctionScoreFunctions -> FunctionScoreFunctions -> Bool
== :: FunctionScoreFunctions -> FunctionScoreFunctions -> Bool
$c== :: FunctionScoreFunctions -> FunctionScoreFunctions -> Bool
Eq, Int -> FunctionScoreFunctions -> ShowS
[FunctionScoreFunctions] -> ShowS
FunctionScoreFunctions -> String
(Int -> FunctionScoreFunctions -> ShowS)
-> (FunctionScoreFunctions -> String)
-> ([FunctionScoreFunctions] -> ShowS)
-> Show FunctionScoreFunctions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FunctionScoreFunctions] -> ShowS
$cshowList :: [FunctionScoreFunctions] -> ShowS
show :: FunctionScoreFunctions -> String
$cshow :: FunctionScoreFunctions -> String
showsPrec :: Int -> FunctionScoreFunctions -> ShowS
$cshowsPrec :: Int -> FunctionScoreFunctions -> ShowS
Show)

data ComponentFunctionScoreFunction =
  ComponentFunctionScoreFunction { ComponentFunctionScoreFunction -> Maybe Filter
componentScoreFunctionFilter :: Maybe Filter
                                 , ComponentFunctionScoreFunction -> FunctionScoreFunction
componentScoreFunction       :: FunctionScoreFunction
                                 , ComponentFunctionScoreFunction -> Maybe Weight
componentScoreFunctionWeight :: Maybe Weight
                                 } deriving (ComponentFunctionScoreFunction
-> ComponentFunctionScoreFunction -> Bool
(ComponentFunctionScoreFunction
 -> ComponentFunctionScoreFunction -> Bool)
-> (ComponentFunctionScoreFunction
    -> ComponentFunctionScoreFunction -> Bool)
-> Eq ComponentFunctionScoreFunction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ComponentFunctionScoreFunction
-> ComponentFunctionScoreFunction -> Bool
$c/= :: ComponentFunctionScoreFunction
-> ComponentFunctionScoreFunction -> Bool
== :: ComponentFunctionScoreFunction
-> ComponentFunctionScoreFunction -> Bool
$c== :: ComponentFunctionScoreFunction
-> ComponentFunctionScoreFunction -> Bool
Eq, Int -> ComponentFunctionScoreFunction -> ShowS
[ComponentFunctionScoreFunction] -> ShowS
ComponentFunctionScoreFunction -> String
(Int -> ComponentFunctionScoreFunction -> ShowS)
-> (ComponentFunctionScoreFunction -> String)
-> ([ComponentFunctionScoreFunction] -> ShowS)
-> Show ComponentFunctionScoreFunction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ComponentFunctionScoreFunction] -> ShowS
$cshowList :: [ComponentFunctionScoreFunction] -> ShowS
show :: ComponentFunctionScoreFunction -> String
$cshow :: ComponentFunctionScoreFunction -> String
showsPrec :: Int -> ComponentFunctionScoreFunction -> ShowS
$cshowsPrec :: Int -> ComponentFunctionScoreFunction -> ShowS
Show)

instance ToJSON ComponentFunctionScoreFunction where
  toJSON :: ComponentFunctionScoreFunction -> Value
toJSON (ComponentFunctionScoreFunction Maybe Filter
filter' FunctionScoreFunction
fn Maybe Weight
weight) =
    [Pair] -> Value
omitNulls [Pair]
base
    where base :: [Pair]
base = FunctionScoreFunction -> Pair
functionScoreFunctionPair FunctionScoreFunction
fn Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
:
                 [ Key
"filter" Key -> Maybe Filter -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Filter
filter'
                 , Key
"weight" Key -> Maybe Weight -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Weight
weight ]

instance FromJSON ComponentFunctionScoreFunction where
  parseJSON :: Value -> Parser ComponentFunctionScoreFunction
parseJSON = String
-> (Object -> Parser ComponentFunctionScoreFunction)
-> Value
-> Parser ComponentFunctionScoreFunction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"ComponentFunctionScoreFunction" Object -> Parser ComponentFunctionScoreFunction
parse
    where parse :: Object -> Parser ComponentFunctionScoreFunction
parse Object
o = Maybe Filter
-> FunctionScoreFunction
-> Maybe Weight
-> ComponentFunctionScoreFunction
ComponentFunctionScoreFunction
                    (Maybe Filter
 -> FunctionScoreFunction
 -> Maybe Weight
 -> ComponentFunctionScoreFunction)
-> Parser (Maybe Filter)
-> Parser
     (FunctionScoreFunction
      -> Maybe Weight -> ComponentFunctionScoreFunction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe Filter)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"filter"
                    Parser
  (FunctionScoreFunction
   -> Maybe Weight -> ComponentFunctionScoreFunction)
-> Parser FunctionScoreFunction
-> Parser (Maybe Weight -> ComponentFunctionScoreFunction)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> Parser FunctionScoreFunction
parseFunctionScoreFunction Object
o
                    Parser (Maybe Weight -> ComponentFunctionScoreFunction)
-> Parser (Maybe Weight) -> Parser ComponentFunctionScoreFunction
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Weight)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"weight"

functionScoreFunctionsPair :: FunctionScoreFunctions -> (Key, Value)
functionScoreFunctionsPair :: FunctionScoreFunctions -> Pair
functionScoreFunctionsPair (FunctionScoreSingle FunctionScoreFunction
fn)
  = FunctionScoreFunction -> Pair
functionScoreFunctionPair FunctionScoreFunction
fn
functionScoreFunctionsPair (FunctionScoreMultiple NonEmpty ComponentFunctionScoreFunction
componentFns) =
  (Key
"functions", NonEmpty ComponentFunctionScoreFunction -> Value
forall a. ToJSON a => a -> Value
toJSON NonEmpty ComponentFunctionScoreFunction
componentFns)

fieldTagged :: (Monad m, MonadFail m)=> (FieldName -> Object -> m a) -> Object -> m a
fieldTagged :: (FieldName -> Object -> m a) -> Object -> m a
fieldTagged FieldName -> Object -> m a
f Object
o = case Object -> [Pair]
forall v. KeyMap v -> [(Key, v)]
X.toList Object
o of
                    [(Key
k, Object Object
o')] -> FieldName -> Object -> m a
f (Text -> FieldName
FieldName (Text -> FieldName) -> Text -> FieldName
forall a b. (a -> b) -> a -> b
$ Key -> Text
toText Key
k) Object
o'
                    [Pair]
_ -> String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Expected object with 1 field-named key"

-- | Fuzziness value as a number or 'AUTO'.
-- See:
-- https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#fuzziness
data Fuzziness = Fuzziness Double | FuzzinessAuto
  deriving (Fuzziness -> Fuzziness -> Bool
(Fuzziness -> Fuzziness -> Bool)
-> (Fuzziness -> Fuzziness -> Bool) -> Eq Fuzziness
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Fuzziness -> Fuzziness -> Bool
$c/= :: Fuzziness -> Fuzziness -> Bool
== :: Fuzziness -> Fuzziness -> Bool
$c== :: Fuzziness -> Fuzziness -> Bool
Eq, Int -> Fuzziness -> ShowS
[Fuzziness] -> ShowS
Fuzziness -> String
(Int -> Fuzziness -> ShowS)
-> (Fuzziness -> String)
-> ([Fuzziness] -> ShowS)
-> Show Fuzziness
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Fuzziness] -> ShowS
$cshowList :: [Fuzziness] -> ShowS
show :: Fuzziness -> String
$cshow :: Fuzziness -> String
showsPrec :: Int -> Fuzziness -> ShowS
$cshowsPrec :: Int -> Fuzziness -> ShowS
Show)

instance ToJSON Fuzziness where
  toJSON :: Fuzziness -> Value
toJSON (Fuzziness Double
n) = Double -> Value
forall a. ToJSON a => a -> Value
toJSON Double
n
  toJSON Fuzziness
FuzzinessAuto = Text -> Value
String Text
"AUTO"

instance FromJSON Fuzziness where
  parseJSON :: Value -> Parser Fuzziness
parseJSON (String Text
"AUTO") = Fuzziness -> Parser Fuzziness
forall (m :: * -> *) a. Monad m => a -> m a
return Fuzziness
FuzzinessAuto
  parseJSON Value
v               = Double -> Fuzziness
Fuzziness (Double -> Fuzziness) -> Parser Double -> Parser Fuzziness
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser Double
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v

data InnerHits = InnerHits
  { InnerHits -> Maybe Integer
innerHitsFrom :: Maybe Integer
  , InnerHits -> Maybe Integer
innerHitsSize :: Maybe Integer
  } deriving (InnerHits -> InnerHits -> Bool
(InnerHits -> InnerHits -> Bool)
-> (InnerHits -> InnerHits -> Bool) -> Eq InnerHits
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InnerHits -> InnerHits -> Bool
$c/= :: InnerHits -> InnerHits -> Bool
== :: InnerHits -> InnerHits -> Bool
$c== :: InnerHits -> InnerHits -> Bool
Eq, Int -> InnerHits -> ShowS
[InnerHits] -> ShowS
InnerHits -> String
(Int -> InnerHits -> ShowS)
-> (InnerHits -> String)
-> ([InnerHits] -> ShowS)
-> Show InnerHits
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InnerHits] -> ShowS
$cshowList :: [InnerHits] -> ShowS
show :: InnerHits -> String
$cshow :: InnerHits -> String
showsPrec :: Int -> InnerHits -> ShowS
$cshowsPrec :: Int -> InnerHits -> ShowS
Show)

instance ToJSON InnerHits where
  toJSON :: InnerHits -> Value
toJSON (InnerHits Maybe Integer
ihFrom Maybe Integer
ihSize) =
    [Pair] -> Value
omitNulls [ Key
"from" Key -> Maybe Integer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Integer
ihFrom
              , Key
"size" Key -> Maybe Integer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Integer
ihSize
              ]

instance FromJSON InnerHits where
  parseJSON :: Value -> Parser InnerHits
parseJSON = String -> (Object -> Parser InnerHits) -> Value -> Parser InnerHits
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"InnerHits" Object -> Parser InnerHits
parse
    where parse :: Object -> Parser InnerHits
parse Object
o = Maybe Integer -> Maybe Integer -> InnerHits
InnerHits
                    (Maybe Integer -> Maybe Integer -> InnerHits)
-> Parser (Maybe Integer) -> Parser (Maybe Integer -> InnerHits)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"from"
                    Parser (Maybe Integer -> InnerHits)
-> Parser (Maybe Integer) -> Parser InnerHits
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"size"