Expand description
§Fuzzies
Fuzzy search crate for Rust.
More information about this crate can be found in the crate documentation
[!WARNING]
Early Development & Disclaimer: This project is in its early stages of development. Breaking changes may occur frequently and without warning between versions. This library is built by a university sophomore for personal learning and experimentation, not as a full-time, production-ready project. Use with caution!
§Installation
cargo add fuzzies§Example
This library allows you to build a compact, memory-mapped FST from a file and perform fast, fuzzy searches with configurable Levenshtein distances (supporting distances of 1 and 2).
use fuzzies::Dictionary;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// 1. Build the dictionary from a text file (one word per line)
// Note: The input file must be sorted lexicographically
Dictionary::build("words.txt", "words.fst")?;
// 2. Load the dictionary
let dict = Dictionary::open("words.fst")?;
// 3. Perform a fuzzy search with a max typo distance of 2 and limit of 5 results
let results = dict.search("baxaxa")
.distance(2)
.limit(5)
.execute()?;
for result in results {
println!("Found: {} (Exact: {})", result.key, result.is_exact);
}
// 4. Batch search (multithreaded, defaults to distance of 1)
let queries = vec!["aple", "baxana", "cherri"];
let batch_results = dict.batch_search(&queries);
for (query, result) in queries.iter().zip(batch_results) {
match result {
Ok(matches) => println!("Query '{}' found {} matches", query, matches.len()),
Err(e) => eprintln!("Error searching for '{}': {}", query, e),
}
}
Ok(())
}Structs§
- Dictionary
- A memory-mapped dictionary for fuzzy string lookups.
- FstDfa
Wrapper - A wrapper implementing
fst::Automatonfor a LevenshteinDFA. - Search
Builder - A builder for configuring and running a dictionary search query.
- Search
Result - An individual match from a fuzzy search query.