[][src]Struct fuse_rust::Fuse

pub struct Fuse {
    pub location: i32,
    pub distance: i32,
    pub threshold: f64,
    pub max_pattern_length: i32,
    pub is_case_sensitive: bool,
    pub tokenize: bool,
}

Creates a new fuse object with given config settings Use to create patterns and access the search methods. Also implements a default method to quickly get a fuse object ready with the default config.

Examples:

Basic Usage:

let fuse = Fuse{
    location: 0,
    distance: 100,
    threshold: 0.6,
    max_pattern_length: 32,
    is_case_sensitive: false,
    tokenize: false,
};

Fields

location: i32

location to starting looking for patterns

distance: i32

maximum distance to look away from the location

threshold: f64

threshold for the search algorithm to give up at, 0.0 is perfect match 1.0 is imperfect match

max_pattern_length: i32

maximum allowed pattern length

is_case_sensitive: bool

check for lowercase and uppercase seperately

tokenize: bool

tokenize search patterns

Implementations

impl Fuse[src]

pub fn create_pattern(&self, string: &str) -> Option<Pattern>[src]

Creates a pattern object from input string.

  • Parameter string: A string from which to create the pattern object
  • Returns: A tuple containing pattern metadata

pub fn search(
    &self,
    pattern: Option<&Pattern>,
    string: &str
) -> Option<ScoreResult>
[src]

Searches for a pattern in a given string.

  • Parameters:
    • pattern: The pattern to search for. This is created by calling createPattern
    • string: The string in which to search for the pattern
  • Returns: Some(ScoreResult) if a match is found containing a score between 0.0 (exact match) and 1 (not a match), and ranges of the matched characters. If no match is found or if search pattern was empty will return None.

Example:

use fuse_rust::{ Fuse };
let fuse = Fuse::default();
let pattern = fuse.create_pattern("some text");
fuse.search(pattern.as_ref(), "some string");

impl Fuse[src]

pub fn search_text_in_string(
    &self,
    text: &str,
    string: &str
) -> Option<ScoreResult>
[src]

Searches for a text pattern in a given string.

  • Parameters:
    • text: the text string to search for.
    • string: The string in which to search for the pattern
  • Returns: Some(ScoreResult) if a match is found, containing a score between 0.0 (exact match) and 1 (not a match), and ranges of the matched characters. Otherwise if a match is not found, returns None.

Examples:

use fuse_rust::{ Fuse };
let fuse = Fuse::default();
fuse.search_text_in_string("some text", "some string");

Note: if the same text needs to be searched across many strings, consider creating the pattern once via createPattern, and then use the other search function. This will improve performance, as the pattern object would only be created once, and re-used across every search call:

use fuse_rust::{ Fuse };
let fuse = Fuse::default();
let pattern = fuse.create_pattern("some text");
fuse.search(pattern.as_ref(), "some string");
fuse.search(pattern.as_ref(), "another string");
fuse.search(pattern.as_ref(), "yet another string");

pub fn search_text_in_iterable<It>(
    &self,
    text: &str,
    list: It
) -> Vec<SearchResult> where
    It: IntoIterator,
    It::Item: AsRef<str>, 
[src]

Searches for a text pattern in an iterable containing string references.

  • Parameters:
    • text: The pattern string to search for
    • list: Iterable over string references
  • Returns: Vec containing Search results corresponding to matches found, with its index, its score, and the ranges of the matched characters.

Example:

use fuse_rust::{ Fuse };
let fuse = Fuse::default();
let books = [
    "The Silmarillion",
    "The Lock Artist",
    "The Lost Symbol"
];

let results = fuse.search_text_in_iterable("Te silm", books.iter());

pub fn search_text_in_string_list(
    &self,
    text: &str,
    list: &[&str],
    chunk_size: usize,
    completion: &dyn Fn(Vec<SearchResult>)
)
[src]

Asynchronously searches for a text pattern in a slice of string references.

  • Parameters:
    • text: The pattern string to search for
    • list: &[&str] A reference to a slice of string references.
    • chunkSize: The size of a single chunk of the array. For example, if the slice has 1000 items, it may be useful to split the work into 10 chunks of 100. This should ideally speed up the search logic.
    • completion: The handler which is executed upon completion

Example:

use fuse_rust::{ Fuse, SearchResult };
let fuse = Fuse::default();
let books = [
    "The Silmarillion",
    "The Lock Artist",
    "The Lost Symbol"
];

fuse.search_text_in_string_list("Te silm", &books, 100 as usize, &|x: Vec<SearchResult>| {
    dbg!(x);
});

pub fn search_text_in_fuse_list(
    &self,
    text: &str,
    list: &[impl Fuseable]
) -> Vec<FuseableSearchResult>
[src]

Searches for a text pattern in an array of Fuseable objects.

  • Parameters:
    • text: The pattern string to search for
    • list: A list of Fuseable objects, i.e. structs implementing the Fuseable trait in which to search
  • Returns: A list of FuseableSearchResult objects Each Fuseable object contains a properties method which returns FuseProperty array. Each FuseProperty is a struct containing a value (the name of the field which should be included in the search), and a weight (how much "weight" to assign to the score)

Example


struct Book<'a> {
   title: &'a str,
   author: &'a str,
}

impl Fuseable for Book<'_>{
    fn properties(&self) -> Vec<FuseProperty> {
        return vec!(
            FuseProperty{value: String::from("title"), weight: 0.3},
            FuseProperty{value: String::from("author"), weight: 0.7},
        )
    }

    fn lookup(&self, key: &str) -> Option<&str> {
        return match key {
            "title" => Some(self.title),
            "author" => Some(self.author),
            _ => None
        }
    }
}   
let books = [
    Book{author: "John X", title: "Old Man's War fiction"},
    Book{author: "P.D. Mans", title: "Right Ho Jeeves"},
];

let fuse = Fuse::default();
let results = fuse.search_text_in_fuse_list("man", &books);

pub fn search_text_in_fuse_list_with_chunk_size<T>(
    &self,
    text: &str,
    list: &[T],
    chunk_size: usize,
    completion: &dyn Fn(Vec<FuseableSearchResult>)
) where
    T: Fuseable + Sync
[src]

Asynchronously searches for a text pattern in an array of Fuseable objects.

  • Parameters:
    • text: The pattern string to search for
    • list: A list of Fuseable objects, i.e. structs implementing the Fuseable trait in which to search
    • chunkSize: The size of a single chunk of the array. For example, if the array has 1000 items, it may be useful to split the work into 10 chunks of 100. This should ideally speed up the search logic. Defaults to 100.
    • completion: The handler which is executed upon completion Each Fuseable object contains a properties method which returns FuseProperty array. Each FuseProperty is a struct containing a value (the name of the field which should be included in the search), and a weight (how much "weight" to assign to the score)

Example


struct Book<'a> {
   title: &'a str,
   author: &'a str,
}

impl Fuseable for Book<'_>{
    fn properties(&self) -> Vec<FuseProperty> {
        return vec!(
            FuseProperty{value: String::from("title"), weight: 0.3},
            FuseProperty{value: String::from("author"), weight: 0.7},
        )
    }

    fn lookup(&self, key: &str) -> Option<&str> {
        return match key {
            "title" => Some(self.title),
            "author" => Some(self.author),
            _ => None
        }
    }
}    
let books = [
    Book{author: "John X", title: "Old Man's War fiction"},
    Book{author: "P.D. Mans", title: "Right Ho Jeeves"},
];

let fuse = Fuse::default();
let results = fuse.search_text_in_fuse_list_with_chunk_size("man", &books, 1, &|x: Vec<FuseableSearchResult>| {
    dbg!(x);
});

Trait Implementations

impl Default for Fuse[src]

Auto Trait Implementations

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.