fix: naming match

This commit is contained in:
Simon Ding
2024-07-16 18:58:13 +08:00
parent fb04ca03d3
commit 6bc3a6f49e
2 changed files with 14 additions and 5 deletions

View File

@@ -2,8 +2,11 @@ package utils
import ( import (
"regexp" "regexp"
"strings"
"unicode" "unicode"
"github.com/adrg/strutil"
"github.com/adrg/strutil/metrics"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
"golang.org/x/exp/rand" "golang.org/x/exp/rand"
) )
@@ -48,3 +51,11 @@ func RandString(n int) string {
} }
return string(b) return string(b)
} }
func IsNameAcceptable(name1, name2 string) bool {
re := regexp.MustCompile(`[^\p{L}\w\s]`)
name1 = re.ReplaceAllString(strings.ToLower(name1), "")
name2 = re.ReplaceAllString(strings.ToLower(name2), "")
return strutil.Similarity(name1, name2, metrics.NewHamming()) > 0.1
}

View File

@@ -9,12 +9,11 @@ import (
"polaris/log" "polaris/log"
"polaris/pkg/torznab" "polaris/pkg/torznab"
"polaris/pkg/transmission" "polaris/pkg/transmission"
"polaris/pkg/utils"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
"github.com/adrg/strutil"
"github.com/adrg/strutil/metrics"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@@ -226,9 +225,8 @@ func (s *Server) SearchAvailableMovies(c *gin.Context) (interface{}, error) {
if !strings.Contains(r.Name, strconv.Itoa(year)) && !strings.Contains(r.Name, strconv.Itoa(year+1)) && !strings.Contains(r.Name, strconv.Itoa(year-1)) { if !strings.Contains(r.Name, strconv.Itoa(year)) && !strings.Contains(r.Name, strconv.Itoa(year+1)) && !strings.Contains(r.Name, strconv.Itoa(year-1)) {
continue //not the same movie, if year is not correct continue //not the same movie, if year is not correct
} }
distCn := strutil.Similarity(strings.ToLower(r.Name), movieDetail.NameCn, metrics.NewHamming())
distEn := strutil.Similarity(strings.ToLower(r.Name), strings.ToLower(movieDetail.NameEn), metrics.NewHamming()) if !utils.IsNameAcceptable(r.Name, movieDetail.NameCn) && !utils.IsNameAcceptable(r.Name, movieDetail.NameEn) {
if distCn == 0 && distEn == 0 {
continue //name not match continue //name not match
} }
searchResults = append(searchResults, TorznabSearchResult{ searchResults = append(searchResults, TorznabSearchResult{