FIX: Use ILIKE for searching categories (#26619)

Full text search does not return ideal results for category dropdown.
Usually, in category dropdowns we want to search for categories as we
type. For example, while typing "theme", the dropdown should show
intermediary results for "t", "th", "the", "them" and finally "theme".
For some of these substrings (like "the"), full text search does not
return any results, which leads to an unpleasant user experience.
This commit is contained in:
Bianca Nenciu
2024-04-17 17:20:25 +03:00
committed by GitHub
parent 840ac6bd0a
commit c9a46cfdda
2 changed files with 6 additions and 9 deletions

View File

@ -366,13 +366,9 @@ class CategoriesController < ApplicationController
categories = Category.secured(guardian)
categories =
categories
.includes(:category_search_data)
.references(:category_search_data)
.where(
"category_search_data.search_data @@ #{Search.ts_query(term: term)}",
) if term.present?
if term.present? && words = term.split
words.each { |word| categories = categories.where("name ILIKE ?", "%#{word}%") }
end
categories =
(