Commit ffaf8284c1bfa4b3d3d732b7fe71c1ef9d003df0
1 parent
bf82e057
Exists in
master
and in
20 other branches
search_data optimizations
Showing
1 changed file
with
19 additions
and
13 deletions
Show diff stats
lib/searchkick/index.rb
... | ... | @@ -306,32 +306,38 @@ module Searchkick |
306 | 306 | source = source.each_with_object({}) { |(k, v), memo| memo[k.to_s] = v; memo }.except("_id", "_type") |
307 | 307 | |
308 | 308 | # conversions |
309 | - Array(options[:conversions]).map(&:to_s).each do |conversions_field| | |
310 | - if source[conversions_field] | |
311 | - source[conversions_field] = source[conversions_field].map { |k, v| {query: k, count: v} } | |
309 | + if options[:conversions] | |
310 | + Array(options[:conversions]).map(&:to_s).each do |conversions_field| | |
311 | + if source[conversions_field] | |
312 | + source[conversions_field] = source[conversions_field].map { |k, v| {query: k, count: v} } | |
313 | + end | |
312 | 314 | end |
313 | 315 | end |
314 | 316 | |
315 | 317 | # hack to prevent generator field doesn't exist error |
316 | - (options[:suggest] || []).map(&:to_s).each do |field| | |
317 | - source[field] = nil if !source[field] && !partial_reindex | |
318 | + if options[:suggest] | |
319 | + options[:suggest].map(&:to_s).each do |field| | |
320 | + source[field] = nil if !source[field] && !partial_reindex | |
321 | + end | |
318 | 322 | end |
319 | 323 | |
320 | 324 | # locations |
321 | - (options[:locations] || []).map(&:to_s).each do |field| | |
322 | - if source[field] | |
323 | - if !source[field].is_a?(Hash) && (source[field].first.is_a?(Array) || source[field].first.is_a?(Hash)) | |
324 | - # multiple locations | |
325 | - source[field] = source[field].map { |a| location_value(a) } | |
326 | - else | |
327 | - source[field] = location_value(source[field]) | |
325 | + if options[:locations] | |
326 | + options[:locations].map(&:to_s).each do |field| | |
327 | + if source[field] | |
328 | + if !source[field].is_a?(Hash) && (source[field].first.is_a?(Array) || source[field].first.is_a?(Hash)) | |
329 | + # multiple locations | |
330 | + source[field] = source[field].map { |a| location_value(a) } | |
331 | + else | |
332 | + source[field] = location_value(source[field]) | |
333 | + end | |
328 | 334 | end |
329 | 335 | end |
330 | 336 | end |
331 | 337 | |
332 | 338 | cast_big_decimal(source) |
333 | 339 | |
334 | - source.as_json | |
340 | + source | |
335 | 341 | end |
336 | 342 | |
337 | 343 | def location_value(value) | ... | ... |