MM-47374: Revert full text search (#21233)
* Revert "MM-46871: Add remining search parameters to be escaped (#20963)" This reverts commit8797bfcde7. * Revert "MM-46503: Escape incorrect pg user search query (#20863)" This reverts commit8fd1762c3b. * Revert "MM-44576 autocomplete names including utf 8 chars (#20367)" This reverts commit8444c45959.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
10655a2eb3
Коммит
70c74fc10d
@@ -1509,34 +1509,17 @@ func generateSearchQuery(query sq.SelectBuilder, terms []string, fields []string
|
||||
for _, term := range terms {
|
||||
searchFields := []string{}
|
||||
termArgs := []any{}
|
||||
var dbSpecificTerm string
|
||||
|
||||
if isPostgreSQL {
|
||||
// Refer to https://www.postgresql.org/docs/current/functions-textsearch.html for the list of operators.
|
||||
for _, c := range []string{":", "(", ")", "<", "!", "|"} {
|
||||
// Escaping the special chars in case of a Postgres search.
|
||||
term = strings.ReplaceAll(term, c, "\\"+c)
|
||||
}
|
||||
}
|
||||
|
||||
for _, field := range fields {
|
||||
if isPostgreSQL {
|
||||
if strings.TrimLeft(term, "@") == "" {
|
||||
// For wildcard search, we need to fall back to pattern matching.
|
||||
searchFields = append(searchFields, fmt.Sprintf("%s ILIKE ? escape '*' ", field))
|
||||
dbSpecificTerm = fmt.Sprintf("%s%%", strings.TrimLeft(term, "@"))
|
||||
} else {
|
||||
searchFields = append(searchFields, fmt.Sprintf("to_tsvector(lower(%[1]s)) @@ to_tsquery(concat(lower(?),':*'))", field))
|
||||
dbSpecificTerm = strings.TrimLeft(term, "@")
|
||||
}
|
||||
searchFields = append(searchFields, fmt.Sprintf("lower(%s) LIKE lower(?) escape '*' ", field))
|
||||
} else {
|
||||
searchFields = append(searchFields, fmt.Sprintf("%s LIKE ? escape '*' ", field))
|
||||
dbSpecificTerm = fmt.Sprintf("%s%%", strings.TrimLeft(term, "@"))
|
||||
}
|
||||
termArgs = append(termArgs, dbSpecificTerm)
|
||||
termArgs = append(termArgs, fmt.Sprintf("%s%%", strings.TrimLeft(term, "@")))
|
||||
}
|
||||
query = query.Where(fmt.Sprintf("(%s)", strings.Join(searchFields, " OR ")), termArgs...)
|
||||
}
|
||||
|
||||
return query
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user