public
Created

  • Download Gist
deindex.rb
Ruby
1 2 3 4 5 6 7
class RemoveRecordFromSolr
@queue = :high
 
def self.perform(klass, id)
klass.constantize.find(id).remove_from_index!
end
end
index.rb
Ruby
1 2 3 4 5 6 7
class IndexRecordInSolr
@queue = :high
 
def self.perform(klass, id)
klass.constantize.find(id).index!
end
end
observer.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
class SolrObserver < ActiveRecord::Observer
observe Company, Customer, Todo, Deal, Message, PhoneCall
 
def after_save(record)
return if ENV['POPULATING']
 
Resque.enqueue IndexRecordInSolr, record.class.to_s, record.id
end
 
def before_destroy(record)
return if ENV['POPULATING']
 
Resque.enqueue RemoveRecordFromSolr, record.class.to_s, record.id
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.