Skip to content

Instantly share code, notes, and snippets.

@bbhoss
Created October 8, 2013 07:25
Show Gist options
  • Save bbhoss/6880917 to your computer and use it in GitHub Desktop.
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…
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
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