Commit d2627dd9ec7aef9089c584fae98ee3cf35eaebf3

Authored by Andrew Kane
1 parent 2778f001

Updated async reindex job to call search_import for nested associations [skip ci]

CHANGELOG.md
... ... @@ -7,6 +7,7 @@
7 7 - Changed async reindex to fetch ids instead of using ranges for numeric primary keys with Active Record
8 8 - Changed `searchkick_index_options` to return symbol keys (instead of mix of strings and symbols)
9 9 - Changed non-anchored regular expressions to match expected results (previously warned)
  10 +- Updated async reindex job to call `search_import` for nested associations
10 11 - Fixed removing records when `should_index?` is `false` when `reindex` called on relation
11 12 - Fixed issue with `merge_mappings` for fields that use `searchkick` options
12 13 - Raise error when `search` called on relations
... ...
lib/searchkick/process_batch_job.rb
... ... @@ -13,9 +13,7 @@ module Searchkick
13 13 {id: parts[0], routing: parts[1]}
14 14 end
15 15  
16   - relation = klass
17   - relation = relation.search_import if relation.respond_to?(:search_import)
18   - index.send(:record_indexer).reindex_items(relation, items, method_name: nil)
  16 + index.send(:record_indexer).reindex_items(klass, items, method_name: nil)
19 17 end
20 18 end
21 19 end
... ...
lib/searchkick/record_indexer.rb
... ... @@ -59,7 +59,10 @@ module Searchkick
59 59 routing = items.to_h { |r| [r[:id], r[:routing]] }
60 60 record_ids = routing.keys
61 61  
62   - records = Searchkick.load_records(klass, record_ids).select(&:should_index?)
  62 + relation = Searchkick.load_records(klass, record_ids)
  63 + # call search_import even for single records for nested associations
  64 + relation = relation.search_import if relation.respond_to?(:search_import)
  65 + records = relation.select(&:should_index?)
63 66  
64 67 # determine which records to delete
65 68 delete_ids = record_ids - records.map { |r| r.id.to_s }
... ...