git.iko.soy/typeable/bloodhound
on master help sign in
Split out Highlight
5ce22d3Chris Allen
bloodhound.cabal+1
@@ -40,6 +40,7 @@ library
40 Database.V5.Bloodhound.Internal.Aggregation
40 Database.V5.Bloodhound.Internal.Aggregation
41 Database.V5.Bloodhound.Internal.Analysis
41 Database.V5.Bloodhound.Internal.Analysis
42 Database.V5.Bloodhound.Internal.Client
42 Database.V5.Bloodhound.Internal.Client
43+ Database.V5.Bloodhound.Internal.Highlight
43 Database.V5.Bloodhound.Internal.Newtypes
44 Database.V5.Bloodhound.Internal.Newtypes
44 Database.V5.Bloodhound.Internal.Query
45 Database.V5.Bloodhound.Internal.Query
45 Database.V5.Bloodhound.Internal.Sort
46 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
5
5
6import Bloodhound.Import
6import Bloodhound.Import
7
7
8−import Data.Aeson
9−import Data.Aeson.Types (Parser)
10import qualified Data.Map.Strict as M
8import qualified Data.Map.Strict as M
11−import Data.Maybe (catMaybes)
12−import Data.Text (Text)
13import qualified Data.Text as T
9import qualified Data.Text as T
14
10
15import Database.V5.Bloodhound.Internal.Newtypes
11import Database.V5.Bloodhound.Internal.Newtypes
@@ -216,7 +212,7 @@ data Language
216 deriving (Eq, Show)
212 deriving (Eq, Show)
217
213
218instance ToJSON Language where
214instance ToJSON Language where
219− toJSON = Data.Aeson.String . languageToText
215+ toJSON = String . languageToText
220
216
221instance FromJSON Language where
217instance FromJSON Language where
222 parseJSON = withText "Language" $ \t -> case languageFromText t of
218 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
5
5
6import Bloodhound.Import
6import Bloodhound.Import
7
7
8+import qualified Data.Map.Strict as M
9+
8newtype From = From Int deriving (Eq, Show, ToJSON)
10newtype From = From Int deriving (Eq, Show, ToJSON)
9newtype Size = Size Int deriving (Eq, Show, ToJSON, FromJSON)
11newtype Size = Size Int deriving (Eq, Show, ToJSON, FromJSON)
10
12
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+
11-- Slight misnomer.
22-- Slight misnomer.
12type Score = Maybe Double
23type Score = Maybe Double
13
24
src/Database/V5/Bloodhound/Internal/StringlyTyped.hs+2−2
@@ -2,10 +2,10 @@
2
2
3module Database.V5.Bloodhound.Internal.StringlyTyped where
3module Database.V5.Bloodhound.Internal.StringlyTyped where
4
4
5−import Data.Aeson
5+import Bloodhound.Import
6+
6import qualified Data.Text as T
7import qualified Data.Text as T
7
8
8−import Bloodhound.Import
9
9
10-- This whole module is a sin bucket to deal with Elasticsearch badness.
10-- This whole module is a sin bucket to deal with Elasticsearch badness.
11newtype StringlyTypedDouble = StringlyTypedDouble
11newtype StringlyTypedDouble = StringlyTypedDouble
src/Database/V5/Bloodhound/Types.hs+1−78
@@ -421,6 +421,7 @@ import Database.V5.Bloodhound.Types.Class
421import Database.V5.Bloodhound.Internal.Analysis
421import Database.V5.Bloodhound.Internal.Analysis
422import Database.V5.Bloodhound.Internal.Aggregation
422import Database.V5.Bloodhound.Internal.Aggregation
423import Database.V5.Bloodhound.Internal.Client
423import Database.V5.Bloodhound.Internal.Client
424+import Database.V5.Bloodhound.Internal.Highlight
424import Database.V5.Bloodhound.Internal.Newtypes
425import Database.V5.Bloodhound.Internal.Newtypes
425import Database.V5.Bloodhound.Internal.Query
426import Database.V5.Bloodhound.Internal.Query
426import Database.V5.Bloodhound.Internal.Sort
427import Database.V5.Bloodhound.Internal.Sort
@@ -491,74 +492,6 @@ data Exclude = Exclude [Pattern] deriving (Eq, Read, Show)
491
492
492newtype Pattern = Pattern Text deriving (Eq, Read, Show)
493newtype Pattern = Pattern Text deriving (Eq, Read, Show)
493
494
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−
562data SearchResult a =
495data SearchResult a =
563 SearchResult { took :: Int
496 SearchResult { took :: Int
564 , timedOut :: Bool
497 , timedOut :: Bool
@@ -627,16 +560,6 @@ instance (FromJSON a) => FromJSON (Hit a) where
627 v .:? "highlight"
560 v .:? "highlight"
628 parseJSON _ = empty
561 parseJSON _ = empty
629
562
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−
640data MissingResult = MissingResult
563data MissingResult = MissingResult
641 { missingDocCount :: Int
564 { missingDocCount :: Int
642 } deriving (Show)
565 } deriving (Show)