sort documentation, nicer types

This commit is contained in:
Chris Allen 2014-04-15 03:16:15 -05:00
parent 1de5b91a86
commit ce3e658fd0
2 changed files with 29 additions and 3 deletions

View File

@ -188,14 +188,17 @@ unpackId :: DocId -> String
unpackId (DocId docId) = docId
type Boost = Double
type TrackSortScores = Bool
type From = Int
type Size = Int
data Search = Search { queryBody :: Maybe Query
, filterBody :: Maybe Filter
, sortBody :: Maybe Sort
-- default False
, trackSortScores :: Bool
, from :: Int
, size :: Int} deriving (Eq, Show)
, trackSortScores :: TrackSortScores
, from :: From
, size :: Size} deriving (Eq, Show)
data Query = TermQuery Term (Maybe Boost)
| ConstantScoreFilter Filter Boost

View File

@ -285,6 +285,29 @@ Right [Hit {hitIndex = IndexName "twitter"
#+BEGIN_SRC haskell
let sortSpec = DefaultSortSpec $ mkSort (FieldName "age") Ascending
-- mkSort is a shortcut function that takes a FieldName and a SortOrder
-- to generate a vanilla DefaultSort.
-- checkt the DefaultSort type for the full list of customizable options.
-- From and size are integers for pagination.
-- When sorting on a field, scores are not computed. By setting TrackSortScores to true, scores will still be computed and tracked.
-- type Sort = [SortSpec]
-- type TrackSortScores = Bool
-- type From = Int
-- type Size = Int
-- Search takes Maybe Query
-- -> Maybe Filter
-- -> Maybe Sort
-- -> TrackSortScores
-- -> From -> Size
let search = Search Nothing (Just IdentityFilter) (Just [sortSpec]) False 0 10
#+END_SRC
*** Filtering