From ba1162c4539e9e18963cca6fc288236def1ce5a4 Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 2 Oct 2024 11:02:18 +0200 Subject: [PATCH] Improve storage locations search [SCI-11129] --- app/models/storage_location.rb | 1 + .../lists/storage_locations_service.rb | 21 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/models/storage_location.rb b/app/models/storage_location.rb index e4c3366ed..03fb0a0b3 100644 --- a/app/models/storage_location.rb +++ b/app/models/storage_location.rb @@ -6,6 +6,7 @@ class StorageLocation < ApplicationRecord ID_PREFIX = 'SL' include PrefixedIdModel include Shareable + include SearchableModel default_scope -> { kept } diff --git a/app/services/lists/storage_locations_service.rb b/app/services/lists/storage_locations_service.rb index ca1c6b77b..fb79c91ef 100644 --- a/app/services/lists/storage_locations_service.rb +++ b/app/services/lists/storage_locations_service.rb @@ -44,8 +44,25 @@ module Lists @records = @records.where(parent_id: @parent_id) end - @records = @records.where('LOWER(storage_locations.name) ILIKE ?', "%#{@filters[:query].downcase}%") if @filters[:query].present? - @records = @records.where('LOWER(storage_locations.name) ILIKE ?', "%#{@params[:search].downcase}%") if @params[:search].present? + if @filters[:query].present? + @records = @records.where_attributes_like( + [ + 'storage_locations.name', + 'storage_locations.description', + StorageLocation::PREFIXED_ID_SQL + ], @filters[:query] + ) + end + + if @params[:search].present? + @records = @records.where_attributes_like( + [ + 'storage_locations.name', + 'storage_locations.description', + StorageLocation::PREFIXED_ID_SQL + ], @params[:search] + ) + end end private