From 5fbc169ade4a553d5ab00a5bf52319caff635a72 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Wed, 25 Feb 2026 08:08:02 -0500 Subject: [PATCH] Restored old search --- app/models/customer.rb | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/app/models/customer.rb b/app/models/customer.rb index 60e2bc1..8627dfe 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -182,23 +182,9 @@ class Customer < ActiveRecord::Base end def self.search(search) - return all if search.blank? - - # 1. Clean the input: Remove existing stars and special Boolean operators - # to prevent "red**" or syntax errors from hyphens/plus signs. - clean_search = search.gsub(/[*+\-><()~]/, '') - - # 2. Add a single trailing wildcard for partial matching - ft_query = "#{clean_search}*" - - # 3. Use the exact column list from your migration - # Using a hybrid approach to ensure "Jonh" still finds "John" - where( - "MATCH(name, phone_number, mobile_phone_number) AGAINST(? IN BOOLEAN MODE) OR - SOUNDEX(SUBSTRING_INDEX(name, ' ', 1)) = SOUNDEX(?) OR - name LIKE ?", - ft_query, clean_search, "%#{sanitize_sql_like(clean_search)}%" - ).order(Arel.sql("MATCH(name, phone_number, mobile_phone_number) AGAINST(#{connection.quote(clean_search)}) DESC")) + search = sanitize_sql_like(search) + customers = where("name LIKE ? OR phone_number LIKE ? OR mobile_phone_number LIKE ?", "%#{search}%", "%#{search}%", "%#{search}%") + return customers.order(:name) end # Override the defult redmine seach method to rank results by id