Skip to main content

Module fuzzy

Module fuzzy 

Source
Expand description

Fuzzy matching for search fields (the command palette, the settings filter): the query’s characters in order in the text, not necessarily next to each other, scored so that matches at word starts, in runs and early in the text come first.

Owned rather than adopted: nucleo-matcher is MPL-2.0 (refused by the licence policy), fuzzy-matcher and sublime_fuzzy are unmaintained and give no say over the word starts this needs (Category: Title).

use egui_pop_model::fuzzy;

let m = fuzzy::score("opf", "File: Open file").unwrap();
assert_eq!(m.positions, [6, 7, 11]); // `Op`en `f`ile
assert!(fuzzy::score("zz", "File: Open file").is_none());

Structs§

Fields
The fields of one thing a search field looks through (a setting, a page), each of a Tier: labels and keywords are matched fuzzily (score), descriptions by words and word prefixes (word_prefix), so a long description does not match a word whose letters it merely holds in order. Each field is matched on its own: a word never spans two fields.
Found
What a search found in Fields: the worst tier any of the query’s words needed, and the words’ summed score. Sorting ascending puts the best first (tier, then the higher score).
Match
A match: its score (higher is better) and the matched characters’ indices (in chars) in the text.

Enums§

Tier
Which kind of field a search word was found in, best first: a label before a keyword, a keyword before a description.

Functions§

rank
The items matching query, best first (ties keep their order), each with its match.
score
Matches query (spaces ignored, case-insensitive) in text; none when its characters are not all there in order. An empty query matches everything with a score of 0.
word_prefix
Matches word (one word of a query, case-insensitive) at the start of a word of text: the whole word or its beginning, never letters scattered over several words. For long text, such as a description, where score would find almost any short word somewhere.