Merge pull request '(FIX): Fixed issues with search.' (#47) from feature/search-fixes into master
Some checks failed
Deploy application with Docker / build_and_deploy (push) Failing after 1m39s
Some checks failed
Deploy application with Docker / build_and_deploy (push) Failing after 1m39s
Reviewed-on: #47
This commit is contained in:
commit
6e96c847ec
@ -369,7 +369,27 @@ func (r *RecipeRepository) SearchRecipes(filters domain.SearchFilters, userId *i
|
|||||||
// Create search vector query
|
// Create search vector query
|
||||||
var orderBy string = ""
|
var orderBy string = ""
|
||||||
if filters.Search != "" {
|
if filters.Search != "" {
|
||||||
vector_query := strings.ReplaceAll(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, " | ")
|
||||||
|
|
||||||
conditions = append(
|
conditions = append(
|
||||||
conditions,
|
conditions,
|
||||||
@ -377,8 +397,8 @@ func (r *RecipeRepository) SearchRecipes(filters domain.SearchFilters, userId *i
|
|||||||
)
|
)
|
||||||
|
|
||||||
template := `
|
template := `
|
||||||
ORDER BY
|
ORDER BY
|
||||||
ts_rank(r.search_vector, to_tsquery('english', '%s')) DESC,
|
ts_rank(r.search_vector, to_tsquery('english', '%s')) DESC,
|
||||||
ts_rank_cd(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)
|
orderBy = fmt.Sprintf(template, vector_query, vector_query)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user