Compare commits
No commits in common. "6e96c847ec03b727668a1e32e3e893a63d677181" and "535b8f1a6f94be4c1057e032cf8e66e097544b56" have entirely different histories.
6e96c847ec
...
535b8f1a6f
@ -369,27 +369,7 @@ func (r *RecipeRepository) SearchRecipes(filters domain.SearchFilters, userId *i
|
||||
// Create search vector query
|
||||
var orderBy string = ""
|
||||
if filters.Search != "" {
|
||||
spl := strings.Split(filters.Search, " ")
|
||||
var cleaned []string
|
||||
|
||||
// Use a string replacer, each word in the query will be passed through this
|
||||
replacer := strings.NewReplacer(
|
||||
"'", "",
|
||||
"-", "",
|
||||
"&", "",
|
||||
"|", "",
|
||||
"!", "",
|
||||
)
|
||||
|
||||
for i := range len(spl) {
|
||||
q := strings.TrimSpace(replacer.Replace(spl[i]))
|
||||
|
||||
if q != "" {
|
||||
cleaned = append(cleaned, q)
|
||||
}
|
||||
}
|
||||
|
||||
vector_query := strings.Join(cleaned, " | ")
|
||||
vector_query := strings.ReplaceAll(filters.Search, " ", " | ")
|
||||
|
||||
conditions = append(
|
||||
conditions,
|
||||
@ -397,8 +377,8 @@ func (r *RecipeRepository) SearchRecipes(filters domain.SearchFilters, userId *i
|
||||
)
|
||||
|
||||
template := `
|
||||
ORDER BY
|
||||
ts_rank(r.search_vector, to_tsquery('english', '%s')) DESC,
|
||||
ORDER BY
|
||||
ts_rank(r.search_vector, to_tsquery('english', '%s')) DESC,
|
||||
ts_rank_cd(r.search_vector, to_tsquery('english', '%s')) DESC
|
||||
`
|
||||
orderBy = fmt.Sprintf(template, vector_query, vector_query)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user