A platform for community discussion. Free, open, simple.
FIX: Use ILIKE for searching categories (#26619)
Bianca Nenciuc9a46cfdda21
diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rbindex 8cb422cabde..e8c7098099c 100644--- a/app/controllers/categories_controller.rb+++ b/app/controllers/categories_controller.rb@@ -366,13 +366,9 @@ class CategoriesController < ApplicationControllercategories = 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}%") }+ endcategories =(diff --git a/spec/requests/categories_controller_spec.rb b/spec/requests/categories_controller_spec.rbindex d1b2b815e52..3ec01bf0381 100644--- a/spec/requests/categories_controller_spec.rb+++ b/spec/requests/categories_controller_spec.rb@@ -1211,7 +1211,7 @@ RSpec.describe CategoriesController doqueries = track_sql_queries { get "/categories/search.json", params: { term: "Notfoo" } }- expect(queries.length).to eq(5)+ expect(queries.length).to eq(8)expect(response.parsed_body["categories"].length).to eq(1)expect(response.parsed_body["categories"][0]["custom_fields"]).to eq("bob" => "marley")@@ -1247,10 +1247,11 @@ RSpec.describe CategoriesController doit "returns categories" doget "/categories/search.json", params: { term: "Foo" }- expect(response.parsed_body["categories"].size).to eq(2)+ expect(response.parsed_body["categories"].size).to eq(3)expect(response.parsed_body["categories"].map { |c| c["name"] }).to contain_exactly("Foo","Foobar",+ "Notfoo",)endend