Crates.io | code-fuzzy-match |
lib.rs | code-fuzzy-match |
version | 0.2.2 |
source | src |
created_at | 2024-02-01 04:43:59.338419 |
updated_at | 2024-02-15 05:17:47.077115 |
description | Fuzzy string matching inspired by Visual Studio Code |
homepage | |
repository | https://github.com/D0ntPanic/code-fuzzy-match |
max_upload_size | |
id | 1122655 |
size | 45,855 |
Fuzzy string matching inspired by Visual Studio Code.
The fuzzy matching algorithm used in this crate is optimized for use cases such as command palettes, quick file navigation, and code searching. It does not use Levenshtein distance, which is more suited to use cases like spell checking.
The algorithm only allows matches where the characters in the query string are present and in the same order as the characters in the target string. All queries are substring queries, so it is not a major hit to the match score to search for a term in the middle of the target string. The algorithm prefers matches that are at the beginning of words in the target string, with words treated as they might appear in code (letters following a separator or in camel case are treated as a word). Sequential matches are also favored.
let mut matcher = code_fuzzy_match::FuzzyMatcher::new();
let matches = matcher.fuzzy_match("the quick brown fox", "bro fox");
assert!(matches.is_some());
let no_match = matcher.fuzzy_match("the quick brown fox", "cat");
assert!(no_match.is_none());
let high_score = matcher.fuzzy_match("Example string", "example");
let lower_score = matcher.fuzzy_match("Example string", "str");
assert!(high_score.unwrap() > lower_score.unwrap());