pub struct SortBuilder { /* private fields */ }Expand description
Builds the sort array, one fluent verb per concern — each absorbing its own
optionality so a request maps straight through with no per-field if let.
by/near/tiebreak/or_default dedup by sort key (first wins), so a
field added twice — or an explicit sort that a tiebreak/default would repeat —
appears once; raw is exempt. or_default only contributes when the builder
would otherwise be empty.
use flusso_query::{SortBuilder, SortOrder, OrderBy};
let sorts = SortBuilder::new()
.score_if(true)
.by(count(), SortOrder::Desc)
.by(keyword("city"), None::<OrderBy>) // skipped
.tiebreak(keyword("id"))
.build();
assert_eq!(sorts.len(), 3); // _score, orderCount, idImplementations§
Source§impl SortBuilder
impl SortBuilder
Sourcepub fn by<H: Sortable>(self, handle: H, dir: impl Into<MaybeOrderBy>) -> Self
pub fn by<H: Sortable>(self, handle: H, dir: impl Into<MaybeOrderBy>) -> Self
Sourcepub fn near<S>(
self,
handle: Geo<S>,
center: impl Into<Option<GeoPoint>>,
) -> Self
pub fn near<S>( self, handle: Geo<S>, center: impl Into<Option<GeoPoint>>, ) -> Self
Sort by distance from center (_geo_distance, nearest first). A None
center skips it. Pass a unit / script geo sort through raw.
Sourcepub fn score_if(self, cond: bool) -> Self
pub fn score_if(self, cond: bool) -> Self
Sort by _score only when cond holds (e.g. a free-text query is present).
Sourcepub fn raw(self, sort: impl Into<Option<Sort>>) -> Self
pub fn raw(self, sort: impl Into<Option<Sort>>) -> Self
Append a pre-built Sort verbatim — the escape hatch for sorts the
typed verbs don’t cover (_script, a geo sort with options). A None
adds nothing. Not deduped.
Sourcepub fn tiebreak<H: Sortable>(self, handle: H) -> Self
pub fn tiebreak<H: Sortable>(self, handle: H) -> Self
A stable final sort key (ascending) — append a unique field so equal leading keys still page deterministically.
Sourcepub fn or_default(self, sort: impl Into<Sort>) -> Self
pub fn or_default(self, sort: impl Into<Sort>) -> Self
A fallback used only if nothing else lands in the builder.