MM-44576 autocomplete names including utf 8 chars (#20367)

* Added unaccent extension

* Changed comment

* Deletes migrations, changes query method

* Mionr changes

* Creates test for multilingual queries

* Minor formatting changes

* Adds two more tests

* Changes name in test function

* Minor change

* Retriggers tests

* Removes % from Postgres query

* Lint fix

* Changes variable name

* Removes SetDefaultTextSearchConfig method

* Removes mocks

* Adds error handling on test raw queries

* Lint fix

* Deletes unused generated file

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Dimitris Oik
2022-08-01 13:58:31 +03:00
коммит произвёл GitHub
родитель 55f64195b1
Коммит 8444c45959
2 изменённых файлов: 178 добавлений и 3 удалений

Просмотреть файл

@@ -1500,17 +1500,20 @@ func generateSearchQuery(query sq.SelectBuilder, terms []string, fields []string
for _, term := range terms {
searchFields := []string{}
termArgs := []any{}
var dbSpecificTerm string
for _, field := range fields {
if isPostgreSQL {
searchFields = append(searchFields, fmt.Sprintf("lower(%s) LIKE lower(?) escape '*' ", field))
searchFields = append(searchFields, fmt.Sprintf("to_tsvector(lower(%[1]s)) @@ to_tsquery(concat(lower(?),':*'))", field))
dbSpecificTerm = strings.TrimLeft(term, "@")
} else {
searchFields = append(searchFields, fmt.Sprintf("%s LIKE ? escape '*' ", field))
dbSpecificTerm = fmt.Sprintf("%s%%", strings.TrimLeft(term, "@"))
}
termArgs = append(termArgs, fmt.Sprintf("%s%%", strings.TrimLeft(term, "@")))
termArgs = append(termArgs, dbSpecificTerm)
}
query = query.Where(fmt.Sprintf("(%s)", strings.Join(searchFields, " OR ")), termArgs...)
}
return query
}