Class: Searchkick::ProcessBatchJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
lib/searchkick/process_batch_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(class_name:, record_ids:, index_name: nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/searchkick/process_batch_job.rb', line 5

def perform(class_name:, record_ids:, index_name: nil)
  model = Searchkick.load_model(class_name)
  index = model.searchkick_index(name: index_name)

  items =
    record_ids.map do |r|
      parts = r.split(/(?<!\|)\|(?!\|)/, 2)
        .map { |v| v.gsub("||", "|") }
      {id: parts[0], routing: parts[1]}
    end

  relation = Searchkick.scope(model)
  RecordIndexer.new(index).reindex_items(relation, items, method_name: nil)
end