git.iko.soy/typeable/bloodhound
on master help sign in
Split out Highlight
commit5ce22d3a9f170e8b960dbdbabef3cdceececb7dc authorChris Allen <cma@bitemyapp.com> dateSat 3 Mar 2018, 13:00 (9 years ago) parent38fdbc7
6 files changed+99−85
bloodhound.cabal+1 src/Database/V5/Bloodhound/Internal/Analysis.hs+1−5 src/Database/V5/Bloodhound/Internal/Highlight.hs+83 src/Database/V5/Bloodhound/Internal/Newtypes.hs+11 src/Database/V5/Bloodhound/Internal/StringlyTyped.hs+2−2 src/Database/V5/Bloodhound/Types.hs+1−78
bloodhound.cabal+1
@@ -40,6 +40,7 @@ library
4040 Database.V5.Bloodhound.Internal.Aggregation
4141 Database.V5.Bloodhound.Internal.Analysis
4242 Database.V5.Bloodhound.Internal.Client
43+ Database.V5.Bloodhound.Internal.Highlight
4344 Database.V5.Bloodhound.Internal.Newtypes
4445 Database.V5.Bloodhound.Internal.Query
4546 Database.V5.Bloodhound.Internal.Sort
src/Database/V5/Bloodhound/Internal/Analysis.hs+1−5
@@ -5,11 +5,7 @@ module Database.V5.Bloodhound.Internal.Analysis where
55
66import Bloodhound.Import
77
8−import Data.Aeson
9−import Data.Aeson.Types (Parser)
108import qualified Data.Map.Strict as M
11−import Data.Maybe (catMaybes)
12−import Data.Text (Text)
139import qualified Data.Text as T
1410
1511import Database.V5.Bloodhound.Internal.Newtypes
@@ -216,7 +212,7 @@ data Language
216212 deriving (Eq, Show)
217213
218214instance ToJSON Language where
219− toJSON = Data.Aeson.String . languageToText
215+ toJSON = String . languageToText
220216
221217instance FromJSON Language where
222218 parseJSON = withText "Language" $ \t -> case languageFromText t of
src/Database/V5/Bloodhound/Internal/Highlight.hsnew file+83
@@ -0,0 +1,83 @@
1+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
2+{-# LANGUAGE OverloadedStrings #-}
3+
4+module Database.V5.Bloodhound.Internal.Highlight where
5+
6+import Bloodhound.Import
7+
8+-- import Data.Aeson
9+-- import Data.Aeson.Types (Parser)
10+import qualified Data.Map.Strict as M
11+
12+import Database.V5.Bloodhound.Internal.Newtypes
13+import Database.V5.Bloodhound.Internal.Query
14+
15+type HitHighlight = M.Map Text [Text]
16+
17+data Highlights = Highlights
18+ { globalsettings :: Maybe HighlightSettings
19+ , highlightFields :: [FieldHighlight]
20+ } deriving (Eq, Show)
21+
22+data FieldHighlight =
23+ FieldHighlight FieldName (Maybe HighlightSettings)
24+ deriving (Eq, Show)
25+
26+
27+data HighlightSettings =
28+ Plain PlainHighlight
29+ | Postings PostingsHighlight
30+ | FastVector FastVectorHighlight
31+ deriving (Eq, Show)
32+
33+data PlainHighlight =
34+ PlainHighlight { plainCommon :: Maybe CommonHighlight
35+ , plainNonPost :: Maybe NonPostings }
36+ deriving (Eq, Show)
37+
38+ -- This requires that index_options are set to 'offset' in the mapping.
39+data PostingsHighlight =
40+ PostingsHighlight (Maybe CommonHighlight)
41+ deriving (Eq, Show)
42+
43+-- This requires that term_vector is set to 'with_positions_offsets' in the mapping.
44+data FastVectorHighlight = FastVectorHighlight
45+ { fvCommon :: Maybe CommonHighlight
46+ , fvNonPostSettings :: Maybe NonPostings
47+ , boundaryChars :: Maybe Text
48+ , boundaryMaxScan :: Maybe Int
49+ , fragmentOffset :: Maybe Int
50+ , matchedFields :: [Text]
51+ , phraseLimit :: Maybe Int
52+ } deriving (Eq, Show)
53+
54+data CommonHighlight = CommonHighlight
55+ { order :: Maybe Text
56+ , forceSource :: Maybe Bool
57+ , tag :: Maybe HighlightTag
58+ , encoder :: Maybe HighlightEncoder
59+ , noMatchSize :: Maybe Int
60+ , highlightQuery :: Maybe Query
61+ , requireFieldMatch :: Maybe Bool
62+ } deriving (Eq, Show)
63+
64+-- Settings that are only applicable to FastVector and Plain highlighters.
65+data NonPostings =
66+ NonPostings { fragmentSize :: Maybe Int
67+ , numberOfFragments :: Maybe Int
68+ } deriving (Eq, Show)
69+
70+data HighlightEncoder = DefaultEncoder
71+ | HTMLEncoder
72+ deriving (Eq, Show)
73+
74+instance ToJSON HighlightEncoder where
75+ toJSON DefaultEncoder = String "default"
76+ toJSON HTMLEncoder = String "html"
77+
78+-- NOTE: Should the tags use some kind of HTML type, rather than Text?
79+data HighlightTag =
80+ TagSchema Text
81+ -- Only uses more than the first value in the lists if fvh
82+ | CustomTags ([Text], [Text])
83+ deriving (Eq, Show)
src/Database/V5/Bloodhound/Internal/Newtypes.hs+11
@@ -5,9 +5,20 @@ module Database.V5.Bloodhound.Internal.Newtypes where
55
66import Bloodhound.Import
77
8+import qualified Data.Map.Strict as M
9+
810newtype From = From Int deriving (Eq, Show, ToJSON)
911newtype Size = Size Int deriving (Eq, Show, ToJSON, FromJSON)
1012
13+-- Used with scripts
14+newtype HitFields =
15+ HitFields (M.Map Text [Value])
16+ deriving (Eq, Show)
17+
18+instance FromJSON HitFields where
19+ parseJSON x
20+ = HitFields <$> parseJSON x
21+
1122-- Slight misnomer.
1223type Score = Maybe Double
1324
src/Database/V5/Bloodhound/Internal/StringlyTyped.hs+2−2
@@ -2,10 +2,10 @@
22
33module Database.V5.Bloodhound.Internal.StringlyTyped where
44
5−import Data.Aeson
5+import Bloodhound.Import
6+
67import qualified Data.Text as T
78
8−import Bloodhound.Import
99
1010-- This whole module is a sin bucket to deal with Elasticsearch badness.
1111newtype StringlyTypedDouble = StringlyTypedDouble
src/Database/V5/Bloodhound/Types.hs+1−78
@@ -421,6 +421,7 @@ import Database.V5.Bloodhound.Types.Class
421421import Database.V5.Bloodhound.Internal.Analysis
422422import Database.V5.Bloodhound.Internal.Aggregation
423423import Database.V5.Bloodhound.Internal.Client
424+import Database.V5.Bloodhound.Internal.Highlight
424425import Database.V5.Bloodhound.Internal.Newtypes
425426import Database.V5.Bloodhound.Internal.Query
426427import Database.V5.Bloodhound.Internal.Sort
@@ -491,74 +492,6 @@ data Exclude = Exclude [Pattern] deriving (Eq, Read, Show)
491492
492493newtype Pattern = Pattern Text deriving (Eq, Read, Show)
493494
494−data Highlights = Highlights
495− { globalsettings :: Maybe HighlightSettings
496− , highlightFields :: [FieldHighlight]
497− } deriving (Eq, Show)
498−
499−data FieldHighlight =
500− FieldHighlight FieldName (Maybe HighlightSettings)
501− deriving (Eq, Show)
502−
503−
504−data HighlightSettings =
505− Plain PlainHighlight
506− | Postings PostingsHighlight
507− | FastVector FastVectorHighlight
508− deriving (Eq, Show)
509−
510−data PlainHighlight =
511− PlainHighlight { plainCommon :: Maybe CommonHighlight
512− , plainNonPost :: Maybe NonPostings }
513− deriving (Eq, Show)
514−
515− -- This requires that index_options are set to 'offset' in the mapping.
516−data PostingsHighlight =
517− PostingsHighlight (Maybe CommonHighlight)
518− deriving (Eq, Show)
519−
520−-- This requires that term_vector is set to 'with_positions_offsets' in the mapping.
521−data FastVectorHighlight = FastVectorHighlight
522− { fvCommon :: Maybe CommonHighlight
523− , fvNonPostSettings :: Maybe NonPostings
524− , boundaryChars :: Maybe Text
525− , boundaryMaxScan :: Maybe Int
526− , fragmentOffset :: Maybe Int
527− , matchedFields :: [Text]
528− , phraseLimit :: Maybe Int
529− } deriving (Eq, Show)
530−
531−data CommonHighlight = CommonHighlight
532− { order :: Maybe Text
533− , forceSource :: Maybe Bool
534− , tag :: Maybe HighlightTag
535− , encoder :: Maybe HighlightEncoder
536− , noMatchSize :: Maybe Int
537− , highlightQuery :: Maybe Query
538− , requireFieldMatch :: Maybe Bool
539− } deriving (Eq, Show)
540−
541−-- Settings that are only applicable to FastVector and Plain highlighters.
542−data NonPostings =
543− NonPostings { fragmentSize :: Maybe Int
544− , numberOfFragments :: Maybe Int
545− } deriving (Eq, Show)
546−
547−data HighlightEncoder = DefaultEncoder
548− | HTMLEncoder
549− deriving (Eq, Show)
550−
551−instance ToJSON HighlightEncoder where
552− toJSON DefaultEncoder = String "default"
553− toJSON HTMLEncoder = String "html"
554−
555−-- NOTE: Should the tags use some kind of HTML type, rather than Text?
556−data HighlightTag =
557− TagSchema Text
558− -- Only uses more than the first value in the lists if fvh
559− | CustomTags ([Text], [Text])
560− deriving (Eq, Show)
561−
562495data SearchResult a =
563496 SearchResult { took :: Int
564497 , timedOut :: Bool
@@ -627,16 +560,6 @@ instance (FromJSON a) => FromJSON (Hit a) where
627560 v .:? "highlight"
628561 parseJSON _ = empty
629562
630−newtype HitFields =
631− HitFields (M.Map Text [Value])
632− deriving (Eq, Show)
633−
634−instance FromJSON HitFields where
635− parseJSON x
636− = HitFields <$> parseJSON x
637−
638−type HitHighlight = M.Map Text [Text]
639−
640563data MissingResult = MissingResult
641564 { missingDocCount :: Int
642565 } deriving (Show)