Merge branch 'master' of github.com:bitemyapp/bloodhound

This commit is contained in:
Chris Allen 2018-05-05 14:20:57 -05:00
commit c20f3034b2
4 changed files with 38 additions and 1 deletions

View File

@ -16,6 +16,8 @@
- @rvl
- Add [character filters][] to the `AnalyzerDefinition` type.
- Add the "stemmer" and "stop" [token filters][] to `TokenFilterDefinition`.
- @ahodgen
- Add support for wildcard queries
[Character Filters]: https://www.elastic.co/guide/en/elasticsearch/reference/5.6/analysis-charfilters.html
[Token Filters]: https://www.elastic.co/guide/en/elasticsearch/reference/5.6/analysis-tokenfilters.html

View File

@ -47,6 +47,7 @@ data Query =
| QueryExistsQuery FieldName
| QueryTemplateQueryInline TemplateQueryInline
| QueryMatchNoneQuery
| QueryWildcardQuery WildcardQuery
deriving (Eq, Show)
instance ToJSON Query where
@ -147,6 +148,9 @@ instance ToJSON Query where
toJSON (QueryTemplateQueryInline templateQuery) =
object [ "template" .= templateQuery ]
toJSON (QueryWildcardQuery query) =
object [ "wildcard" .= query ]
instance FromJSON Query where
parseJSON v = withObject "Query" parse v
where parse o = termQuery `taggedWith` "term"
@ -176,6 +180,7 @@ instance FromJSON Query where
<|> queryRegexpQuery `taggedWith` "regexp"
<|> querySimpleQueryStringQuery `taggedWith` "simple_query_string"
<|> queryTemplateQueryInline `taggedWith` "template"
<|> queryWildcardQuery `taggedWith` "wildcard"
where taggedWith parser k = parser =<< o .: k
termQuery = fieldTagged $ \(FieldName fn) o ->
TermQuery <$> (Term fn <$> o .: "value") <*> o .:? "boost"
@ -215,6 +220,7 @@ instance FromJSON Query where
querySimpleQueryStringQuery = pure . QuerySimpleQueryStringQuery
-- queryExistsQuery o = QueryExistsQuery <$> o .: "field"
queryTemplateQueryInline = pure . QueryTemplateQueryInline
queryWildcardQuery = pure . QueryWildcardQuery
-- | As of Elastic 2.0, 'Filters' are just 'Queries' housed in a
-- Bool Query, and flagged in a different context.
@ -251,6 +257,26 @@ instance FromJSON RegexpQuery where
<*> o .: "flags"
<*> o .:? "boost"
data WildcardQuery =
WildcardQuery { wildcardQueryField :: FieldName
, wildcardQuery :: Text
, wildcardQueryBoost :: Maybe Boost
} deriving (Eq, Show)
instance ToJSON WildcardQuery where
toJSON (WildcardQuery (FieldName wcQueryField)
(wcQueryQuery) wcQueryBoost) =
object [ wcQueryField .= omitNulls base ]
where base = [ "value" .= wcQueryQuery
, "boost" .= wcQueryBoost ]
instance FromJSON WildcardQuery where
parseJSON = withObject "WildcardQuery" parse
where parse = fieldTagged $ \fn o ->
WildcardQuery fn
<$> o .: "value"
<*> o .:? "boost"
data RangeQuery =
RangeQuery { rangeQueryField :: FieldName
, rangeQueryRange :: RangeValue
@ -1219,7 +1245,7 @@ parseRangeValue mkGt mkLt mkGte mkLte
(Nothing, Nothing, Nothing, Nothing) ->
nada
instance FromJSON RangeValue where
parseJSON = withObject "RangeValue" parse
where parse o = parseDate o

View File

@ -218,6 +218,7 @@ module Database.V5.Bloodhound.Types
, QueryString(..)
, TemplateQueryInline(..)
, TemplateQueryKeyValuePairs(..)
, WildcardQuery(..)
, BooleanOperator(..)
, ZeroTermsQuery(..)
, CutoffFrequency(..)

View File

@ -113,3 +113,11 @@ spec =
search = mkSearch (Just templateQuery) Nothing
myTweet <- searchTweet search
liftIO $ myTweet `shouldBe` Right exampleTweet
it "returns document for wildcard query" $ withTestEnv $ do
_ <- insertData
let query = QueryWildcardQuery $ WildcardQuery (FieldName "user") "bitemy*" (Nothing)
let search = mkSearch (Just query) Nothing
myTweet <- searchTweet search
liftIO $
myTweet `shouldBe` Right exampleTweet