module Elasticfusion::Model::Indexing

Public Class Methods

included(model) click to toggle source
# File lib/elasticfusion/model/indexing.rb, line 7
def self.included(model)
  model.class_eval do
    after_commit(on: :create) do
      __elasticsearch__.index_document
    end

    after_commit(on: :destroy) do
      __elasticsearch__.delete_document
    end

    if elasticfusion[:reindex_when_updated]
      after_commit(on: :update) do |record|
        if (record.previous_changes.keys.map(&:to_sym) &
            record.class.elasticfusion[:reindex_when_updated]).any?
          record.reindex_later
        end
      end
    end
  end
end

Public Instance Methods

reindex_later() click to toggle source
# File lib/elasticfusion/model/indexing.rb, line 28
def reindex_later
  Elasticfusion::Jobs::ReindexJob.perform_later(self.class.to_s, self.id)
end
reindex_now() click to toggle source
# File lib/elasticfusion/model/indexing.rb, line 32
def reindex_now
  __elasticsearch__.index_document
end