app/models/concerns/agilibox/search.rb in agilibox-1.0.15 vs app/models/concerns/agilibox/search.rb in agilibox-1.1.0

- old
+ new

@@ -1,13 +1,13 @@ module Agilibox::Search extend ActiveSupport::Concern class_methods do def default_search_fields - columns.map do |column| - "#{table_name}.#{column.name}" - end + columns + .select { |column| column.type.in?([:string, :text]) } + .map { |column| "#{table_name}.#{column.name}" } end # def default_search_fields def search(q, *fields) words = q.to_s.parameterize.split("-") fields = default_search_fields if fields.empty? @@ -16,15 +16,11 @@ fields.map { |field| "(UNACCENT(CAST(#{field} AS TEXT)) ILIKE :w#{index})" }.join(" OR ") }.map { |e| "(#{e})" }.join(" AND ") - sql_params_a = words.map.with_index do |word, index| - ["w#{index}".to_sym, "%#{word}%"] - end + sql_params = words.map.with_index { |word, index| ["w#{index}".to_sym, "%#{word}%"] }.to_h - sql_params_h = Hash[sql_params_a] - - where(sql_query, sql_params_h) + where(sql_query, sql_params) end # def search end # class_methods end # class Agilibox::Search