git.iko.soy/typeable/bloodhound
on master help sign in
Cleanup
df021caChris Allen
src/Database/V5/Bloodhound/Types.hs+78−62
@@ -518,25 +518,25 @@ data PostingsHighlight =
518 deriving (Eq, Show)
518 deriving (Eq, Show)
519
519
520-- This requires that term_vector is set to 'with_positions_offsets' in the mapping.
520-- This requires that term_vector is set to 'with_positions_offsets' in the mapping.
521−data FastVectorHighlight =
521+data FastVectorHighlight = FastVectorHighlight
522− FastVectorHighlight { fvCommon :: Maybe CommonHighlight
522+ { fvCommon :: Maybe CommonHighlight
523− , fvNonPostSettings :: Maybe NonPostings
523+ , fvNonPostSettings :: Maybe NonPostings
524− , boundaryChars :: Maybe Text
524+ , boundaryChars :: Maybe Text
525− , boundaryMaxScan :: Maybe Int
525+ , boundaryMaxScan :: Maybe Int
526− , fragmentOffset :: Maybe Int
526+ , fragmentOffset :: Maybe Int
527− , matchedFields :: [Text]
527+ , matchedFields :: [Text]
528− , phraseLimit :: Maybe Int
528+ , phraseLimit :: Maybe Int
529− } deriving (Eq, Show)
529+ } deriving (Eq, Show)
530−
530+
531−data CommonHighlight =
531+data CommonHighlight = CommonHighlight
532− CommonHighlight { order :: Maybe Text
532+ { order :: Maybe Text
533− , forceSource :: Maybe Bool
533+ , forceSource :: Maybe Bool
534− , tag :: Maybe HighlightTag
534+ , tag :: Maybe HighlightTag
535− , encoder :: Maybe HighlightEncoder
535+ , encoder :: Maybe HighlightEncoder
536− , noMatchSize :: Maybe Int
536+ , noMatchSize :: Maybe Int
537− , highlightQuery :: Maybe Query
537+ , highlightQuery :: Maybe Query
538− , requireFieldMatch :: Maybe Bool
538+ , requireFieldMatch :: Maybe Bool
539− } deriving (Eq, Show)
539+ } deriving (Eq, Show)
540
540
541-- Settings that are only applicable to FastVector and Plain highlighters.
541-- Settings that are only applicable to FastVector and Plain highlighters.
542data NonPostings =
542data NonPostings =
@@ -824,15 +824,16 @@ fastVectorHighPairs (Just
824
824
825commonHighlightPairs :: Maybe CommonHighlight -> [Pair]
825commonHighlightPairs :: Maybe CommonHighlight -> [Pair]
826commonHighlightPairs Nothing = []
826commonHighlightPairs Nothing = []
827−commonHighlightPairs (Just (CommonHighlight chScore chForceSource chTag chEncoder
827+commonHighlightPairs (Just (CommonHighlight chScore chForceSource
828− chNoMatchSize chHighlightQuery
828+ chTag chEncoder chNoMatchSize
829− chRequireFieldMatch)) =
829+ chHighlightQuery chRequireFieldMatch)) =
830 [ "order" .= chScore
830 [ "order" .= chScore
831 , "force_source" .= chForceSource
831 , "force_source" .= chForceSource
832 , "encoder" .= chEncoder
832 , "encoder" .= chEncoder
833 , "no_match_size" .= chNoMatchSize
833 , "no_match_size" .= chNoMatchSize
834 , "highlight_query" .= chHighlightQuery
834 , "highlight_query" .= chHighlightQuery
835− , "require_fieldMatch" .= chRequireFieldMatch]
835+ , "require_fieldMatch" .= chRequireFieldMatch
836+ ]
836 ++ highlightTagToPairs chTag
837 ++ highlightTagToPairs chTag
837
838
838
839
@@ -840,32 +841,41 @@ nonPostingsToPairs :: Maybe NonPostings -> [Pair]
840nonPostingsToPairs Nothing = []
841nonPostingsToPairs Nothing = []
841nonPostingsToPairs (Just (NonPostings npFragSize npNumOfFrags)) =
842nonPostingsToPairs (Just (NonPostings npFragSize npNumOfFrags)) =
842 [ "fragment_size" .= npFragSize
843 [ "fragment_size" .= npFragSize
843− , "number_of_fragments" .= npNumOfFrags]
844+ , "number_of_fragments" .= npNumOfFrags
845+ ]
844
846
845highlightTagToPairs :: Maybe HighlightTag -> [Pair]
847highlightTagToPairs :: Maybe HighlightTag -> [Pair]
846−highlightTagToPairs (Just (TagSchema _)) = [ "scheme" .= String "default"]
848+highlightTagToPairs (Just (TagSchema _)) =
849+ [ "scheme" .= String "default"
850+ ]
847−highlightTagToPairs (Just (CustomTags (pre, post))) = [ "pre_tags" .= pre
851+highlightTagToPairs (Just (CustomTags (pre, post))) =
852+ [ "pre_tags" .= pre
848− , "post_tags" .= post]
853+ , "post_tags" .= post
854+ ]
849highlightTagToPairs Nothing = []
855highlightTagToPairs Nothing = []
850
856
851−data Suggest = Suggest { suggestText :: Text
857+data Suggest = Suggest
858+ { suggestText :: Text
852− , suggestName :: Text
859+ , suggestName :: Text
853− , suggestType :: SuggestType
860+ , suggestType :: SuggestType
854− }
855− deriving (Eq, Show)
861+ } deriving (Eq, Show)
856
862
857instance ToJSON Suggest where
863instance ToJSON Suggest where
864+ toJSON Suggest{..} =
858− toJSON Suggest{..} = object [ "text" .= suggestText
865+ object [ "text" .= suggestText
859− , suggestName .= suggestType
866+ , suggestName .= suggestType
860− ]
867+ ]
861
868
862instance FromJSON Suggest where
869instance FromJSON Suggest where
863 parseJSON (Object o) = do
870 parseJSON (Object o) = do
864 suggestText' <- o .: "text"
871 suggestText' <- o .: "text"
872+ let dropTextList =
873+ HM.toList
865− let dropTextList = HM.toList $ HM.filterWithKey (\x _ -> x /= "text") o
874+ $ HM.filterWithKey (\x _ -> x /= "text") o
875+ suggestName' <-
866− suggestName' <- case dropTextList of
876+ case dropTextList of
867− [(x, _)] -> return x
877+ [(x, _)] -> return x
868− _ -> fail "error parsing Suggest field name"
878+ _ -> fail "error parsing Suggest field name"
869 suggestType' <- o .: suggestName'
879 suggestType' <- o .: suggestName'
870 return $ Suggest suggestText' suggestName' suggestType'
880 return $ Suggest suggestText' suggestName' suggestType'
871 parseJSON x = typeMismatch "Suggest" x
881 parseJSON x = typeMismatch "Suggest" x
@@ -988,11 +998,12 @@ data SuggestOptions =
988
998
989instance FromJSON SuggestOptions where
999instance FromJSON SuggestOptions where
990 parseJSON = withObject "SuggestOptions" parse
1000 parseJSON = withObject "SuggestOptions" parse
1001+ where
991− where parse o = SuggestOptions
1002+ parse o = SuggestOptions
992− <$> o .: "text"
1003+ <$> o .: "text"
993− <*> o .: "score"
1004+ <*> o .: "score"
994− <*> o .:? "freq"
1005+ <*> o .:? "freq"
995− <*> o .:? "highlighted"
1006+ <*> o .:? "highlighted"
996
1007
997data SuggestResponse =
1008data SuggestResponse =
998 SuggestResponse { suggestResponseText :: Text
1009 SuggestResponse { suggestResponseText :: Text
@@ -1037,10 +1048,15 @@ instance ToJSON DirectGeneratorSuggestModeTypes where
1037
1048
1038instance FromJSON DirectGeneratorSuggestModeTypes where
1049instance FromJSON DirectGeneratorSuggestModeTypes where
1039 parseJSON = withText "DirectGeneratorSuggestModeTypes" parse
1050 parseJSON = withText "DirectGeneratorSuggestModeTypes" parse
1051+ where
1052+ parse "missing" =
1040− where parse "missing" = pure DirectGeneratorSuggestModeMissing
1053+ pure DirectGeneratorSuggestModeMissing
1054+ parse "popular" =
1041− parse "popular" = pure DirectGeneratorSuggestModePopular
1055+ pure DirectGeneratorSuggestModePopular
1056+ parse "always" =
1042− parse "always" = pure DirectGeneratorSuggestModeAlways
1057+ pure DirectGeneratorSuggestModeAlways
1058+ parse f =
1043− parse f = fail ("Unexpected DirectGeneratorSuggestModeTypes: " <> show f)
1059+ fail ("Unexpected DirectGeneratorSuggestModeTypes: " <> show f)
1044
1060
1045data DirectGenerators = DirectGenerators
1061data DirectGenerators = DirectGenerators
1046 { directGeneratorsField :: FieldName
1062 { directGeneratorsField :: FieldName
@@ -1054,22 +1070,22 @@ data DirectGenerators = DirectGenerators
1054 , directGeneratorMaxTermFreq :: Maybe Double
1070 , directGeneratorMaxTermFreq :: Maybe Double
1055 , directGeneratorPreFilter :: Maybe Text
1071 , directGeneratorPreFilter :: Maybe Text
1056 , directGeneratorPostFilter :: Maybe Text
1072 , directGeneratorPostFilter :: Maybe Text
1057− }
1058− deriving (Eq, Show)
1073+ } deriving (Eq, Show)
1059
1074
1060instance ToJSON DirectGenerators where
1075instance ToJSON DirectGenerators where
1076+ toJSON DirectGenerators{..} =
1061− toJSON DirectGenerators{..} = omitNulls [ "field" .= directGeneratorsField
1077+ omitNulls [ "field" .= directGeneratorsField
1062− , "size" .= directGeneratorsSize
1078+ , "size" .= directGeneratorsSize
1063− , "suggest_mode" .= directGeneratorSuggestMode
1079+ , "suggest_mode" .= directGeneratorSuggestMode
1064− , "max_edits" .= directGeneratorMaxEdits
1080+ , "max_edits" .= directGeneratorMaxEdits
1065− , "prefix_length" .= directGeneratorPrefixLength
1081+ , "prefix_length" .= directGeneratorPrefixLength
1066− , "min_word_length" .= directGeneratorMinWordLength
1082+ , "min_word_length" .= directGeneratorMinWordLength
1067− , "max_inspections" .= directGeneratorMaxInspections
1083+ , "max_inspections" .= directGeneratorMaxInspections
1068− , "min_doc_freq" .= directGeneratorMinDocFreq
1084+ , "min_doc_freq" .= directGeneratorMinDocFreq
1069− , "max_term_freq" .= directGeneratorMaxTermFreq
1085+ , "max_term_freq" .= directGeneratorMaxTermFreq
1070− , "pre_filter" .= directGeneratorPreFilter
1086+ , "pre_filter" .= directGeneratorPreFilter
1071− , "post_filter" .= directGeneratorPostFilter
1087+ , "post_filter" .= directGeneratorPostFilter
1072− ]
1088+ ]
1073
1089
1074instance FromJSON DirectGenerators where
1090instance FromJSON DirectGenerators where
1075 parseJSON = withObject "DirectGenerators" parse
1091 parseJSON = withObject "DirectGenerators" parse