SearchResults

Struct SearchResults 

Source
pub struct SearchResults<T>(/* private fields */);
Expand description

A collection of scored values, sorted in descending order by score.

Implementations§

Source§

impl<T> SearchResults<T>

Source

pub fn new() -> SearchResults<T>

Create an empty collection of scored values.

Source

pub fn from_min_heap( queue: &mut BinaryHeap<Reverse<Scored<T>>>, ) -> SearchResults<T>

Create a collection of search results from a min-heap of scored values.

Source

pub fn push(&mut self, scored: Scored<T>)

Add a new scored value to this collection.

The score provided must be less than or equal to every other score in this collection, otherwise this method will panic.

Source

pub fn normalize(&mut self)

Normalizes the scores in this collection such that all scores are in the range [0, 1] where the top result always has score 1.0.

This operation is idempotent and does not change the ordering of results.

Source

pub fn rescore<F: FnMut(&T) -> f64>(&mut self, rescore: F)

Recomputes the scores in this collection using the given function.

The results are then re-sorted according to the new scores.

Source

pub fn trim(&mut self, size: usize)

Trim this collection so that it contains at most the first size results.

Source

pub fn len(&self) -> usize

Returns the number of results in this collection.

Source

pub fn is_empty(&self) -> bool

Returns true if and only if this collection is empty.

Source

pub fn as_slice(&self) -> &[Scored<T>]

Return a slice of search results in order.

Source

pub fn into_vec(self) -> Vec<Scored<T>>

Consume this collection and return the underlying sorted sequence of scored values.

Trait Implementations§

Source§

impl<T: Clone> Clone for SearchResults<T>

Source§

fn clone(&self) -> SearchResults<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for SearchResults<T>

Source§

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

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

impl<T: Default> Default for SearchResults<T>

Source§

fn default() -> SearchResults<T>

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

impl<T> IntoIterator for SearchResults<T>

Source§

type IntoIter = IntoIter<Scored<T>>

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

type Item = Scored<T>

The type of the elements being iterated over.
Source§

fn into_iter(self) -> IntoIter<Scored<T>>

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T> Freeze for SearchResults<T>

§

impl<T> RefUnwindSafe for SearchResults<T>
where T: RefUnwindSafe,

§

impl<T> Send for SearchResults<T>
where T: Send,

§

impl<T> Sync for SearchResults<T>
where T: Sync,

§

impl<T> Unpin for SearchResults<T>
where T: Unpin,

§

impl<T> UnwindSafe for SearchResults<T>
where T: UnwindSafe,

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, 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> 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.