Skip to main content

MapKeySort

Struct MapKeySort 

Source
pub struct MapKeySort<S = Root> { /* private fields */ }
Expand description

A sort over a dynamic-key map field by an ordered fallback of keys — “sort by it, else en, …”. Built with *Map::sort_key("it").or("en") and used like any other sortable handle: SortBuilder::by(handle, dir), or .asc() / .desc() for a bare Sort.

It renders a _script sort whose painless source walks the keys in order and sorts by the value of the first one a document has — true fallback, so a row with only en still orders by en (not lexicographic tiers). String maps sort case-insensitively on the dynamic .keyword subfield; numeric/date maps on the bare key (epoch millis for dates). Nesting-aware via scope S, exactly like a field sort.

Documents with none of the keys sort first under .asc() / last under .desc() by default; place them explicitly with .missing_first() / .missing_last() / .missing(value) on the produced Sort (or via the OrderBy passed to SortBuilder::by) — these redirect into the script’s fallback value, so they work despite a _script sort ignoring missing.

use flusso_query::{Root, SortBuilder, SortOrder, TextMap};

// Italian, falling back to English — through the normal `by`.
let sorts = SortBuilder::new()
    .by(TextMap::<Root>::at("name").sort_key("it").or("en"), SortOrder::Desc)
    .build();
assert_eq!(sorts.len(), 1);

Implementations§

Source§

impl<S> MapKeySort<S>

Source

pub fn or(self, key: impl Into<String>) -> Self

Add the next fallback key, tried only for documents missing every key so far. Chain several for a longer preference order (itende).

Trait Implementations§

Source§

impl<S: Clone> Clone for MapKeySort<S>

Source§

fn clone(&self) -> MapKeySort<S>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S: Debug> Debug for MapKeySort<S>

Source§

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

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

impl<S: FlussoDocument> From<MapKeySort<S>> for Sort

Source§

fn from(map_sort: MapKeySort<S>) -> Self

Converts to this type from the input type.
Source§

impl<S: FlussoDocument> From<MapKeySort<S>> for Option<Sort>

Source§

fn from(map_sort: MapKeySort<S>) -> Self

Converts to this type from the input type.
Source§

impl<S: FlussoDocument> Sortable for MapKeySort<S>

.asc() / .desc() build the _script sort; a bare value defaults to asc.

Source§

fn asc(&self) -> Sort

Sort ascending.
Source§

fn desc(&self) -> Sort

Sort descending.

Auto Trait Implementations§

§

impl<S> Freeze for MapKeySort<S>

§

impl<S> RefUnwindSafe for MapKeySort<S>

§

impl<S> Send for MapKeySort<S>

§

impl<S> Sync for MapKeySort<S>

§

impl<S> Unpin for MapKeySort<S>

§

impl<S> UnsafeUnpin for MapKeySort<S>

§

impl<S> UnwindSafe for MapKeySort<S>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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