Struct simsearch::SimSearch

source ·
pub struct SimSearch<Id>
where Id: Eq + PartialEq + Clone + Hash + Ord,
{ /* private fields */ }
Expand description

The simple search engine.

Implementations§

source§

impl<Id> SimSearch<Id>
where Id: Eq + PartialEq + Clone + Hash + Ord,

source

pub fn new() -> Self

Creates search engine with default options.

source

pub fn new_with(option: SearchOptions) -> Self

Creates search engine with custom options.

§Examples
use simsearch::{SearchOptions, SimSearch};

let mut engine: SimSearch<usize> = SimSearch::new_with(
    SearchOptions::new().case_sensitive(true));
source

pub fn insert(&mut self, id: Id, content: &str)

Inserts an entry into search engine.

Input will be tokenized according to the search option. By default whitespaces(including tabs) are considered as stop words, you can change the behavior by providing SearchOptions.

Insert with an existing id updates the content.

Note that id is not searchable. Add id to the contents if you would like to perform search on it.

Additionally, note that content must be an ASCII string if Levenshtein distance is used.

§Examples
use simsearch::{SearchOptions, SimSearch};

let mut engine: SimSearch<&str> = SimSearch::new_with(
    SearchOptions::new().stop_words(vec![",".to_string(), ".".to_string()]));

engine.insert("BoJack Horseman", "BoJack Horseman, an American
adult animated comedy-drama series created by Raphael Bob-Waksberg.
The series stars Will Arnett as the title character,
with a supporting cast including Amy Sedaris,
Alison Brie, Paul F. Tompkins, and Aaron Paul.");
source

pub fn insert_tokens(&mut self, id: Id, tokens: &[&str])

Inserts entry tokens into search engine.

Search engine also applies tokenizer to the provided tokens. Use this method when you have special tokenization rules in addition to the built-in ones.

Insert with an existing id updates the content.

Note that id is not searchable. Add id to the contents if you would like to perform search on it.

Additionally, note that each token must be an ASCII string if Levenshtein distance is used.

§Examples
use simsearch::SimSearch;

let mut engine: SimSearch<&str> = SimSearch::new();

engine.insert_tokens("Arya Stark", &["Arya Stark", "a fictional
character in American author George R. R", "portrayed by English actress."]);
source

pub fn search(&self, pattern: &str) -> Vec<Id>

Searches pattern and returns ids sorted by relevance.

Pattern will be tokenized according to the search option. By default whitespaces(including tabs) are considered as stop words, you can change the behavior by providing SearchOptions.

Additionally, note that pattern must be an ASCII string if Levenshtein distance is used.

§Examples
use simsearch::SimSearch;

let mut engine: SimSearch<u32> = SimSearch::new();

engine.insert(1, "Things Fall Apart");
engine.insert(2, "The Old Man and the Sea");
engine.insert(3, "James Joyce");

let results: Vec<u32> = engine.search("thngs apa");

assert_eq!(results, &[1]);
source

pub fn search_tokens(&self, pattern_tokens: &[&str]) -> Vec<Id>

Searches pattern tokens and returns ids sorted by relevance.

Search engine also applies tokenizer to the provided tokens. Use this method when you have special tokenization rules in addition to the built-in ones.

Additionally, note that each pattern token must be an ASCII string if Levenshtein distance is used.

§Examples
use simsearch::SimSearch;

let mut engine: SimSearch<u32> = SimSearch::new();

engine.insert(1, "Things Fall Apart");
engine.insert(2, "The Old Man and the Sea");
engine.insert(3, "James Joyce");

let results: Vec<u32> = engine.search_tokens(&["thngs", "apa"]);

assert_eq!(results, &[1]);
source

pub fn delete(&mut self, id: &Id)

Deletes entry by id.

Trait Implementations§

source§

impl<Id> Clone for SimSearch<Id>
where Id: Eq + PartialEq + Clone + Hash + Ord + Clone,

source§

fn clone(&self) -> SimSearch<Id>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<Id> Debug for SimSearch<Id>
where Id: Eq + PartialEq + Clone + Hash + Ord + Debug,

source§

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

Formats the value using the given formatter. Read more
source§

impl<Id> Default for SimSearch<Id>
where Id: Eq + PartialEq + Clone + Hash + Ord,

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<Id> Freeze for SimSearch<Id>

§

impl<Id> RefUnwindSafe for SimSearch<Id>
where Id: RefUnwindSafe,

§

impl<Id> Send for SimSearch<Id>
where Id: Send,

§

impl<Id> Sync for SimSearch<Id>
where Id: Sync,

§

impl<Id> Unpin for SimSearch<Id>
where Id: Unpin,

§

impl<Id> UnwindSafe for SimSearch<Id>
where Id: 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.