Unified · Split
| @@ -13,6 +13,8 @@ fuzzyRegexp = # query fuzzy regexp · 12 unmodified lines | |||
| 13 | index = # position of the query in the string being matched | 13 | index = # position of the query in the string being matched |
| 14 | lastIndex = # last position of the query in the string being matched | 14 | lastIndex = # last position of the query in the string being matched |
| 15 | match = # regexp match data | 15 | match = # regexp match data |
| 16 | matchIndex = | ||
| 17 | matchLength = | ||
| 16 | score = # score for the current match | 18 | score = # score for the current match |
| 17 | separators = # counter | 19 | separators = # counter |
| 18 | i = null # cursor | 20 | i = null # cursor |
| @@ -74,16 +76,27 @@ return Math.max 1, score · 55 unmodified lines | |||
| 74 | `function fuzzyMatch() {` | 76 | `function fuzzyMatch() {` |
| 75 | return if valueLength <= queryLength or value.indexOf(query) >= 0 | 77 | return if valueLength <= queryLength or value.indexOf(query) >= 0 |
| 76 | return unless match = fuzzyRegexp.exec(value) | 78 | return unless match = fuzzyRegexp.exec(value) |
| 79 | matchIndex = match.index | ||
| 80 | matchLength = match[0].length | ||
| 81 | score = scoreFuzzyMatch() | ||
| 82 | if match = fuzzyRegexp.exec(value.slice(i = value.lastIndexOf(SEPARATOR) + 1)) | ||
| 83 | matchIndex = i + match.index | ||
| 84 | matchLength = match[0].length | ||
| 85 | return Math.max(score, scoreFuzzyMatch()) | ||
| 86 | else | ||
| 87 | return score | ||
| 88 | `}` | ||
| 77 | 89 | ||
| 90 | `function scoreFuzzyMatch() {` | ||
| 78 | # When the match is at the beginning of the string or preceded by a dot. | 91 | # When the match is at the beginning of the string or preceded by a dot. |
| 79 | if match.index is 0 or value.charAt(match.index - 1) is SEPARATOR | 92 | if matchIndex is 0 or value.charAt(matchIndex - 1) is SEPARATOR |
| 80 | return Math.max 66, 100 - match[0].length | 93 | return Math.max 66, 100 - matchLength |
| 81 | # When the match is at the end of the string. | 94 | # When the match is at the end of the string. |
| 82 | else if match.index + match[0].length is valueLength | 95 | else if matchIndex + matchLength is valueLength |
| 83 | return Math.max 33, 67 - match[0].length | 96 | return Math.max 33, 67 - matchLength |
| 84 | # When the match is in the middle of the string. | 97 | # When the match is in the middle of the string. |
| 85 | else | 98 | else |
| 86 | return Math.max 1, 34 - match[0].length | 99 | return Math.max 1, 34 - matchLength |
| 87 | `}` | 100 | `}` |
| 88 | 101 | ||
| 89 | # | 102 | # |