Struct SearchIndexPrefixTree

Source
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>

Source

pub fn new() -> Self

Creates a new SearchIndexPrefixTree.

§Example
use attribute_search_engine::SearchIndexPrefixTree;

let index = SearchIndexPrefixTree::<usize>::new();
Source

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> Default for SearchIndexPrefixTree<P>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<P: Eq + Hash + Clone> SearchIndex<P> for SearchIndexPrefixTree<P>

Source§

fn search(&self, query: &Query) -> Result<HashSet<P>>

Perform a search on an index. Read more
Source§

fn supported_queries(&self) -> SupportedQueries

Returns which queries are directly supported by an index. Read more

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> 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, 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.