Commit 7f34e3bc5d0588f587fb8c2ea3b2a07e23988f36

Authored by Andrew
1 parent c5a9e021

Do not force string keys for performance [skip ci]

lib/searchkick/index.rb
... ... @@ -230,7 +230,10 @@ module Searchkick
230 230  
231 231 # should not be public
232 232 def conversions_fields
233   - @conversions_fields ||= Array(options[:conversions]).map(&:to_s)
  233 + @conversions_fields ||= begin
  234 + conversions = Array(options[:conversions])
  235 + conversions.map(&:to_s) + conversions.map(&:to_sym)
  236 + end
234 237 end
235 238  
236 239 def suggest_fields
... ... @@ -238,7 +241,10 @@ module Searchkick
238 241 end
239 242  
240 243 def locations_fields
241   - @locations_fields ||= Array(options[:locations]).map(&:to_s)
  244 + @locations_fields ||= begin
  245 + locations = Array(options[:locations])
  246 + locations.map(&:to_s) + locations.map(&:to_sym)
  247 + end
242 248 end
243 249  
244 250 protected
... ...
lib/searchkick/record_data.rb
1 1 module Searchkick
2 2 class RecordData
3   - EXCLUDED_ATTRIBUTES = ["_id", "_type"]
4   - TYPE_KEY = "type"
  3 + EXCLUDED_ATTRIBUTES = ["id", :id]
  4 + TYPE_KEYS = ["type", :type]
5 5  
6 6 attr_reader :index, :record
7 7  
... ... @@ -52,11 +52,6 @@ module Searchkick
52 52  
53 53 # remove _id since search_id is used instead
54 54 source = record.send(method_name || :search_data)
55   - source.keys.each do |k|
56   - unless k.is_a?(String)
57   - source[k.to_s] = source.delete(k)
58   - end
59   - end
60 55 EXCLUDED_ATTRIBUTES.each do |attr|
61 56 raise Searchkick::Error, "Cannot index a field with name: #{attr}" if source[attr]
62 57 end
... ... @@ -69,8 +64,12 @@ module Searchkick
69 64 end
70 65  
71 66 # hack to prevent generator field doesn't exist error
72   - index.suggest_fields.each do |field|
73   - source[field] = nil if !source[field] && !partial_reindex
  67 + if !partial_reindex
  68 + index.suggest_fields.each do |field|
  69 + if !source[field] && !source[field.to_sym]
  70 + source[field] = nil
  71 + end
  72 + end
74 73 end
75 74  
76 75 # locations
... ... @@ -85,8 +84,10 @@ module Searchkick
85 84 end
86 85 end
87 86  
88   - if !source.key?(TYPE_KEY) && index.options[:inheritance]
89   - source[TYPE_KEY] = document_type(true)
  87 + if index.options[:inheritance]
  88 + if !TYPE_KEYS.any? { |tk| source.key?(tk) }
  89 + source[:type] = document_type(true)
  90 + end
90 91 end
91 92  
92 93 cast_big_decimal(source)
... ...