From 22ce8d5f1ab565100a85ad8e4dc250cd11d79e4a Mon Sep 17 00:00:00 2001 From: Bohung Date: Sun, 19 Dec 2021 18:01:23 +0800 Subject: [PATCH] Fix search bug. --- app/controllers/universal_tables_controller.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controllers/universal_tables_controller.rb b/app/controllers/universal_tables_controller.rb index 9af6641..292d332 100644 --- a/app/controllers/universal_tables_controller.rb +++ b/app/controllers/universal_tables_controller.rb @@ -181,10 +181,13 @@ class UniversalTablesController < ApplicationController if params["column"].present? keywords = params["q"] keywords = keywords.strip.nil? ? keywords : keywords.strip - regexes = keywords.split(/\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/) - regex = Regexp.union(regexes.map{|word| Regexp.new(".*"+word+".*", "i")}) - column = table.table_columns.where(:key => params["column"]).first + if column.make_categorizable + regex = Regexp.new(".*"+keywords+".*", "i") + else + regexes = keywords.split(/\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/) + regex = Regexp.union(regexes.map{|word| Regexp.new(".*"+word+".*", "i")}) + end if params["sort"].present? column_to_sort = table.table_columns.where(:key => params["sortcolumn"]).first case column_to_sort.type