mirror of
https://github.com/typeable/bloodhound.git
synced 2024-09-11 08:25:32 +03:00
add V1 support, fix tests
This commit is contained in:
parent
7f00743ad7
commit
1454d6933e
@ -1,5 +1,5 @@
|
||||
name: bloodhound
|
||||
version: 0.15.1.0
|
||||
version: 0.16.0.0
|
||||
synopsis: ElasticSearch client library for Haskell
|
||||
description: ElasticSearch made awesome for Haskell hackers
|
||||
homepage: https://github.com/bitemyapp/bloodhound
|
||||
|
@ -333,6 +333,9 @@ module Database.V1.Bloodhound.Types
|
||||
, SuggestOptions(..)
|
||||
, SuggestResponse(..)
|
||||
, NamedSuggestionResponse(..)
|
||||
, DirectGenerators(..)
|
||||
, mkDirectGenerators
|
||||
, DirectGeneratorSuggestModeTypes (..)
|
||||
|
||||
, Aggregation(..)
|
||||
, Aggregations
|
||||
@ -5382,6 +5385,7 @@ data PhraseSuggester =
|
||||
, phraseSuggesterShardSize :: Maybe Int
|
||||
, phraseSuggesterHighlight :: Maybe PhraseSuggesterHighlighter
|
||||
, phraseSuggesterCollate :: Maybe PhraseSuggesterCollate
|
||||
, phraseSuggesterCandidateGenerators :: [DirectGenerators]
|
||||
}
|
||||
deriving (Show, Generic, Eq, Read, Typeable)
|
||||
|
||||
@ -5397,6 +5401,7 @@ instance ToJSON PhraseSuggester where
|
||||
, "shard_size" .= phraseSuggesterShardSize
|
||||
, "highlight" .= phraseSuggesterHighlight
|
||||
, "collate" .= phraseSuggesterCollate
|
||||
, "direct_generator" .= phraseSuggesterCandidateGenerators
|
||||
]
|
||||
|
||||
instance FromJSON PhraseSuggester where
|
||||
@ -5413,11 +5418,12 @@ instance FromJSON PhraseSuggester where
|
||||
<*> o .:? "shard_size"
|
||||
<*> o .:? "highlight"
|
||||
<*> o .:? "collate"
|
||||
<*> o .:? "direct_generator" .!= []
|
||||
|
||||
mkPhraseSuggester :: FieldName -> PhraseSuggester
|
||||
mkPhraseSuggester fName =
|
||||
PhraseSuggester fName Nothing Nothing Nothing Nothing Nothing Nothing
|
||||
Nothing Nothing Nothing Nothing
|
||||
Nothing Nothing Nothing Nothing []
|
||||
|
||||
data PhraseSuggesterHighlighter =
|
||||
PhraseSuggesterHighlighter { phraseSuggesterHighlighterPreTag :: Text
|
||||
@ -5507,3 +5513,68 @@ instance FromJSON NamedSuggestionResponse where
|
||||
return $ NamedSuggestionResponse suggestionName' suggestionResponses'
|
||||
|
||||
parseJSON x = typeMismatch "NamedSuggestionResponse" x
|
||||
|
||||
data DirectGeneratorSuggestModeTypes = DirectGeneratorSuggestModeMissing
|
||||
| DirectGeneratorSuggestModePopular
|
||||
| DirectGeneratorSuggestModeAlways
|
||||
deriving (Show, Eq, Read, Generic)
|
||||
|
||||
instance ToJSON DirectGeneratorSuggestModeTypes where
|
||||
toJSON DirectGeneratorSuggestModeMissing = "missing"
|
||||
toJSON DirectGeneratorSuggestModePopular = "popular"
|
||||
toJSON DirectGeneratorSuggestModeAlways = "always"
|
||||
|
||||
instance FromJSON DirectGeneratorSuggestModeTypes where
|
||||
parseJSON = withText "DirectGeneratorSuggestModeTypes" parse
|
||||
where parse "missing" = pure DirectGeneratorSuggestModeMissing
|
||||
parse "popular" = pure DirectGeneratorSuggestModePopular
|
||||
parse "always" = pure DirectGeneratorSuggestModeAlways
|
||||
parse f = fail ("Unexpected DirectGeneratorSuggestModeTypes: " <> show f)
|
||||
|
||||
data DirectGenerators = DirectGenerators
|
||||
{ directGeneratorsField :: FieldName
|
||||
, directGeneratorsSize :: Maybe Int
|
||||
, directGeneratorSuggestMode :: DirectGeneratorSuggestModeTypes
|
||||
, directGeneratorMaxEdits :: Maybe Double
|
||||
, directGeneratorPrefixLength :: Maybe Int
|
||||
, directGeneratorMinWordLength :: Maybe Int
|
||||
, directGeneratorMaxInspections :: Maybe Int
|
||||
, directGeneratorMinDocFreq :: Maybe Double
|
||||
, directGeneratorMaxTermFreq :: Maybe Double
|
||||
, directGeneratorPreFilter :: Maybe Text
|
||||
, directGeneratorPostFilter :: Maybe Text
|
||||
}
|
||||
deriving (Show, Eq, Read, Generic)
|
||||
|
||||
|
||||
instance ToJSON DirectGenerators where
|
||||
toJSON DirectGenerators{..} = omitNulls [ "field" .= directGeneratorsField
|
||||
, "size" .= directGeneratorsSize
|
||||
, "suggest_mode" .= directGeneratorSuggestMode
|
||||
, "max_edits" .= directGeneratorMaxEdits
|
||||
, "prefix_length" .= directGeneratorPrefixLength
|
||||
, "min_word_length" .= directGeneratorMinWordLength
|
||||
, "max_inspections" .= directGeneratorMaxInspections
|
||||
, "min_doc_freq" .= directGeneratorMinDocFreq
|
||||
, "max_term_freq" .= directGeneratorMaxTermFreq
|
||||
, "pre_filter" .= directGeneratorPreFilter
|
||||
, "post_filter" .= directGeneratorPostFilter
|
||||
]
|
||||
|
||||
instance FromJSON DirectGenerators where
|
||||
parseJSON = withObject "DirectGenerators" parse
|
||||
where parse o = DirectGenerators
|
||||
<$> o .: "field"
|
||||
<*> o .:? "size"
|
||||
<*> o .: "suggest_mode"
|
||||
<*> o .:? "max_edits"
|
||||
<*> o .:? "prefix_length"
|
||||
<*> o .:? "min_word_length"
|
||||
<*> o .:? "max_inspections"
|
||||
<*> o .:? "min_doc_freq"
|
||||
<*> o .:? "max_term_freq"
|
||||
<*> o .:? "pre_filter"
|
||||
<*> o .:? "post_filter"
|
||||
|
||||
mkDirectGenerators :: FieldName -> DirectGenerators
|
||||
mkDirectGenerators fn = DirectGenerators fn Nothing DirectGeneratorSuggestModeMissing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
|
||||
|
@ -5429,7 +5429,7 @@ data DirectGeneratorSuggestModeTypes = DirectGeneratorSuggestModeMissing
|
||||
| DirectGeneratorSuggestModePopular
|
||||
| DirectGeneratorSuggestModeAlways
|
||||
deriving (Show, Eq, Read, Generic)
|
||||
|
||||
|
||||
instance ToJSON DirectGeneratorSuggestModeTypes where
|
||||
toJSON DirectGeneratorSuggestModeMissing = "missing"
|
||||
toJSON DirectGeneratorSuggestModePopular = "popular"
|
||||
|
@ -5,13 +5,13 @@ flags:
|
||||
packages:
|
||||
- '.'
|
||||
- './examples'
|
||||
# extra-deps:
|
||||
extra-deps:
|
||||
# - http-client-0.5.0
|
||||
# - aeson-1.2.0.0
|
||||
# - fail-4.9.0.0
|
||||
# - http-types-0.9
|
||||
# - attoparsec-0.13.0.1
|
||||
# - quickcheck-properties-0.1
|
||||
- quickcheck-properties-0.1
|
||||
# - semigroups-0.18.3
|
||||
# - uri-bytestring-0.1.9
|
||||
# - temporary-resourcet-0.1.0.0
|
||||
|
@ -6,4 +6,7 @@ packages:
|
||||
- '.'
|
||||
- './examples'
|
||||
|
||||
extra-deps:
|
||||
- quickcheck-properties-0.1
|
||||
|
||||
resolver: lts-10.0
|
||||
|
@ -607,6 +607,8 @@ instance ApproxEq PhraseSuggesterCollate
|
||||
instance ApproxEq PhraseSuggester
|
||||
instance ApproxEq SuggestType
|
||||
instance ApproxEq Suggest
|
||||
instance ApproxEq DirectGenerators
|
||||
instance ApproxEq DirectGeneratorSuggestModeTypes
|
||||
|
||||
-- | Due to the way nodeattrfilters get serialized here, they may come
|
||||
-- out in a different order, but they are morally equivalent
|
||||
@ -937,6 +939,8 @@ instance Arbitrary Size where arbitrary = sopArbitrary; shrink = genericShrink
|
||||
instance Arbitrary PhraseSuggester where arbitrary = sopArbitrary; shrink = genericShrink
|
||||
instance Arbitrary SuggestType where arbitrary = sopArbitrary; shrink = genericShrink
|
||||
instance Arbitrary Suggest where arbitrary = sopArbitrary; shrink = genericShrink
|
||||
instance Arbitrary DirectGenerators where arbitrary = sopArbitrary; shrink = genericShrink
|
||||
instance Arbitrary DirectGeneratorSuggestModeTypes where arbitrary = sopArbitrary; shrink = genericShrink
|
||||
|
||||
newtype UpdatableIndexSetting' = UpdatableIndexSetting' UpdatableIndexSetting
|
||||
deriving (Show, Eq, ToJSON, FromJSON, ApproxEq, Typeable)
|
||||
@ -1933,6 +1937,8 @@ main = hspec $ do
|
||||
propJSON (Proxy :: Proxy CompoundFormat)
|
||||
propJSON (Proxy :: Proxy TemplateQueryInline)
|
||||
propJSON (Proxy :: Proxy Suggest)
|
||||
propJSON (Proxy :: Proxy DirectGenerators)
|
||||
propJSON (Proxy :: Proxy DirectGeneratorSuggestModeTypes)
|
||||
|
||||
-- Temporary solution for lacking of generic derivation of Arbitrary
|
||||
-- We use generics-sop, as it's much more concise than directly using GHC.Generics
|
||||
|
Loading…
Reference in New Issue
Block a user