Method: Searchkick::RecordIndexer#reindex_items

Defined in:
lib/searchkick/record_indexer.rb

#reindex_items(klass, items, method_name:, single: false) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/searchkick/record_indexer.rb', line 63

def reindex_items(klass, items, method_name:, single: false)
  routing = items.to_h { |r| [r[:id], r[:routing]] }
  record_ids = routing.keys

  relation = Searchkick.load_records(klass, record_ids)
  # call search_import even for single records for nested associations
  relation = relation.search_import if relation.respond_to?(:search_import)
  records = relation.select(&:should_index?)

  # determine which records to delete
  delete_ids = record_ids - records.map { |r| r.id.to_s }
  delete_records =
    delete_ids.map do |id|
      construct_record(klass, id, routing[id])
    end

  import_inline(records, delete_records, method_name: method_name, single: single)
end