SearchEngine

Struct SearchEngine 

Source
pub struct SearchEngine<K, D: TokenEmbedder = u32, T = DefaultTokenizer> { /* private fields */ }
Expand description

A search engine that ranks documents with BM25. K is the type of the document id, D is the type of the token embedder and T is the type of the tokenizer.

Implementations§

Source§

impl<K, D, T> SearchEngine<K, D, T>
where K: Hash + Eq + Clone, D: TokenEmbedder, D::EmbeddingSpace: Eq + Hash + Clone, T: Tokenizer,

Source

pub fn upsert(&mut self, document: impl Into<Document<K>>)

Upserts a document into the search engine. If a document with the same id already exists, it will be replaced. Note that upserting a document will change the true value of avgdl. The more avgdl drifts from its true value, the less accurate the BM25 scores will be.

Source

pub fn remove(&mut self, document_id: &K)

Removes a document from the search engine if it exists.

Source

pub fn get(&self, document_id: &K) -> Option<Document<K>>

Gets the contents of a document by its id.

Source

pub fn iter(&self) -> impl Iterator<Item = Document<K>> + '_

Returns an iterator over the documents in the search engine.

Source

pub fn search( &self, query: &str, limit: impl Into<Option<usize>>, ) -> Vec<SearchResult<K>>

Searches the documents for the given query and returns the top limit results. Only the document contents are searched, not the document ids.

Trait Implementations§

Source§

impl<K: Debug, D: TokenEmbedder + Debug, T: Debug> Debug for SearchEngine<K, D, T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<K, D, T> Freeze for SearchEngine<K, D, T>
where T: Freeze,

§

impl<K, D, T> RefUnwindSafe for SearchEngine<K, D, T>

§

impl<K, D, T> Send for SearchEngine<K, D, T>
where T: Send, D: Send, K: Send, <D as TokenEmbedder>::EmbeddingSpace: Send,

§

impl<K, D, T> Sync for SearchEngine<K, D, T>
where T: Sync, D: Sync, K: Sync, <D as TokenEmbedder>::EmbeddingSpace: Sync,

§

impl<K, D, T> Unpin for SearchEngine<K, D, T>
where T: Unpin, D: Unpin, K: Unpin, <D as TokenEmbedder>::EmbeddingSpace: Unpin,

§

impl<K, D, T> UnwindSafe for SearchEngine<K, D, T>

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, 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.