-
-
Notifications
You must be signed in to change notification settings - Fork 969
Add typo-resistency to filter graceful #4745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 9 commits
077fdc8
78a3a00
99e9a16
61e7475
052b118
5bfe457
30f35d2
1b60717
a350c9e
ad9947f
0b321c6
8f09c11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -81,21 +81,47 @@ function fuzzyScoreWithPermutations(pattern: string, lowPattern: string, pattern | |||||||||||||||||||||||||||||||
| // permutations of the pattern to find a better match. The | ||||||||||||||||||||||||||||||||
| // permutations only swap neighbouring characters, e.g | ||||||||||||||||||||||||||||||||
| // `cnoso` becomes `conso`, `cnsoo`, `cnoos`. | ||||||||||||||||||||||||||||||||
| const tries = Math.min(7, pattern.length - 1) | ||||||||||||||||||||||||||||||||
| for (let movingPatternPos = patternPos + 1; movingPatternPos < tries; movingPatternPos++) { | ||||||||||||||||||||||||||||||||
| const newPattern = nextTypoPermutation(pattern, movingPatternPos) | ||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||
| // For the last 2 permutations try to remove the last characters, | ||||||||||||||||||||||||||||||||
| // maybe the last few letters are typos. For example, | ||||||||||||||||||||||||||||||||
| // `conson` could be a typo for `console` | ||||||||||||||||||||||||||||||||
| const maxTriesPermutation = Math.min(7, pattern.length - 1); | ||||||||||||||||||||||||||||||||
| const maxTries = maxTriesPermutation + pattern.length; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // Loop for existing permutations | ||||||||||||||||||||||||||||||||
fannheyward marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||
| for (let i = 1; i <= maxTriesPermutation; i++) { | ||||||||||||||||||||||||||||||||
| const newPattern = nextTypoPermutation(pattern, patternPos + i); | ||||||||||||||||||||||||||||||||
| checkAndUpdateTopCandidate(newPattern, 3); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| const lastChar = pattern.charAt(pattern.length - 1); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if ((/[a-zA-Z0-9]/.test(lastChar))) { | ||||||||||||||||||||||||||||||||
fannheyward marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||
| // Loop for removing characters at all positions | ||||||||||||||||||||||||||||||||
| for (let i = 0; i < pattern.length; i++) { | ||||||||||||||||||||||||||||||||
fannheyward marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||
| const newPattern = pattern.slice(0, i) + pattern.slice(i + 1); | ||||||||||||||||||||||||||||||||
| checkAndUpdateTopCandidate(newPattern, 4); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
fannheyward marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||
| // Loop for removing last characters | ||||||||||||||||||||||||||||||||
| for (let i = 1; i < 3; i++) { | ||||||||||||||||||||||||||||||||
| const newPattern = pattern.slice(0, pattern.length - i); | ||||||||||||||||||||||||||||||||
| checkAndUpdateTopCandidate(newPattern, i+4); | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
| 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); |
Uh oh!
There was an error while loading. Please reload this page.