pub struct SimSearch<Id>{ /* private fields */ }
Expand description
The simple search engine.
Implementations§
source§impl<Id> SimSearch<Id>
impl<Id> SimSearch<Id>
sourcepub fn new_with(option: SearchOptions) -> Self
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));
sourcepub fn insert(&mut self, id: Id, content: &str)
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.");
sourcepub fn insert_tokens(&mut self, id: Id, tokens: &[&str])
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."]);
sourcepub fn search(&self, pattern: &str) -> Vec<Id>
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]);
sourcepub fn search_tokens(&self, pattern_tokens: &[&str]) -> Vec<Id>
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]);