[][src]Struct simsearch::SimSearch

pub struct SimSearch<Id> where
    Id: PartialEq + Clone
{ /* fields omitted */ }

The simple search engine.

Implementations

impl<Id> SimSearch<Id> where
    Id: PartialEq + Clone
[src]

pub fn new() -> Self[src]

Creates search engine with default options.

pub fn new_with(option: SearchOptions) -> Self[src]

Creates search engine with custom options.

Examples

use simsearch::{SearchOptions, SimSearch};

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

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

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(&[",", "."]));

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.");

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

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."]);

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

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]);

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

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]);

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

Deletes entry by id.

Auto Trait Implementations

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.