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:

```rust use sublimefuzzy::bestmatch;

let s = "some search thing"; let search = "something"; let result = best_match(search, s).unwrap();

// Output: score: 368 println!("score: {:?}", result.score()); ```

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.

```rust use sublimefuzzy::{bestmatch, format_simple};

let s = "some search thing"; let search = "something"; let result = best_match(search, s).unwrap();

// Output: some search thing println!("formatted: {:?}", format_simple(&result, s, "", "")); ```

Matches are scored based on consecutively matching chars (bonus) and distance between two chars (penalty). The actual values can be adjusted.

```rust use sublime_fuzzy::{FuzzySearch, ScoreConfig};

let mut search = FuzzySearch::new("something", "some search thing");

let config = ScoreConfig { bonusconsecutive: 20, penaltydistance: 8 }; // Weight consecutive matching chars less. search.setscoreconfig(config);

println!("result: {:?}", search.best_match()); ```

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.