From a54b2586ec48e31e616e401b69ac6d513478f42e Mon Sep 17 00:00:00 2001 From: Bilal Date: Thu, 16 Apr 2020 15:30:01 +0200 Subject: [PATCH] update PgSearchable to accept array of default columns --- lib/pg_searchable_regex.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/pg_searchable_regex.rb b/lib/pg_searchable_regex.rb index 8c7374b..f14e120 100644 --- a/lib/pg_searchable_regex.rb +++ b/lib/pg_searchable_regex.rb @@ -26,7 +26,7 @@ module PgSearchable wildcard: true, external_cache_data: nil, joins: [], - default_field: "" + default_fields: [] ) @ts_search_fields = fields @ts_search_fields_mappings = fields_mappings @@ -36,7 +36,11 @@ module PgSearchable @ts_skip_cache_update = skip_callback @ts_wildcard = wildcard @ts_joins = joins - @default_field = default_field.to_s.empty? ? fields.first : default_field.to_sym + @default_fields = if default_fields.is_a? Array + default_fields.empty? ? [fields.first] : default_fields + else + default_fields.to_s.empty? ? [fields.first] : [default_fields.to_sym] + end ts_add_scope end @@ -52,7 +56,7 @@ module PgSearchable def ts_search(value) return if @ts_search_fields.blank? || value.blank? includes(@ts_joins).references(:all).where( - TextToSqlQuery.new(value, @ts_search_fields, @default_field, @ts_search_fields_mappings).where_clause).distinct + TextToSqlQuery.new(value, @ts_search_fields, @default_fields, @ts_search_fields_mappings).where_clause).distinct end def should_update_cache_field?