fix: address code review findings
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
package scanner
|
||||
|
||||
import (
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/lithammer/fuzzysearch/fuzzy"
|
||||
"naviwatcher/internal/normalize"
|
||||
)
|
||||
@@ -44,10 +46,13 @@ func Similarity(a, b string) float64 {
|
||||
return 0.0
|
||||
}
|
||||
|
||||
// fuzzy.LevenshteinDistance operates on runes, so the comparison basis
|
||||
// must be rune count, not byte length, to avoid biasing the score for
|
||||
// non-ASCII titles (where bytes > runes).
|
||||
dist := fuzzy.LevenshteinDistance(na, nb)
|
||||
maxLen := len(na)
|
||||
if len(nb) > maxLen {
|
||||
maxLen = len(nb)
|
||||
maxLen := utf8.RuneCountInString(na)
|
||||
if rb := utf8.RuneCountInString(nb); rb > maxLen {
|
||||
maxLen = rb
|
||||
}
|
||||
|
||||
// 1.0 - normalized distance → higher is more similar.
|
||||
|
||||
Reference in New Issue
Block a user