lib/manage/fields/searcher.rb in manage-1.3.1 vs lib/manage/fields/searcher.rb in manage-1.3.2

- old
+ new

@@ -5,11 +5,11 @@ def generate_search_object(resource_class, search_fields) search_class = Class.new do include SearchObject.module(:model, :sorting) def escape_search_term(term) - "%#{term.gsub(/\s+/, '%')}%" + "%#{term.gsub(/\s+/, '%')}%".downcase end def parse_date(date) Date.strptime(date, '%Y-%m-%d') rescue nil end @@ -21,21 +21,21 @@ search_fields.select {|f| not f.to_s.include?('.')}.each do |field| field_type = resource_class.columns_hash[field.to_s].type if field_type == :text or field_type == :string search_class.option field.to_sym do |scope, value| - scope.where "#{field.to_s} LIKE ?", escape_search_term(value) + scope.where "lower(#{field.to_s}) LIKE lower(?)", escape_search_term(value) end elsif field_type == :datetime search_class.option field.to_sym do |scope, value| date = parse_date value scope.where("DATE(#{field.to_s}) >= ?", date) if date.present? end elsif field_type == :integer search_class.option field.to_sym else search_class.option field.to_sym do |scope, value| - scope.where "#{field.to_s} LIKE ?", escape_search_term(value) + scope.where "lower(#{field.to_s}) LIKE lower(?)", escape_search_term(value) end end end search_class