Handle unicode characters in autotag (#2336)

This commit is contained in:
WithoutPants
2022-02-28 13:12:43 +11:00
committed by GitHub
parent c5c94e783e
commit 1ab5be162e
6 changed files with 41 additions and 11 deletions

View File

@@ -21,6 +21,8 @@ WHERE performers_tags.tag_id = ?
GROUP BY performers_tags.performer_id
`
const singleFirstCharacterRegex = `^[\w\p{L}][.\-_ ]`
type performerQueryBuilder struct {
repository
}
@@ -184,7 +186,7 @@ func (qb *performerQueryBuilder) QueryForAutoTag(words []string) ([]*models.Perf
var args []interface{}
whereClauses = append(whereClauses, "name regexp ?")
args = append(args, "^[\\w][.\\-_ ]")
args = append(args, singleFirstCharacterRegex)
for _, w := range words {
whereClauses = append(whereClauses, "name like ?")

View File

@@ -171,6 +171,8 @@ func (r *repository) runSumQuery(query string, args []interface{}) (float64, err
}
func (r *repository) queryFunc(query string, args []interface{}, single bool, f func(rows *sqlx.Rows) error) error {
logger.Tracef("SQL: %s, args: %v", query, args)
rows, err := r.tx.Queryx(query, args...)
if err != nil && !errors.Is(err, sql.ErrNoRows) {

View File

@@ -145,7 +145,6 @@ func (qb *studioQueryBuilder) QueryForAutoTag(words []string) ([]*models.Studio,
var args []interface{}
// always include names that begin with a single character
singleFirstCharacterRegex := "^[\\w][.\\-_ ]"
whereClauses = append(whereClauses, "studios.name regexp ? OR COALESCE(studio_aliases.alias, '') regexp ?")
args = append(args, singleFirstCharacterRegex, singleFirstCharacterRegex)

View File

@@ -236,7 +236,6 @@ func (qb *tagQueryBuilder) QueryForAutoTag(words []string) ([]*models.Tag, error
var args []interface{}
// always include names that begin with a single character
singleFirstCharacterRegex := "^[\\w][.\\-_ ]"
whereClauses = append(whereClauses, "tags.name regexp ? OR COALESCE(tag_aliases.alias, '') regexp ?")
args = append(args, singleFirstCharacterRegex, singleFirstCharacterRegex)