fix: address code review findings

This commit is contained in:
2026-07-19 19:45:08 +03:00
parent beef81d598
commit a7803615cd
7 changed files with 185 additions and 94 deletions

View File

@@ -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.