9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/searchkick/relation_indexer.rb', line 9
def reindex(relation, mode:, method_name: nil, full: false, resume: false, scope: nil)
if scope
relation = relation.send(scope)
elsif relation.respond_to?(:search_import)
relation = relation.search_import
end
if mode == :async || mode == :queue
if relation.respond_to?(:primary_key)
relation = relation.except(:includes, :preload)
unless mode == :queue && relation.klass.method_defined?(:search_routing)
relation = relation.except(:select).select(relation.primary_key)
end
elsif relation.respond_to?(:only)
unless mode == :queue && relation.klass.method_defined?(:search_routing)
relation = relation.only(:_id)
end
end
end
if mode == :async && full
return full_reindex_async(relation)
end
relation = resume_relation(relation) if resume
reindex_options = {
mode: mode,
method_name: method_name,
full: full
}
record_indexer = RecordIndexer.new(index)
in_batches(relation) do |items|
record_indexer.reindex(items, **reindex_options)
end
end
|