git.iko.soy/typeable/bloodhound
on master help sign in
Add support for source filtering in search.
commit414b41d029701e93467ea868c0921de83a960fb1 authorThomas van Noort <thomas@silk.co> dateThu 25 Jun 2015, 13:07 (11 years ago) parent9c4c90a
2 files changed+21−6
src/Database/Bloodhound/Client.hs+3−3 src/Database/Bloodhound/Types.hs+18−3
src/Database/Bloodhound/Client.hs+3−3
@@ -471,7 +471,7 @@ searchByType (IndexName indexName)
471471-- >>> mkSearch (Just query) Nothing
472472-- Search {queryBody = Just (TermQuery (Term {termField = "user", termValue = "bitemyapp"}) Nothing), filterBody = Nothing, sortBody = Nothing, aggBody = Nothing, highlight = Nothing, trackSortScores = False, from = From 0, size = Size 10}
473473mkSearch :: Maybe Query -> Maybe Filter -> Search
474−mkSearch query filter = Search query filter Nothing Nothing Nothing False (From 0) (Size 10)
474+mkSearch query filter = Search query filter Nothing Nothing Nothing False (From 0) (Size 10) Nothing
475475
476476-- | 'mkAggregateSearch' is a helper function that defaults everything in a 'Search' except for
477477-- the 'Query' and the 'Aggregation'.
@@ -481,7 +481,7 @@ mkSearch query filter = Search query filter Nothing Nothing Nothing False (From
481481-- TermsAgg (TermsAggregation {term = Left "user", termInclude = Nothing, termExclude = Nothing, termOrder = Nothing, termMinDocCount = Nothing, termSize = Nothing, termShardSize = Nothing, termCollectMode = Just BreadthFirst, termExecutionHint = Nothing, termAggs = Nothing})
482482-- >>> let myAggregation = mkAggregateSearch Nothing $ mkAggregations "users" terms
483483mkAggregateSearch :: Maybe Query -> Aggregations -> Search
484−mkAggregateSearch query mkSearchAggs = Search query Nothing Nothing (Just mkSearchAggs) Nothing False (From 0) (Size 0)
484+mkAggregateSearch query mkSearchAggs = Search query Nothing Nothing (Just mkSearchAggs) Nothing False (From 0) (Size 0) Nothing
485485
486486-- | 'mkHighlightSearch' is a helper function that defaults everything in a 'Search' except for
487487-- the 'Query' and the 'Aggregation'.
@@ -490,7 +490,7 @@ mkAggregateSearch query mkSearchAggs = Search query Nothing Nothing (Just mkSear
490490-- >>> let testHighlight = Highlights Nothing [FieldHighlight (FieldName "message") Nothing]
491491-- >>> let search = mkHighlightSearch (Just query) testHighlight
492492mkHighlightSearch :: Maybe Query -> Highlights -> Search
493−mkHighlightSearch query searchHighlights = Search query Nothing Nothing Nothing (Just searchHighlights) False (From 0) (Size 10)
493+mkHighlightSearch query searchHighlights = Search query Nothing Nothing Nothing (Just searchHighlights) False (From 0) (Size 10) Nothing
494494
495495-- | 'pageSearch' is a helper function that takes a search and assigns the from
496496-- and size fields for the search. The from parameter defines the offset
src/Database/Bloodhound/Types.hs+18−3
@@ -63,6 +63,7 @@ module Database.Bloodhound.Types
6363 , TrackSortScores
6464 , From(..)
6565 , Size(..)
66+ , Source(..)
6667 , ShardResult(..)
6768 , Hit(..)
6869 , Filter(..)
@@ -604,7 +605,14 @@ data Search = Search { queryBody :: Maybe Query
604605 -- default False
605606 , trackSortScores :: TrackSortScores
606607 , from :: From
607− , size :: Size } deriving (Eq, Show)
608+ , size :: Size
609+ , source :: Maybe Source } deriving (Eq, Show)
610+
611+data Source =
612+ NoSource
613+ | SourceFields FieldOrFields
614+ | SourceIncludeExclude [Text] [Text]
615+ deriving (Show, Eq)
608616
609617data Highlights = Highlights { globalsettings :: Maybe HighlightSettings
610618 , highlightFields :: [FieldHighlight]
@@ -1918,7 +1926,7 @@ instance (FromJSON a) => FromJSON (EsResult a) where
19181926
19191927
19201928instance ToJSON Search where
1921− toJSON (Search query sFilter sort searchAggs highlight sTrackSortScores sFrom sSize) =
1929+ toJSON (Search query sFilter sort searchAggs highlight sTrackSortScores sFrom sSize sSource) =
19221930 omitNulls [ "query" .= query
19231931 , "filter" .= sFilter
19241932 , "sort" .= sort
@@ -1926,7 +1934,14 @@ instance ToJSON Search where
19261934 , "highlight" .= highlight
19271935 , "from" .= sFrom
19281936 , "size" .= sSize
1929− , "track_scores" .= sTrackSortScores]
1937+ , "track_scores" .= sTrackSortScores
1938+ , "_source" .= sSource]
1939+
1940+
1941+instance ToJSON Source where
1942+ toJSON NoSource = toJSON False
1943+ toJSON (SourceFields fields) = toJSON fields
1944+ toJSON (SourceIncludeExclude incl excl) = object [ "include" .= incl, "exclude" .= excl ]
19301945
19311946
19321947instance ToJSON FieldHighlight where