lib/meilisearch-rails.rb in meilisearch-rails-0.10.1 vs lib/meilisearch-rails.rb in meilisearch-rails-0.10.2

- old
+ new

@@ -37,10 +37,14 @@ klass.class_eval do extend ClassMethods include InstanceMethods end end + + def logger + @logger ||= (::Rails.logger || Logger.new($stdout)) + end end class IndexSettings DEFAULT_BATCH_SIZE = 1000 @@ -302,11 +306,11 @@ yield rescue ::MeiliSearch::TimeoutError, ::MeiliSearch::ApiError => e raise e if raise_on_failure # log the error - (::Rails.logger || Logger.new($stdout)).info("[meilisearch-rails] #{e.message}") + MeiliSearch::Rails.logger.info("[meilisearch-rails] #{e.message}") # return something case method.to_s when 'search' # some attributes are required { 'hits' => [], 'hitsPerPage' => 0, 'page' => 0, 'facetDistribution' => {}, 'error' => e } @@ -442,10 +446,12 @@ end elsif respond_to?(:after_destroy) after_destroy { |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 @@ -855,9 +861,22 @@ 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