SimpleSearch

Struct SimpleSearch 

Source
pub struct SimpleSearch {
    pub algorithm: Algorithm,
    pub distance: fn(&str, &str) -> f64,
    pub max_edits: Option<i32>,
    pub similarity_threshold: Option<f64>,
    pub targets: Vec<String>,
}
Expand description

A struct to hold the input into a Simple Search.

Simple Search focuses on comparing strings which could be anything provided by the user.

Simple Search uses SimpleSearch and SimpleResult to hold the input and output data.

Fields§

§algorithm: Algorithm

The Algorithm to use.

§distance: fn(&str, &str) -> f64

The distance function to use, based on the Algorithm selected.

§max_edits: Option<i32>

The maximum number of edits allowed.

This can be None if the user does not want to limit the results based on the number of edits.

This should be None if the Algorithm is not an edit distance.

§similarity_threshold: Option<f64>

The minimum similarity score required.

This can be None if the user does not want to limit the results based on the similarity score.

§targets: Vec<String>

The target search words in the format of a vector of strings.

Implementations§

Source§

impl SimpleSearch

Source

pub fn new( algorithm: Algorithm, distance: fn(&str, &str) -> f64, max_edits: Option<i32>, similarity_threshold: Option<f64>, targets: &[String], ) -> SimpleSearch

Create a new SimpleSearch struct.

Trait Implementations§

Source§

impl Search for SimpleSearch

Source§

fn scan( &self, text: &str, record: Option<String>, state: &mut Option<HashMap<(String, String), f64>>, ) -> Vec<SearchOutput>

Scanning function to find matches.

Searches the input text for the target words. This also does some pre-processing to remove punctuation and other non-alphanumeric characters as well as upper-casing the input text.

The search will be limited by the number of edits and/or similarity threshold (if) provided in the SimpleSearch struct.

The results will be returned as a vector of SimpleResult structs.

§Examples

TODO: Add examples

let search = SimpleSearch::new(Algorithm::Levenshtein, levenshtein, None, None, &["hello", "world"]);
let results = search.scan("hello world", None);

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

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

Source§

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.