lib/meilisearch-rails.rb in meilisearch-rails-0.14.0 vs lib/meilisearch-rails.rb in meilisearch-rails-0.14.1

- old
+ new

@@ -82,12 +82,28 @@ end def initialize(options, &block) @options = options instance_exec(&block) if block_given? + warn_searchable_missing_attributes end + def warn_searchable_missing_attributes + searchables = get_setting(:searchable_attributes)&.map { |searchable| searchable.to_s.split('.').first } + attrs = get_setting(:attributes)&.map { |k, _| k.to_s } + + if searchables.present? && attrs.present? + (searchables - attrs).each do |missing_searchable| + warning = <<~WARNING + [meilisearch-rails] #{missing_searchable} declared in searchable_attributes but not in attributes. \ + Please add it to attributes if it should be searchable. + WARNING + MeiliSearch::Rails.logger.warn(warning) + end + end + end + def use_serializer(serializer) @serializer = serializer # instance_variable_set("@serializer", serializer) end @@ -462,12 +478,10 @@ end elsif respond_to?(:after_destroy) after_destroy_commit { |searchable| searchable.ms_enqueue_remove_from_index!(ms_synchronous?) } end end - - warn_searchable_missing_attributes end def ms_without_auto_index(&block) self.ms_without_auto_index_scope = true begin @@ -553,18 +567,18 @@ doc = settings.get_attributes(document) doc = doc.merge ms_pk(options) => primary_key if synchronous || options[:synchronous] - index.add_documents!(doc) + index.add_documents(doc).await else index.add_documents(doc) end elsif ms_conditional_index?(options) && primary_key.present? # remove non-indexable documents if synchronous || options[:synchronous] - index.delete_document!(primary_key) + index.delete_document(primary_key).await else index.delete_document(primary_key) end end end.compact @@ -592,11 +606,11 @@ ms_configurations.each do |options, settings| next if ms_indexing_disabled?(options) index = ms_ensure_init(options, settings) if synchronous || options[:synchronous] - index.delete_document!(primary_key) + index.delete_document(primary_key).await else index.delete_document(primary_key) end end nil @@ -605,11 +619,11 @@ def ms_clear_index!(synchronous = false) ms_configurations.each do |options, settings| next if ms_indexing_disabled?(options) index = ms_ensure_init(options, settings) - synchronous || options[:synchronous] ? index.delete_all_documents! : index.delete_all_documents + synchronous || options[:synchronous] ? index.delete_all_documents.await : index.delete_all_documents @ms_indexes[MeiliSearch::Rails.active?][settings] = nil end nil end @@ -898,22 +912,9 @@ return document.send("will_save_change_to_#{attr_name}?") end # We don't know if the attribute has changed, so conservatively assume it has true - end - - def warn_searchable_missing_attributes - searchables = meilisearch_settings.get_setting(:searchable_attributes) - attrs = meilisearch_settings.get_setting(:attributes)&.keys - - if searchables.present? && attrs.present? - (searchables.map(&:to_s) - attrs.map(&:to_s)).each do |missing_searchable| - MeiliSearch::Rails.logger.warn( - "[meilisearch-rails] #{name}##{missing_searchable} declared in searchable_attributes but not in attributes. Please add it to attributes if it should be searchable." - ) - end - end end end # these are the instance methods included module InstanceMethods