Module: Elasticfusion::Model::Indexing
- Defined in:
- lib/elasticfusion/model/indexing.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(model) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# 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 |
Instance Method Details
#reindex_later ⇒ Object
28 29 30 |
# 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 ⇒ Object
32 33 34 |
# File 'lib/elasticfusion/model/indexing.rb', line 32 def reindex_now __elasticsearch__.index_document end |