git.iko.soy/typeable/bloodhound
on master help sign in
sort documentation, nicer types
ce3e658Chris Allen
Database/Bloodhound/Types.hs+6−3
@@ -188,14 +188,17 @@ unpackId :: DocId -> String
188unpackId (DocId docId) = docId
188unpackId (DocId docId) = docId
189
189
190type Boost = Double
190type Boost = Double
191+type TrackSortScores = Bool
192+type From = Int
193+type Size = Int
191
194
192data Search = Search { queryBody :: Maybe Query
195data Search = Search { queryBody :: Maybe Query
193 , filterBody :: Maybe Filter
196 , filterBody :: Maybe Filter
194 , sortBody :: Maybe Sort
197 , sortBody :: Maybe Sort
195 -- default False
198 -- default False
196− , trackSortScores :: Bool
199+ , trackSortScores :: TrackSortScores
197− , from :: Int
200+ , from :: From
198− , size :: Int} deriving (Eq, Show)
201+ , size :: Size} deriving (Eq, Show)
199
202
200data Query = TermQuery Term (Maybe Boost)
203data Query = TermQuery Term (Maybe Boost)
201 | ConstantScoreFilter Filter Boost
204 | ConstantScoreFilter Filter Boost
README.org+23
@@ -285,6 +285,29 @@ Right [Hit {hitIndex = IndexName "twitter"
285
285
286#+BEGIN_SRC haskell
286#+BEGIN_SRC haskell
287
287
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+
288#+END_SRC
311#+END_SRC
289
312
290*** Filtering
313*** Filtering