Struct simsearch::SearchOptions

source ·
pub struct SearchOptions { /* private fields */ }
Expand description

Options and flags that configuring the search engine.

§Examples

use simsearch::{SearchOptions, SimSearch};

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

Implementations§

source§

impl SearchOptions

source

pub fn new() -> Self

Creates a default configuration.

source

pub fn case_sensitive(self, case_sensitive: bool) -> Self

Sets whether search engine is case sensitive or not.

Defaults to false.

source

pub fn stop_whitespace(self, stop_whitespace: bool) -> Self

Sets the whether search engine splits tokens on whitespace or not. The whitespace here includes tab, returns and so forth.

See also std::str::split_whitespace().

Defaults to true.

source

pub fn stop_words(self, stop_words: Vec<String>) -> Self

Sets the custom token stop word.

This option enables tokenizer to split contents and search words by the extra list of custom stop words.

Defaults to &[].

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

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

engine.insert(1, "the old/man/and/the sea");

let results = engine.search("old");

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

pub fn threshold(self, threshold: f64) -> Self

Sets the threshold for search scoring.

Search results will be sorted by their Jaro winkler similarity scores. Scores ranges from 0 to 1 where the 1 indicates the most relevant. Only the entries with scores greater than the threshold will be returned.

Defaults to 0.8.

source

pub fn levenshtein(self, levenshtein: bool) -> Self

Sets whether Levenshtein distance, which is SIMD-accelerated, should be used instead of the default Jaro-Winkler distance.

The implementation of Levenshtein distance is very fast but cannot handle Unicode strings, unlike the default Jaro-Winkler distance. The strings are treated as byte slices with Levenshtein distance, which means that the calculated score may be incorrectly lower for Unicode strings, where each character is represented with multiple bytes.

Defaults to false.

Trait Implementations§

source§

impl Clone for SearchOptions

source§

fn clone(&self) -> SearchOptions

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 Debug for SearchOptions

source§

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

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

impl Default for SearchOptions

source§

fn default() -> Self

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

Auto Trait Implementations§

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.