Commit 15bbb837d57ab26be587cd48500bc5f7441d5c45
1 parent
717ed55c
Exists in
master
and in
19 other branches
Performance updates [skip ci]
Showing
3 changed files
with
29 additions
and
22 deletions
Show diff stats
lib/searchkick/bulk_reindex_job.rb
... | ... | @@ -4,7 +4,7 @@ module Searchkick |
4 | 4 | |
5 | 5 | def perform(class_name:, record_ids: nil, index_name: nil, method_name: nil, batch_id: nil, min_id: nil, max_id: nil) |
6 | 6 | klass = class_name.constantize |
7 | - index = index_name ? Searchkick::Index.new(index_name) : klass.searchkick_index | |
7 | + index = index_name ? Searchkick::Index.new(index_name, **klass.searchkick_options) : klass.searchkick_index | |
8 | 8 | record_ids ||= min_id..max_id |
9 | 9 | index.import_scope( |
10 | 10 | Searchkick.load_records(klass, record_ids), | ... | ... |
lib/searchkick/index.rb
... | ... | @@ -228,6 +228,19 @@ module Searchkick |
228 | 228 | end |
229 | 229 | end |
230 | 230 | |
231 | + # should not be public | |
232 | + def conversions_fields | |
233 | + @conversions_fields ||= Array(options[:conversions]).map(&:to_s) | |
234 | + end | |
235 | + | |
236 | + def suggest_fields | |
237 | + @suggest_fields ||= Array(options[:suggest]).map(&:to_s) | |
238 | + end | |
239 | + | |
240 | + def locations_fields | |
241 | + @locations_fields ||= Array(options[:locations]).map(&:to_s) | |
242 | + end | |
243 | + | |
231 | 244 | protected |
232 | 245 | |
233 | 246 | def client | ... | ... |
lib/searchkick/record_data.rb
1 | 1 | module Searchkick |
2 | 2 | class RecordData |
3 | 3 | EXCLUDED_ATTRIBUTES = ["_id", "_type"] |
4 | + TYPE_KEY = "type" | |
4 | 5 | |
5 | 6 | attr_reader :index, :record |
6 | 7 | |
... | ... | @@ -48,7 +49,6 @@ module Searchkick |
48 | 49 | |
49 | 50 | def search_data(method_name = nil) |
50 | 51 | partial_reindex = !method_name.nil? |
51 | - options = record.class.searchkick_options | |
52 | 52 | |
53 | 53 | # remove _id since search_id is used instead |
54 | 54 | source = record.send(method_name || :search_data) |
... | ... | @@ -62,37 +62,31 @@ module Searchkick |
62 | 62 | end |
63 | 63 | |
64 | 64 | # conversions |
65 | - if options[:conversions] | |
66 | - Array(options[:conversions]).map(&:to_s).each do |conversions_field| | |
67 | - if source[conversions_field] | |
68 | - source[conversions_field] = source[conversions_field].map { |k, v| {query: k, count: v} } | |
69 | - end | |
65 | + index.conversions_fields.each do |conversions_field| | |
66 | + if source[conversions_field] | |
67 | + source[conversions_field] = source[conversions_field].map { |k, v| {query: k, count: v} } | |
70 | 68 | end |
71 | 69 | end |
72 | 70 | |
73 | 71 | # hack to prevent generator field doesn't exist error |
74 | - if options[:suggest] | |
75 | - options[:suggest].map(&:to_s).each do |field| | |
76 | - source[field] = nil if !source[field] && !partial_reindex | |
77 | - end | |
72 | + index.suggest_fields.each do |field| | |
73 | + source[field] = nil if !source[field] && !partial_reindex | |
78 | 74 | end |
79 | 75 | |
80 | 76 | # locations |
81 | - if options[:locations] | |
82 | - options[:locations].map(&:to_s).each do |field| | |
83 | - if source[field] | |
84 | - if !source[field].is_a?(Hash) && (source[field].first.is_a?(Array) || source[field].first.is_a?(Hash)) | |
85 | - # multiple locations | |
86 | - source[field] = source[field].map { |a| location_value(a) } | |
87 | - else | |
88 | - source[field] = location_value(source[field]) | |
89 | - end | |
77 | + index.locations_fields.each do |field| | |
78 | + if source[field] | |
79 | + if !source[field].is_a?(Hash) && (source[field].first.is_a?(Array) || source[field].first.is_a?(Hash)) | |
80 | + # multiple locations | |
81 | + source[field] = source[field].map { |a| location_value(a) } | |
82 | + else | |
83 | + source[field] = location_value(source[field]) | |
90 | 84 | end |
91 | 85 | end |
92 | 86 | end |
93 | 87 | |
94 | - if !source.key?("type") && record.class.searchkick_klass.searchkick_options[:inheritance] | |
95 | - source["type"] = document_type(true) | |
88 | + if !source.key?(TYPE_KEY) && index.options[:inheritance] | |
89 | + source[TYPE_KEY] = document_type(true) | |
96 | 90 | end |
97 | 91 | |
98 | 92 | cast_big_decimal(source) | ... | ... |