Comments (4)
Do you have any good cyrillic strings I can add to the tests? Preferably a negative, positive and equal match.
from fuzzysearch.
Please see this diff — it should introduce 2 failing tests — with 2 and 3-byte wide characters:
diff --git i/fuzzy/fuzzy_test.go w/fuzzy/fuzzy_test.go
index 11d946c..08e86a7 100644
--- i/fuzzy/fuzzy_test.go
+++ w/fuzzy/fuzzy_test.go
@@ -19,6 +19,10 @@ var fuzzyTests = []struct {
{"art", "cartwheel", true, 6},
{"eeel", "cartwheel", false, -1},
{"dog", "cartwheel", false, -1},
+ {"ёлка", "ёлочка", true, 2},
+ {"ветер", "ёлочка", false, -1},
+ {"**", "中华人民共和国", true, 5},
+ {"日本", "中华人民共和国", false, -1},
}
func TestFuzzyMatch(t *testing.T) {
from fuzzysearch.
Thanks, that will surely help. Seems like I'm gonna have to tweak the LevenshteinDistance
function as well.
This is what I have so far at least, TestFuzzyMatch
now passes with your additional tests:
diff --git a/fuzzy/fuzzy.go b/fuzzy/fuzzy.go
index 2751121..666311c 100644
--- a/fuzzy/fuzzy.go
+++ b/fuzzy/fuzzy.go
@@ -1,5 +1,7 @@
package fuzzy
+import "unicode/utf8"
+
// Match returns true if needle matches haystack using a fuzzy-searching
// algorithm. Note that it doesn't implement Levenshtein distance (see
// RankMatch instead), but rather a simplified version where there's no
@@ -16,12 +18,11 @@ func Match(needle, haystack string) bool {
if nlen == hlen {
return needle == haystack
}
-
Outer:
- for i, j := 0, 0; i < nlen; i++ {
- for j < hlen {
- j++
- if needle[i] == haystack[j-1] {
+ for _, r1 := range needle {
+ for i, r2 := range haystack {
+ if r1 == r2 {
+ haystack = haystack[i+utf8.RuneLen(r2):]
continue Outer
}
}
from fuzzysearch.
Fixed by #6 (hopefully)
from fuzzysearch.
Related Issues (20)
- RankFind does not use Levenshtein distance to build results HOT 6
- Introduce gopkg support HOT 2
- new type for targets HOT 2
- Expose Normalize function
- RankMatch seems to be broken HOT 3
- Getting error:" github.com/lithammer/fuzzysearch: module github.com/lithammer/fuzzysearch@latest found (v1.1.2), but does not contain package github.com/lithammer/fuzzysearch" HOT 3
- Document differences with bevacqua/fuzzysearch HOT 1
- Add case insensitive RankFind HOT 2
- New Release + upgrade to go 1.18. HOT 5
- Unecessary alocations due to transformer.Nop HOT 2
- Exact match mode?
- Change LevenshteinDistance to Damerau–Levenshtein distance? HOT 4
- Using MaxInt instead of -1
- Use of CMOV instruction in Levenshtein's minimum function HOT 1
- mishandling of utf8 replacement character HOT 2
- support a method for returning matched indices for characters
- support match for reversed words
- panic in transform.go when it's trying to reslice HOT 2
- Case insensetivity HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fuzzysearch.