Giter Club home page Giter Club logo

Comments (4)

lithammer avatar lithammer commented on August 27, 2024

Do you have any good cyrillic strings I can add to the tests? Preferably a negative, positive and equal match.

from fuzzysearch.

artyom avatar artyom commented on August 27, 2024

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.

lithammer avatar lithammer commented on August 27, 2024

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.

lithammer avatar lithammer commented on August 27, 2024

Fixed by #6 (hopefully)

from fuzzysearch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.