sniffer-rs

Crates.iosniffer-rs
lib.rssniffer-rs
version1.1.2
sourcesrc
created_at2024-09-06 20:03:25.354901
updated_at2024-10-26 10:20:45.027557
descriptionA library that simplifies fuzzy string matching in rust
homepage
repositoryhttps://github.com/Whiskers-Apps/sniffer-rs
max_upload_size
id1366416
size62,619
lighttigerXIV (lighttigerXIV)

documentation

README

About

Sniffer is a library for fuzzy matching strings in rust. For example ybe is a match for Youtube. This provides a easy and user friendly way to search for a match without the need for a lot of code.

Install

To install do this in your project:

cargo add sniffer-rs

Or add it manually in cargo.toml:

[dependencies]
sniffer-rs = "1.1.1"

Usage

The usage of the library is very simple. It provides 4 algorithms for searching and a sniffer object that contains sane defaults for searching.

Basic match

let sniffer = Sniffer::new();
let matches = sniffer.matches("banana", "bana");

Case sensitive match

let sniffer = Sniffer::new().set_case_sensitive(true);
let matches = sniffer.matches("Banana", "banana");

Levenshtein Algorithm

Returns the amount of characters that are different.

let matches = get_levenshtein_distance("Banana", "banin3");

Hamming Algorithm

Returns the amount of positional characters different. It only works with same size strings.

let matches = get_hamming_distance("banana", "banin3")

Jaro Winkler Algorithm

Returns the difference in a percentage. From 0.0 to 1.0.

let matches = get_jaro_winkler_distance("banana", "banan")

Inner Algorithm

Returns true if the characters are inside the string.

let matches = get_inner_match("Sprigatito", "agt");

Contain Match

Returns true if the search string is inside the the original. It matches even if it has spaces.

let contains = get_contain_match("youtube", "utu");
let contains = get_contain_match("macacos me mordam", "smem");

Sniffer

The sniffer match object can be changed in its initialization in case you don't like the default values.

let sniffer = Sniffer().set_levenshtein_distance(2)
                .set_do_levenshtein_match(true)
                .set_hamming_distance(2)
                .set_do_hamming_match(true)
                .set_jaro_winkler_distance(0.8)
                .set_do_jaro_winkler_match(true)
                .set_do_inner_match(true)
                .set_do_contain_match(false)
                .set_case_sensitive(false);

Sniffer Result

The sniffer result returns the values of the algorithms from a match. It's more appropriate for debuging.

let result = get_sniffer_result("Luxray", "lux");

Contributors

The people that are helping the project with minor or big changes.

Commit count: 15

cargo fmt