sublime_fuzzy
Fuzzy matching algorithm based on Sublime Text's string search. Iterates through characters of a search string and calculates a score.
The score is based on several factors:
- Word starts like the
t
insome_thing
get a bonus (bonus_word_start
) - Consecutive matches get an accumulative bonus for every consecutive match (
bonus_consecutive
) - Matches that also match case (
T
->T
instead oft
->T
) in case of a case-insensitive search get a bonus (bonus_match_case
) - The distance between two matches will be multiplied with the
penalty_distance
penalty and subtracted from the score
The default scoring is configured to give a lot of weight to word starts. So a pattern scc
will match
SoccerCartoonController, not SoccerCartoonController.
Match Examples
With default weighting.
Pattern | Target string | Result |
---|---|---|
scc |
SoccerCartoonController |
SoccerCartoonController |
something |
some search thing |
some search thing |
Usage
Basic usage:
use best_match;
let result = best_match;
assert!;
Match::continuous_matches
returns an iter of consecutive matches. Based on those the input
string can be formatted.
format_simple
provides a simple formatting that wraps matches in tags:
use ;
let target = "some search thing";
let result = best_match.unwrap;
assert_eq!;
The weighting of the different factors can be adjusted:
use ;
// Or pick from one of the provided `Scoring::...` methods like `emphasize_word_starts`
let scoring = Scoring ;
let result = new
.case_sensitive
.score_with
.best_match;
assert!
Note: Any whitespace in the pattern ('something'
in the examples above) will be removed.
Documentation
Check out the documentation at docs.rs.