[−][src]Struct porigon::SearchStream
FST stream on which various operations can be chained.
Methods
impl<'s> SearchStream<'s>
[src]
pub fn rescore<F: 's + Fn(&[u8], u64, Score) -> Score>(self, func: F) -> Self
[src]
Scores a stream, using the given closure.
Examples
Basic usage:
use fst::Streamer; use porigon::Searchable; let searchable = Searchable::build_from_iter(vec!( ("foo".as_bytes(), 0), ("foobar".as_bytes(), 1)) ).unwrap(); let mut strm = searchable .starts_with("foo") .rescore(|key, _, _| key.len() as porigon::Score) ; assert_eq!(strm.next(), Some(("foo".as_bytes(), 0, 3))); assert_eq!(strm.next(), Some(("foobar".as_bytes(), 1, 6))); assert_eq!(strm.next(), None);
You can also use this to build upon a previously set score:
use fst::Streamer; use porigon::Searchable; let searchable = Searchable::build_from_iter(vec!( ("foo".as_bytes(), 0), ("foobar".as_bytes(), 1)) ).unwrap(); let mut strm = searchable .starts_with("foo") .rescore(|key, _, _| key.len() as porigon::Score) .rescore(|_, index, old_score| (old_score << 16) | index) ; assert_eq!(strm.next(), Some(("foo".as_bytes(), 0, 3 << 16))); assert_eq!(strm.next(), Some(("foobar".as_bytes(), 1, (6 << 16) | 1))); assert_eq!(strm.next(), None);
pub fn filter<F: 's + Fn(&[u8], u64, Score) -> bool>(self, func: F) -> Self
[src]
Filters a stream, using the given closure.
Example
use fst::Streamer; use porigon::Searchable; let searchable = Searchable::build_from_iter(vec!( ("foo".as_bytes(), 0), ("foobar".as_bytes(), 1)) ).unwrap(); let mut strm = searchable .starts_with("foo") .filter(|key, _, _| key != "foobar".as_bytes()) ; assert_eq!(strm.next(), Some(("foo".as_bytes(), 0, 0))); assert_eq!(strm.next(), None);
pub fn map<F: 's + Fn(&[u8], u64, Score) -> (&[u8], u64, Score)>(
self,
func: F
) -> Self
[src]
self,
func: F
) -> Self
Maps over a stream, using the given closure.
This more of an advanced method, used for changing the stream's key or index. Most probably you want to use rescore() instead.
Example
use fst::Streamer; use porigon::Searchable; let mut items = vec!( ("this is a bar".as_bytes(), 15), ("is a bar".as_bytes(), (1 << 32) | 15), ("a bar".as_bytes(), (1 << 32) | 15), ("bar".as_bytes(), (1 << 32) | 15), ("barfoo".as_bytes(), 16) ); items.sort_by_key(|(key, _)| *key); let searchable = Searchable::build_from_iter(items).unwrap(); let mut strm = searchable .starts_with("bar") .map(|key, index, score| (key, index & !(1 << 32), score)) ; assert_eq!(strm.next(), Some(("bar".as_bytes(), 15, 0))); assert_eq!(strm.next(), Some(("barfoo".as_bytes(), 16, 0))); assert_eq!(strm.next(), None);
Trait Implementations
impl<'a, 's> Streamer<'a> for SearchStream<'s>
[src]
Auto Trait Implementations
impl<'s> !RefUnwindSafe for SearchStream<'s>
impl<'s> !Send for SearchStream<'s>
impl<'s> !Sync for SearchStream<'s>
impl<'s> Unpin for SearchStream<'s>
impl<'s> !UnwindSafe for SearchStream<'s>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<'a, S> IntoStreamer<'a> for S where
S: Streamer<'a>,
[src]
S: Streamer<'a>,
type Item = <S as Streamer<'a>>::Item
The type of the item emitted by the stream.
type Into = S
The type of the stream to be constructed.
fn into_stream(self) -> S
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,