pub struct SearchIndexPrefixTree<P> { /* private fields */ }
Expand description
SearchIndexPrefixTree is a index backed by a prefix tree that can match Exact and Prefix queries. It can only store String attribute values.
§Example
use attribute_search_engine::{SearchIndex, SearchIndexPrefixTree};
use std::collections::HashSet;
use attribute_search_engine::Query;
let mut index_firstname = SearchIndexPrefixTree::<usize>::new();
index_firstname.insert(0, "Alex".into());
index_firstname.insert(1, "Alexander".into());
index_firstname.insert(2, "Andrea".into());
index_firstname.insert(3, "Ben".into());
let result = index_firstname.search(&Query::Exact("<unused>".into(), "Alex".into()));
assert_eq!(result, Ok(HashSet::from_iter(vec![0])));
let result = index_firstname.search(&Query::Prefix("<unused>".into(), "Alex".into()));
assert_eq!(result, Ok(HashSet::from_iter(vec![0, 1])));
Implementations§
Source§impl<P: Eq + Hash + Clone> SearchIndexPrefixTree<P>
impl<P: Eq + Hash + Clone> SearchIndexPrefixTree<P>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new SearchIndexPrefixTree
.
§Example
use attribute_search_engine::SearchIndexPrefixTree;
let index = SearchIndexPrefixTree::<usize>::new();
Sourcepub fn insert(&mut self, primary_id: P, attribute_value: String)
pub fn insert(&mut self, primary_id: P, attribute_value: String)
Insert a new entry in the index.
§Example
use attribute_search_engine::SearchIndexPrefixTree;
let mut index = SearchIndexPrefixTree::<usize>::new();
// You insert an entry by giving a row / primary id and an attribute value:
index.insert(123, "Hello".into());
// The same row / primary id can have multiple attributes assigned:
index.insert(123, "World".into());
// Add as much entries as you want for as many rows you want:
index.insert(124, "Rust".into());
Trait Implementations§
Source§impl<P: Eq + Hash + Clone> SearchIndex<P> for SearchIndexPrefixTree<P>
impl<P: Eq + Hash + Clone> SearchIndex<P> for SearchIndexPrefixTree<P>
Auto Trait Implementations§
impl<P> Freeze for SearchIndexPrefixTree<P>
impl<P> RefUnwindSafe for SearchIndexPrefixTree<P>where
P: RefUnwindSafe,
impl<P> Send for SearchIndexPrefixTree<P>where
P: Send,
impl<P> Sync for SearchIndexPrefixTree<P>where
P: Sync,
impl<P> Unpin for SearchIndexPrefixTree<P>where
P: Unpin,
impl<P> UnwindSafe for SearchIndexPrefixTree<P>where
P: UnwindSafe,
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