Prioritize exact substring matches over fuzzy-only matches#484
Open
tavian-dev wants to merge 1 commit into
Open
Prioritize exact substring matches over fuzzy-only matches#484tavian-dev wants to merge 1 commit into
tavian-dev wants to merge 1 commit into
Conversation
When fuzzy matching is enabled, commands containing the exact search string as a substring are now always ranked above fuzzy-only matches. This preserves the benefit of fuzzy matching (finding commands you don't exactly remember) while ensuring that the most relevant results aren't buried. Within each tier (exact or fuzzy), the existing ranking logic is preserved: shorter and earlier matches are preferred, weighted by the configurable fuzzy factor on top of the neural network rank. Case sensitivity follows the existing behavior: if the search input contains uppercase characters, exact match checking is case-sensitive; otherwise it is case-insensitive. Fixes cantino#183
Owner
|
Thanks @tavian-dev! What do you think of this @dmfay? |
Contributor
|
I like the idea! The comment it blew away describing the weighting in detail is important though -- overeager LLM? |
Owner
|
Any chance you could test it @dmfay and make sure it still works for your mcfly use? I don't use fuzzy match. |
cantino
reviewed
May 13, 2026
| names = names | ||
| .into_iter() | ||
| .sorted_unstable_by(|a, b| { | ||
| // Fuzzy matches impose new ordering criteria on top of the |
Owner
There was a problem hiding this comment.
Can you please add this comment back?
Contributor
|
having taken it for a spin:
I still like the idea of thumbing the scale harder for exact matches above and beyond |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When fuzzy matching is enabled (
MCFLY_FUZZY), commands containing the exact search string as a substring are now always ranked above fuzzy-only matches. This directly addresses the core issue: exact matches getting buried by fuzzy results.How it works
The fuzzy re-ranking comparator now has two tiers:
Exact matches first: If command A contains the search string as an exact substring and command B doesn't, A always ranks higher — regardless of the fuzzy position/length scoring.
Existing logic within tiers: When both commands are exact matches, or both are fuzzy-only, the existing ranking applies (shorter matches, earlier position, neural network rank, fuzzy factor weighting).
Case sensitivity follows existing behavior: if the search input contains uppercase characters, exact matching is case-sensitive; otherwise case-insensitive.
Example
Searching for
git pushwithMCFLY_FUZZY=2:Before:
git pull --set-upstream-historycould rank abovegit push origin mainbecause the fuzzy position/length heuristic favored it.After:
git push origin main(exact substring match) always ranks abovegit pull --set-upstream-history(fuzzy-only match). Within exact matches, the neural network rank + fuzzy heuristics still determine order.Testing
Fixes #183