Struct FullTextIndex

Source
pub struct FullTextIndex { /* private fields */ }
Expand description

Full-text search index for a collection and field

This struct maintains an inverted index mapping terms to the documents that contain them, with term frequency information for relevance scoring.

Implementations§

Source§

impl FullTextIndex

Source

pub fn new(_collection: &str, field: &str) -> Self

Create a new full-text index for a collection field

§Arguments
  • collection - Name of the collection to index
  • field - Name of the field within documents to index
§Examples
let description_index = FullTextIndex::new("products", "description");
Source

pub fn with_options( collection: &str, field: &str, enable_stop_words: bool, ) -> Self

Create a search index with specific options

§Arguments
  • collection - Name of the collection to index
  • field - Name of the field within documents to index
  • enable_stop_words - Whether to filter out common words (false = no filtering)
§Examples
// Create an index that doesn't filter out common words
let index = FullTextIndex::with_options("products", "description", false);
 
// Create an index that does filter out common words
let index = FullTextIndex::with_options("articles", "content", true);
Source

pub fn set_stop_words_filter(&mut self, enable: bool)

Set whether to filter out common stop words

§Arguments
  • enable - true to filter out common words, false to include all words
§Examples
// Enable filtering of common words like "the", "and", etc.
index.set_stop_words_filter(true);
 
// Disable filtering to allow searching for all words
index.set_stop_words_filter(false);
Source

pub fn index_document(&self, doc: &Document) -> Result<()>

Add or update a document in the index

§Arguments
  • doc - The document to index
§Returns

A Result indicating success or an error

§Examples
index.index_document(&document)?;
Source

pub fn search(&self, query: &str) -> Vec<(String, f32)>

Search the index for documents matching a query

§Arguments
  • query - The search query text
§Returns

A vector of document IDs and relevance scores

§Examples
let matches = index.search("wireless headphones");

Search with fuzzy matching for typo tolerance

§Arguments
  • query - The search query text
  • max_distance - Maximum edit distance for fuzzy matching
§Returns

A vector of document IDs and relevance scores

§Examples
// Allow up to 2 character differences
let matches = index.fuzzy_search("wireles headpones", 2);
Source

pub fn remove_document(&self, doc_id: &str)

Remove a document from the index

§Arguments
  • doc_id - ID of the document to remove
§Examples
index.remove_document("doc-123");
Source

pub fn add_stopwords(&mut self, words: &[&str])

Add custom stopwords to the filter list

§Arguments
  • words - List of words to add to the stopword list
§Examples
// Add domain-specific stopwords
index.add_stopwords(&["widget", "product", "item"]);
Source

pub fn clear_stopwords(&mut self)

Remove all stopwords from the filter

§Examples
// Allow searching for any word, including common ones
index.clear_stopwords();
Source

pub fn get_stopwords(&self) -> Vec<String>

Get the current list of stopwords

§Returns

A vector of stopwords currently in use

§Examples
let current_stopwords = index.get_stopwords();
println!("Currently filtering: {:?}", current_stopwords);
Source

pub fn get_fuzzy_matches( &self, query: &str, max_distance: u32, ) -> Vec<(String, f32)>

Source

pub fn highlight_matches(&self, text: &str, query: &str) -> String

Auto Trait Implementations§

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> 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> Same for T

Source§

type Output = T

Should always be Self
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.