@@ -173,6 +173,7 @@ module Database.Bloodhound.Types
173 , NonPostings(..)
173 , NonPostings(..)
174 , HighlightEncoder(..)
174 , HighlightEncoder(..)
175 , HighlightTag(..)
175 , HighlightTag(..)
177 , TermsResult
178 , TermsResult
178 , DateHistogramResult
179 , DateHistogramResult
@@ -551,7 +552,6 @@ data FastVectorHighlight =
552data CommonHighlight =
553data CommonHighlight =
553 CommonHighlight {
554 CommonHighlight {
554− -- highlightType :: Maybe HighlightType -- See below.
555 forceSource :: Maybe Bool
555 forceSource :: Maybe Bool
556 , tag :: Maybe HighlightTag
556 , tag :: Maybe HighlightTag
557 , encoder :: Maybe HighlightEncoder
557 , encoder :: Maybe HighlightEncoder
@@ -559,6 +559,7 @@ data CommonHighlight =
559 , highlightQuery :: Maybe Query
559 , highlightQuery :: Maybe Query
560 , requireFieldMatch :: Maybe Bool
560 , requireFieldMatch :: Maybe Bool
561 } deriving (Show, Eq)
561 } deriving (Show, Eq)
562-- Settings that are only applicable to FastVector and Plain highlighters.
563-- Settings that are only applicable to FastVector and Plain highlighters.
563data NonPostings =
564data NonPostings =
564 NonPostings { fragmentSize :: Maybe Int
565 NonPostings { fragmentSize :: Maybe Int
@@ -1007,7 +1008,7 @@ data DistanceRange =
1007 DistanceRange { distanceFrom :: Distance
1008 DistanceRange { distanceFrom :: Distance
1008 , distanceTo :: Distance } deriving (Eq, Show)
1009 , distanceTo :: Distance } deriving (Eq, Show)
1010−data FromJSON a => SearchResult a =
1011+data (FromJSON a) => SearchResult a =
1011 SearchResult { took :: Int
1012 SearchResult { took :: Int
1012 , timedOut :: Bool
1013 , timedOut :: Bool
1013 , shards :: ShardResult
1014 , shards :: ShardResult
@@ -1016,24 +1017,26 @@ data FromJSON a => SearchResult a =
1017type Score = Double
1018type Score = Double
1019−data FromJSON a => SearchHits a =
1020+data (FromJSON a) => SearchHits a =
1020 SearchHits { hitsTotal :: Int
1021 SearchHits { hitsTotal :: Int
1021 , maxScore :: Score
1022 , maxScore :: Score
1022 , hits :: [Hit a] } deriving (Eq, Show)
1023 , hits :: [Hit a] } deriving (Eq, Show)
1024−data FromJSON a => Hit a =
1025+data (FromJSON a) => Hit a =
1025 Hit { hitIndex :: IndexName
1026 Hit { hitIndex :: IndexName
1026 , hitType :: MappingName
1027 , hitType :: MappingName
1027 , hitDocId :: DocId
1028 , hitDocId :: DocId
1028 , hitScore :: Score
1029 , hitScore :: Score
1029 , hitSource :: a
1030 , hitSource :: a
1030− , hitHighlight :: Maybe Text } deriving (Eq, Show)
1031+ , hitHighlight :: Maybe HitHighlight } deriving (Eq, Show)
1032data ShardResult =
1033data ShardResult =
1033 ShardResult { shardTotal :: Int
1034 ShardResult { shardTotal :: Int
1034 , shardsSuccessful :: Int
1035 , shardsSuccessful :: Int
1035 , shardsFailed :: Int } deriving (Eq, Show, Generic)
1036 , shardsFailed :: Int } deriving (Eq, Show, Generic)
1038+type HitHighlight = M.Map Text [Text]
1037showText :: Show a => a -> Text
1040showText :: Show a => a -> Text
1038showText = T.pack . show
1041showText = T.pack . show
@@ -1825,13 +1828,13 @@ instance (FromJSON a) => FromJSON (EsResult a) where
1826instance ToJSON Search where
1829instance ToJSON Search where
1827 toJSON (Search query sFilter sort aggs highlight sTrackSortScores sFrom sSize) =
1830 toJSON (Search query sFilter sort aggs highlight sTrackSortScores sFrom sSize) =
1828− omitNulls [ "query" .= query
1831+ omitNulls [ "query" .= query
1829− , "filter" .= sFilter
1832+ , "filter" .= sFilter
1830− , "sort" .= sort
1833+ , "sort" .= sort
1831 , "aggregations" .= aggs
1834 , "aggregations" .= aggs
1832− , "highlight" .= highlight
1835+ , "highlight" .= highlight
1833− , "from" .= sFrom
1836+ , "from" .= sFrom
1834− , "size" .= sSize
1837+ , "size" .= sSize
1835 , "track_scores" .= sTrackSortScores]
1838 , "track_scores" .= sTrackSortScores]
1837instance ToJSON FieldHighlight where
1840instance ToJSON FieldHighlight where
@@ -1842,8 +1845,8 @@ instance ToJSON FieldHighlight where
1843instance ToJSON Highlights where
1846instance ToJSON Highlights where
1844 toJSON (Highlights global fields) =
1847 toJSON (Highlights global fields) =
1845− omitNulls (["fields" .= toJSON fields]
1848+ omitNulls (("fields" .= toJSON fields)
1846− ++ (highlightSettingsPairs global))
1849+ : highlightSettingsPairs global)
1848instance ToJSON HighlightSettings where
1851instance ToJSON HighlightSettings where
1849 toJSON hs = omitNulls (highlightSettingsPairs (Just hs))
1852 toJSON hs = omitNulls (highlightSettingsPairs (Just hs))
@@ -1859,14 +1862,14 @@ plainHighPairs :: Maybe PlainHighlight -> [Pair]
1859plainHighPairs Nothing = []
1862plainHighPairs Nothing = []
1860plainHighPairs (Just (PlainHighlight plCom plNonPost)) =
1863plainHighPairs (Just (PlainHighlight plCom plNonPost)) =
1861 [ "type" .= String "plain"]
1864 [ "type" .= String "plain"]
1862− ++ (commonHighlightPairs plCom)
1865+ ++ commonHighlightPairs plCom
1863− ++ (nonPostingsToPairs plNonPost)
1866+ ++ nonPostingsToPairs plNonPost
1865postHighPairs :: Maybe PostingsHighlight -> [Pair]
1868postHighPairs :: Maybe PostingsHighlight -> [Pair]
1866postHighPairs Nothing = []
1869postHighPairs Nothing = []
1867postHighPairs (Just (PostingsHighlight pCom)) =
1870postHighPairs (Just (PostingsHighlight pCom)) =
1868− [ "type" .= String "postings" ]
1871+ ("type" .= String "postings")
1869− ++ (commonHighlightPairs pCom)
1872+ : commonHighlightPairs pCom
1871fastVectorHighPairs :: Maybe FastVectorHighlight -> [Pair]
1874fastVectorHighPairs :: Maybe FastVectorHighlight -> [Pair]
1872fastVectorHighPairs Nothing = []
1875fastVectorHighPairs Nothing = []
@@ -1880,8 +1883,8 @@ fastVectorHighPairs (Just
1880 , "fragment_offset" .= fvFragOff
1883 , "fragment_offset" .= fvFragOff
1881 , "matched_fields" .= fvMatchedFields
1884 , "matched_fields" .= fvMatchedFields
1882 , "phraseLimit" .= fvPhraseLim]
1885 , "phraseLimit" .= fvPhraseLim]
1883− ++ (commonHighlightPairs fvCom)
1886+ ++ commonHighlightPairs fvCom
1884− ++ (nonPostingsToPairs fvNonPostSettings)
1887+ ++ nonPostingsToPairs fvNonPostSettings
1886commonHighlightPairs :: Maybe CommonHighlight -> [Pair]
1889commonHighlightPairs :: Maybe CommonHighlight -> [Pair]
1887commonHighlightPairs Nothing = []
1890commonHighlightPairs Nothing = []
@@ -1893,7 +1896,7 @@ commonHighlightPairs (Just (CommonHighlight chForceSource chTag chEncoder
1893 , "no_match_size" .= chNoMatchSize
1896 , "no_match_size" .= chNoMatchSize
1894 , "highlight_query" .= chHighlightQuery
1897 , "highlight_query" .= chHighlightQuery
1895 , "require_fieldMatch" .= chRequireFieldMatch]
1898 , "require_fieldMatch" .= chRequireFieldMatch]
1896− ++ (highlightTagToPairs chTag)
1899+ ++ highlightTagToPairs chTag
1899nonPostingsToPairs :: Maybe NonPostings -> [Pair]
1902nonPostingsToPairs :: Maybe NonPostings -> [Pair]
@@ -2072,7 +2075,7 @@ instance (FromJSON a) => FromJSON (Hit a) where
2072 parseJSON _ = empty
2075 parseJSON _ = empty
2074instance FromJSON ShardResult where
2077instance FromJSON ShardResult where
2075− parseJSON (Object v) = ShardResult <$>
2078+ parseJSON (Object v) = ShardResult <$>
2076 v .: "total" <*>
2079 v .: "total" <*>
2077 v .: "successful" <*>
2080 v .: "successful" <*>
2078 v .: "failed"
2081 v .: "failed"