sublime_fuzzy
Fuzzy matching algorithm based on Sublime Text's string search. Iterates through characters of a search string and calculates a score based on matching consecutive/close groups of characters. Tries to find the best match by scoring multiple match paths.
Walks all paths through the string that is being searched. Which means it gets slow relatively quickly.
Documentation
Check out the documentation at docs.rs.
Usage
Basic usage:
use best_match;
let s = "some search thing";
let search = "something";
let result = best_match.unwrap;
// Output: score: 368
println!;
Match.continuous_matches()
returns a list of consecutive matches
((start_index, length)
). Based on those the input string can be formatted.
sublime_fuzzy
provides a simple formatting function that wraps matches in
tags.
use ;
let s = "some search thing";
let search = "something";
let result = best_match.unwrap;
// Output: <span>some</span> search <span>thing</span>
println!;
Matches are scored based on consecutively matching chars (bonus) and distance between two chars (penalty). The actual values can be adjusted.
use ;
let mut search = new;
let config = ScoreConfig ;
// Weight consecutive matching chars less.
search.set_score_config;
println!;
Note: This module removes any whitespace in the pattern ('something'
in the examples above). It does not apply any other formatting. Lowercasing
the inputs for example has to be done manually.