Created
October 8, 2013 07:25
-
-
Save bbhoss/6880917 to your computer and use it in GitHub Desktop.
Very basic hook into Sunspot::Rails to force it to index it using an alternative method, in this case Sidekiq. I decided to do it this way instead of writing a new session proxy because in this case it's more of an application concern instead of something as low as a session proxy. Will probably cause some weird issues if you don't have your sol…
This file contains 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
module SidekiqIndexing | |
module SearchableOverride | |
extend ActiveSupport::Concern | |
module InstanceOverrides | |
def solr_index | |
SunspotIndexer.perform_async(self.class.to_s, self.id) | |
end | |
end | |
module ClassMethods | |
def searchable(*args, &blk) | |
super | |
include InstanceOverrides | |
end | |
end | |
end | |
class Railtie < ::Rails::Railtie | |
initializer 'sidekiq_indexing.init' do | |
ActiveSupport.on_load(:active_record) do | |
include(SidekiqIndexing::SearchableOverride) | |
end | |
end | |
end | |
end |
This file contains 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
class SunspotIndexer | |
include Sidekiq::Worker | |
def perform(klass_name, id) | |
Sunspot.index(klass_name.constantize.find(id)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment