Sha256: e65e56f2c840127270bcc0b2ccdbd6a661243d65d1f5f2f32521b60169995a79
Contents?: true
Size: 1.02 KB
Versions: 1
Compression:
Stored size: 1.02 KB
Contents
module Searchkick module Reindex # https://gist.github.com/jarosan/3124884 def reindex alias_name = tire.index.name new_index = alias_name + "_" + Time.now.strftime("%Y%m%d%H%M%S") # Rake::Task["tire:import"].invoke index = Tire::Index.new(new_index) Tire::Tasks::Import.create_index(index, self) # TODO remove puts scope = respond_to?(:searchkick_import) ? searchkick_import : self scope.find_in_batches do |batch| index.import batch end if a = Tire::Alias.find(alias_name) old_indices = Tire::Alias.find(alias_name).indices old_indices.each do |index| a.indices.delete index end a.indices.add new_index a.save old_indices.each do |index| i = Tire::Index.new(index) i.delete if i.exists? end else i = Tire::Index.new(alias_name) i.delete if i.exists? Tire::Alias.create(name: alias_name, indices: [new_index]) end true end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
searchkick-0.0.2 | lib/searchkick/reindex.rb |