@@ -173,6 +173,7 @@ module Database.Bloodhound.Types
173173 , NonPostings(..)
174174 , HighlightEncoder(..)
175175 , HighlightTag(..)
176+ , HitHighlight
176177
177178 , TermsResult
178179 , DateHistogramResult
@@ -551,7 +552,6 @@ data FastVectorHighlight =
551552
552553data CommonHighlight =
553554 CommonHighlight {
554− -- highlightType :: Maybe HighlightType -- See below.
555555 forceSource :: Maybe Bool
556556 , tag :: Maybe HighlightTag
557557 , encoder :: Maybe HighlightEncoder
@@ -559,6 +559,7 @@ data CommonHighlight =
559559 , highlightQuery :: Maybe Query
560560 , requireFieldMatch :: Maybe Bool
561561 } deriving (Show, Eq)
562+
562563-- Settings that are only applicable to FastVector and Plain highlighters.
563564data NonPostings =
564565 NonPostings { fragmentSize :: Maybe Int
@@ -1007,7 +1008,7 @@ data DistanceRange =
10071008 DistanceRange { distanceFrom :: Distance
10081009 , distanceTo :: Distance } deriving (Eq, Show)
10091010
1010−data FromJSON a => SearchResult a =
1011+data (FromJSON a) => SearchResult a =
10111012 SearchResult { took :: Int
10121013 , timedOut :: Bool
10131014 , shards :: ShardResult
@@ -1016,24 +1017,26 @@ data FromJSON a => SearchResult a =
10161017
10171018type Score = Double
10181019
1019−data FromJSON a => SearchHits a =
1020+data (FromJSON a) => SearchHits a =
10201021 SearchHits { hitsTotal :: Int
10211022 , maxScore :: Score
10221023 , hits :: [Hit a] } deriving (Eq, Show)
10231024
1024−data FromJSON a => Hit a =
1025+data (FromJSON a) => Hit a =
10251026 Hit { hitIndex :: IndexName
10261027 , hitType :: MappingName
10271028 , hitDocId :: DocId
10281029 , hitScore :: Score
10291030 , hitSource :: a
1030− , hitHighlight :: Maybe Text } deriving (Eq, Show)
1031+ , hitHighlight :: Maybe HitHighlight } deriving (Eq, Show)
10311032
10321033data ShardResult =
10331034 ShardResult { shardTotal :: Int
10341035 , shardsSuccessful :: Int
10351036 , shardsFailed :: Int } deriving (Eq, Show, Generic)
10361037
1038+type HitHighlight = M.Map Text [Text]
1039+
10371040showText :: Show a => a -> Text
10381041showText = T.pack . show
10391042
@@ -1825,13 +1828,13 @@ instance (FromJSON a) => FromJSON (EsResult a) where
18251828
18261829instance ToJSON Search where
18271830 toJSON (Search query sFilter sort aggs highlight sTrackSortScores sFrom sSize) =
1828− omitNulls [ "query" .= query
1829− , "filter" .= sFilter
1830− , "sort" .= sort
1831+ omitNulls [ "query" .= query
1832+ , "filter" .= sFilter
1833+ , "sort" .= sort
18311834 , "aggregations" .= aggs
1832− , "highlight" .= highlight
1833− , "from" .= sFrom
1834− , "size" .= sSize
1835+ , "highlight" .= highlight
1836+ , "from" .= sFrom
1837+ , "size" .= sSize
18351838 , "track_scores" .= sTrackSortScores]
18361839
18371840instance ToJSON FieldHighlight where
@@ -1842,8 +1845,8 @@ instance ToJSON FieldHighlight where
18421845
18431846instance ToJSON Highlights where
18441847 toJSON (Highlights global fields) =
1845− omitNulls (["fields" .= toJSON fields]
1846− ++ (highlightSettingsPairs global))
1848+ omitNulls (("fields" .= toJSON fields)
1849+ : highlightSettingsPairs global)
18471850
18481851instance ToJSON HighlightSettings where
18491852 toJSON hs = omitNulls (highlightSettingsPairs (Just hs))
@@ -1859,14 +1862,14 @@ plainHighPairs :: Maybe PlainHighlight -> [Pair]
18591862plainHighPairs Nothing = []
18601863plainHighPairs (Just (PlainHighlight plCom plNonPost)) =
18611864 [ "type" .= String "plain"]
1862− ++ (commonHighlightPairs plCom)
1863− ++ (nonPostingsToPairs plNonPost)
1865+ ++ commonHighlightPairs plCom
1866+ ++ nonPostingsToPairs plNonPost
18641867
18651868postHighPairs :: Maybe PostingsHighlight -> [Pair]
18661869postHighPairs Nothing = []
18671870postHighPairs (Just (PostingsHighlight pCom)) =
1868− [ "type" .= String "postings" ]
1869− ++ (commonHighlightPairs pCom)
1871+ ("type" .= String "postings")
1872+ : commonHighlightPairs pCom
18701873
18711874fastVectorHighPairs :: Maybe FastVectorHighlight -> [Pair]
18721875fastVectorHighPairs Nothing = []
@@ -1880,8 +1883,8 @@ fastVectorHighPairs (Just
18801883 , "fragment_offset" .= fvFragOff
18811884 , "matched_fields" .= fvMatchedFields
18821885 , "phraseLimit" .= fvPhraseLim]
1883− ++ (commonHighlightPairs fvCom)
1884− ++ (nonPostingsToPairs fvNonPostSettings)
1886+ ++ commonHighlightPairs fvCom
1887+ ++ nonPostingsToPairs fvNonPostSettings
18851888
18861889commonHighlightPairs :: Maybe CommonHighlight -> [Pair]
18871890commonHighlightPairs Nothing = []
@@ -1893,7 +1896,7 @@ commonHighlightPairs (Just (CommonHighlight chForceSource chTag chEncoder
18931896 , "no_match_size" .= chNoMatchSize
18941897 , "highlight_query" .= chHighlightQuery
18951898 , "require_fieldMatch" .= chRequireFieldMatch]
1896− ++ (highlightTagToPairs chTag)
1899+ ++ highlightTagToPairs chTag
18971900
18981901
18991902nonPostingsToPairs :: Maybe NonPostings -> [Pair]
@@ -2072,7 +2075,7 @@ instance (FromJSON a) => FromJSON (Hit a) where
20722075 parseJSON _ = empty
20732076
20742077instance FromJSON ShardResult where
2075− parseJSON (Object v) = ShardResult <$>
2078+ parseJSON (Object v) = ShardResult <$>
20762079 v .: "total" <*>
20772080 v .: "successful" <*>
20782081 v .: "failed"