git.iko.soy/typeable/bloodhound
on master help sign in
sort documentation, nicer types
commitce3e658fd0aa82db189698ae94bd9dbe6ee1628d authorChris Allen <cma@bitemyapp.com> dateTue 15 Apr 2014, 03:16 (13 years ago) parent1de5b91
2 files changed+29−3
Database/Bloodhound/Types.hs+6−3 README.org+23
Database/Bloodhound/Types.hs+6−3
@@ -188,14 +188,17 @@ unpackId :: DocId -> String
188188unpackId (DocId docId) = docId
189189
190190type Boost = Double
191+type TrackSortScores = Bool
192+type From = Int
193+type Size = Int
191194
192195data Search = Search { queryBody :: Maybe Query
193196 , filterBody :: Maybe Filter
194197 , sortBody :: Maybe Sort
195198 -- default False
196− , trackSortScores :: Bool
197− , from :: Int
198− , size :: Int} deriving (Eq, Show)
199+ , trackSortScores :: TrackSortScores
200+ , from :: From
201+ , size :: Size} deriving (Eq, Show)
199202
200203data Query = TermQuery Term (Maybe Boost)
201204 | ConstantScoreFilter Filter Boost
README.org+23
@@ -285,6 +285,29 @@ Right [Hit {hitIndex = IndexName "twitter"
285285
286286#+BEGIN_SRC haskell
287287
288+let sortSpec = DefaultSortSpec $ mkSort (FieldName "age") Ascending
289+
290+-- mkSort is a shortcut function that takes a FieldName and a SortOrder
291+-- to generate a vanilla DefaultSort.
292+-- checkt the DefaultSort type for the full list of customizable options.
293+
294+-- From and size are integers for pagination.
295+
296+-- When sorting on a field, scores are not computed. By setting TrackSortScores to true, scores will still be computed and tracked.
297+
298+-- type Sort = [SortSpec]
299+-- type TrackSortScores = Bool
300+-- type From = Int
301+-- type Size = Int
302+
303+-- Search takes Maybe Query
304+-- -> Maybe Filter
305+-- -> Maybe Sort
306+-- -> TrackSortScores
307+-- -> From -> Size
308+
309+let search = Search Nothing (Just IdentityFilter) (Just [sortSpec]) False 0 10
310+
288311#+END_SRC
289312
290313*** Filtering