Skip to main content

SortBuilder

Struct SortBuilder 

Source
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, id

Implementations§

Source§

impl SortBuilder

Source

pub fn new() -> Self

An empty builder.

Source

pub fn by<H: Sortable>(self, handle: H, dir: impl Into<MaybeOrderBy>) -> Self

Sort by a field. dir accepts a SortOrder, an OrderBy, or an Option of either (a None skips the field) — so a request’s Option<dir> flows straight in. Nesting-aware: a field inside nested arrays renders the right nested chain from its scope.

Source

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.

Source

pub fn score(self) -> Self

Sort by relevance _score (descending).

Source

pub fn score_if(self, cond: bool) -> Self

Sort by _score only when cond holds (e.g. a free-text query is present).

Source

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.

Source

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.

Source

pub fn or_default(self, sort: impl Into<Sort>) -> Self

A fallback used only if nothing else lands in the builder.

Source

pub fn build(self) -> Vec<Sort>

Finish: the sort array (the fallback, if set, when otherwise empty).

Trait Implementations§

Source§

impl Debug for SortBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SortBuilder

Source§

fn default() -> SortBuilder

Returns the “default value” for a type. Read more
Source§

impl IntoIterator for SortBuilder

Source§

type Item = Sort

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<Sort>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more