-
-
Save fred/2462595 to your computer and use it in GitHub Desktop.
Sunspot with Resque
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/models/post.rb | |
class Post | |
searchable :auto_index => false, :auto_remove => false do | |
text :title | |
text :body | |
end | |
after_commit :resque_solr_update | |
before_destroy :resque_solr_remove | |
protected | |
def resque_solr_update | |
Resque.enqueue(SolrUpdate, self.class.to_s, id) | |
end | |
def resque_solr_remove | |
Resque.enqueue(SolrRemove, self.class.to_s, id) | |
end | |
end | |
# lib/jobs/solr_update.rb | |
class SolrUpdate | |
@queue = :solr | |
def self.perform(classname, id) | |
classname.constantize.find(id).solr_index | |
end | |
end | |
# lib/jobs/solr_remove.rb | |
class SolrRemove | |
@queue = :solr | |
def self.perform(classname, id) | |
classname.constantize.find(id).solr_remove_from_index | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment