Add typo-resistency to filter graceful#4745
Add typo-resistency to filter graceful#4745hanspinckaers wants to merge 12 commits intoneoclide:masterfrom
Conversation
…a char" This reverts commit 5bfe457.
|
Still fine-tuning the code, will correct later |
There was a problem hiding this comment.
Pull request overview
This PR enhances the fuzzy matching algorithm to be more resilient to typing errors by adding character removal strategies alongside the existing character permutation approach. When a user makes a typo while typing, the enhanced algorithm can now match patterns even when extra characters are present in the search string.
Key Changes
- Extended the typo-correction algorithm to try removing characters at any position in the pattern (not just permutations)
- Added specific handling for removing the last 1-2 characters, which are common typo locations
- Introduced a penalty-based scoring system to rank different correction strategies
- Refactored the permutation loop logic for consistency
Comments suppressed due to low confidence (1)
src/util/filter.ts:89
- Unused variable maxTries.
const maxTries = maxTriesPermutation + pattern.length;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/util/filter.ts
Outdated
| checkAndUpdateTopCandidate(newPattern, 4); | ||
| } | ||
|
|
||
| // Loop for removing last characters | ||
| for (let i = 1; i < 3; i++) { | ||
| const newPattern = pattern.slice(0, pattern.length - i); | ||
| checkAndUpdateTopCandidate(newPattern, i+4); |
There was a problem hiding this comment.
The penalty system is inconsistent and potentially incorrect:
- Character permutations (line 94): penalty of 3
- Removing any character at any position (line 103): penalty of 4
- Removing last 1 character (line 109 when i=1): penalty of 5
- Removing last 2 characters (line 109 when i=2): penalty of 6
This means removing the last character has a higher penalty (5) than removing a character in the middle (4), which seems counterintuitive since typos at the end are more common than in the middle. Consider revising the penalty structure to be more logical, for example:
- Permutations: 3
- Remove last 1 char: 4
- Remove last 2 chars: 5
- Remove middle chars: 6 (higher penalty since less likely to be a typo)
| checkAndUpdateTopCandidate(newPattern, 4); | |
| } | |
| // Loop for removing last characters | |
| for (let i = 1; i < 3; i++) { | |
| const newPattern = pattern.slice(0, pattern.length - i); | |
| checkAndUpdateTopCandidate(newPattern, i+4); | |
| // Penalty 6 for removing middle chars (less likely typo) | |
| checkAndUpdateTopCandidate(newPattern, 6); | |
| } | |
| // Loop for removing last characters | |
| for (let i = 1; i < 3; i++) { | |
| // Penalty 4 for last char, 5 for last two chars | |
| checkAndUpdateTopCandidate(newPattern, i + 3); |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Hi there,
I often mistype, or create a small typo, needing to backspace. On backspace I can retrigger autocomplete, but then I loose the previous results / fuzzy filtering. This commit adds a bit more leeway for making typing errors.
Thanks for the plugin and work!