[][src]Struct porigon::TopScoreCollector

pub struct TopScoreCollector { /* fields omitted */ }

Documents collector, keeping track of the top N items (based on their score).

Internally, this uses a binary min-heap as an efficient manner of keeping track of the top N documents.

Methods

impl TopScoreCollector[src]

pub fn new(limit: usize) -> Self[src]

Constructs a new TopScoreCollector with a hardcoded limit of documents.

pub fn reset(&mut self)[src]

Resets the internal state of the collector.

pub fn consume_stream<'f, I, S>(&mut self, streamer: I) where
    I: for<'a> IntoStreamer<'a, Into = S, Item = (&'a [u8], u64, Score)>,
    S: 'f + for<'a> Streamer<'a, Item = (&'a [u8], u64, Score)>, 
[src]

Consumes a fst::Streamer, collecting the items and only keeping the top N items (based on their score).

Example

use porigon::{Searchable, TopScoreCollector};

let searchable = Searchable::build_from_iter(vec!(
    ("foo".as_bytes(), 1),
    ("foobar".as_bytes(), 2),
)).unwrap();
let mut collector = TopScoreCollector::new(1);

collector.consume_stream(
    searchable
        .starts_with("foo")
        .rescore(|_, index, _| index * 2)
);
collector.consume_stream(
    searchable
        .exact_match("foobar")
);
assert_eq!(collector.top_documents()[0].index, 2);

pub fn top_documents(&mut self) -> &[Document][src]

Returns a slice of the processed top documents, ordered by their score.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.