Crates.io | sniffer-rs |
lib.rs | sniffer-rs |
version | 1.1.2 |
source | src |
created_at | 2024-09-06 20:03:25.354901 |
updated_at | 2024-10-26 10:20:45.027557 |
description | A library that simplifies fuzzy string matching in rust |
homepage | |
repository | https://github.com/Whiskers-Apps/sniffer-rs |
max_upload_size | |
id | 1366416 |
size | 62,619 |
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.
To install do this in your project:
cargo add sniffer-rs
Or add it manually in cargo.toml:
[dependencies]
sniffer-rs = "1.1.1"
The usage of the library is very simple. It provides 4 algorithms for searching and a sniffer object that contains sane defaults for searching.
let sniffer = Sniffer::new();
let matches = sniffer.matches("banana", "bana");
let sniffer = Sniffer::new().set_case_sensitive(true);
let matches = sniffer.matches("Banana", "banana");
Returns the amount of characters that are different.
let matches = get_levenshtein_distance("Banana", "banin3");
Returns the amount of positional characters different. It only works with same size strings.
let matches = get_hamming_distance("banana", "banin3")
Returns the difference in a percentage. From 0.0 to 1.0.
let matches = get_jaro_winkler_distance("banana", "banan")
Returns true if the characters are inside the string.
let matches = get_inner_match("Sprigatito", "agt");
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");
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);
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");
The people that are helping the project with minor or big changes.