Fixed an edge case fuzzy matching bug.
MODIFY
util/fuzzy/fuzzy.go
util/fuzzy/fuzzy.go
@@ -79,6 +79,9 @@ func Score(needle, haystack string) float64 {
j = letterIndex
}
+ if j == haystackLength-1 && i < needleLength-1 {
+ return -1
+ }
}
return score
}

MODIFY
util/fuzzy/fuzzy_test.go
util/fuzzy/fuzzy_test.go
@@ -56,4 +56,8 @@ func TestFuzzyScore(t *testing.T) {
t.Errorf("Unexpected score difference.\n")
}
+ if Score("Hual#1299 ", "Thur_MaliGnY#1112") >= 0 {
+ t.Errorf("Unexpected non-negative score")
+ }
+
}

Fixed an edge case fuzzy matching bug.