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
impl FullTextIndex
Sourcepub fn with_options(
collection: &str,
field: &str,
enable_stop_words: bool,
) -> Self
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 indexfield- Name of the field within documents to indexenable_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);Sourcepub fn set_stop_words_filter(&mut self, enable: bool)
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);Sourcepub fn index_document(&self, doc: &Document) -> Result<()>
pub fn index_document(&self, doc: &Document) -> Result<()>
Sourcepub fn fuzzy_search(
&self,
query: &str,
max_distance: usize,
) -> Vec<(String, f32)>
pub fn fuzzy_search( &self, query: &str, max_distance: usize, ) -> Vec<(String, f32)>
Search with fuzzy matching for typo tolerance
§Arguments
query- The search query textmax_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);Sourcepub fn remove_document(&self, doc_id: &str)
pub fn remove_document(&self, doc_id: &str)
Sourcepub fn add_stopwords(&mut self, words: &[&str])
pub fn add_stopwords(&mut self, words: &[&str])
Sourcepub fn clear_stopwords(&mut self)
pub fn clear_stopwords(&mut self)
Remove all stopwords from the filter
§Examples
// Allow searching for any word, including common ones
index.clear_stopwords();Sourcepub fn get_stopwords(&self) -> Vec<String>
pub fn get_stopwords(&self) -> Vec<String>
pub fn get_fuzzy_matches( &self, query: &str, max_distance: u32, ) -> Vec<(String, f32)>
pub fn highlight_matches(&self, text: &str, query: &str) -> String
Auto Trait Implementations§
impl Freeze for FullTextIndex
impl !RefUnwindSafe for FullTextIndex
impl Send for FullTextIndex
impl Sync for FullTextIndex
impl Unpin for FullTextIndex
impl !UnwindSafe for FullTextIndex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more