[][src]Struct simsearch::SimSearch

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

The simple search engine.

Methods

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 by the built-in tokenizer, by default whitespaces(including tabs) are considered as stop words, you can change the behavior by providing SearchOptions.

Search engine will delete the existing entry with same id before inserting the new one.

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

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_tokenized(&mut self, id: Id, tokens: &[&str])[src]

Inserts a pre-tokenized entry into search engine.

Search engine will apply built-in tokenizer on the provided tokens again. Use this method when you have special tokenizing rules in addition to the built-in ones.

Search engine will delete the existing entry with same id before inserting the new one.

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

Examples

use simsearch::SimSearch;

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

engine.insert_tokenized("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 for pattern and returns ids sorted by relevance.

Pattern will be tokenized by the built-in tokenizer, by default whitespaces(including tabs) are considered as stop words, you can change the behavior by providing SearchOptions.

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_tokenized(&self, pattern_tokens: &[&str]) -> Vec<Id>[src]

Searches for pre-tokenized pattern and returns ids sorted by relevance.

Search engine will apply built-in tokenizer on the provided tokens again. Use this method when you have special tokenizing rules in addition to the built-in ones.

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

assert_eq!(results, &[1]);

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

Deletes entry by id.

Auto Trait Implementations

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

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

Blanket Implementations

impl<T> From for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

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

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

The type returned in the event of a conversion error.