Expand description
Fuzzy matching, scored the way fzf scores it.
The point is not to invent a good matcher, it is to not surprise anyone. A person who reaches for a fuzzy finder has one already calibrated in their fingers, and if datui ranks differently the filter feels broken rather than different.
fzf is the shared ancestor: fzf itself, fzf-lua, Telescope with
telescope-fzf-native, and snacks.picker — which is a direct port of
fzf/src/algo/algo.go — all agree on the behaviour this implements. The scoring
constants below are fzf’s.
What that buys, concretely:
- a match right after
/or_beats one in the middle of a word - consecutive characters beat scattered ones
- a match in the file name beats one in a directory along the way
- the best alignment wins, not the first one found scanning left to right
That last property is the one people notice. Matching revdetail against
warehouse/2024/q3/revenue_detail.parquet greedily puts re inside warehouse;
every mainstream finder puts it on revenue, because it tries every starting
position and keeps the highest score.
Structs§
- Match
- A successful match: how good it is, and exactly which characters made it.
Functions§
- best_
match - Best fuzzy match of
needleinhaystack, orNoneif it does not match at all. - is_
match - Whether
needlematches at all, without paying for the scoring. - substring_
rank - Where a needle sits in a name, for a list narrowed by substring: the whole name
(0), its start (1), or inside it (2).
Nonewhen the name does not contain it. Case-insensitive; an empty needle is inside every name.