Commit a423f8ff08cf3d2715f0025b415988628fe68fa0
1 parent
61ede188
Exists in
master
and in
19 other branches
Slightly better logic
Showing
3 changed files
with
7 additions
and
7 deletions
Show diff stats
lib/searchkick/index.rb
... | ... | @@ -318,11 +318,11 @@ module Searchkick |
318 | 318 | client.indices.analyze(body: {text: text}.merge(options), index: name)["tokens"].map { |t| t["token"] } |
319 | 319 | end |
320 | 320 | |
321 | - def klass_document_type(klass, inheritance = true) | |
322 | - @klass_document_type[[klass, inheritance]] ||= begin | |
321 | + def klass_document_type(klass, ignore_type = false) | |
322 | + @klass_document_type[[klass, ignore_type]] ||= begin | |
323 | 323 | if klass.respond_to?(:document_type) |
324 | 324 | klass.document_type |
325 | - elsif !inheritance && klass.searchkick_klass.searchkick_options[:_type] | |
325 | + elsif !ignore_type && klass.searchkick_klass.searchkick_options[:_type] | |
326 | 326 | type = klass.searchkick_klass.searchkick_options[:_type] |
327 | 327 | type = type.call if type.respond_to?(:call) |
328 | 328 | type |
... | ... | @@ -338,11 +338,11 @@ module Searchkick |
338 | 338 | Searchkick.client |
339 | 339 | end |
340 | 340 | |
341 | - def document_type(record, inheritance = false) | |
341 | + def document_type(record, ignore_type = false) | |
342 | 342 | if record.respond_to?(:search_document_type) |
343 | 343 | record.search_document_type |
344 | 344 | else |
345 | - klass_document_type(record.class, inheritance) | |
345 | + klass_document_type(record.class, ignore_type) | |
346 | 346 | end |
347 | 347 | end |
348 | 348 | ... | ... |
lib/searchkick/model.rb
... | ... | @@ -12,7 +12,7 @@ module Searchkick |
12 | 12 | |
13 | 13 | Searchkick.models << self |
14 | 14 | |
15 | - options[:_type] ||= -> { searchkick_index.klass_document_type(self) } if options[:inheritance] | |
15 | + options[:_type] ||= -> { searchkick_index.klass_document_type(self, true) } if options[:inheritance] | |
16 | 16 | |
17 | 17 | class_eval do |
18 | 18 | cattr_reader :searchkick_options, :searchkick_klass | ... | ... |
lib/searchkick/query.rb
... | ... | @@ -452,7 +452,7 @@ module Searchkick |
452 | 452 | # type when inheritance |
453 | 453 | where = (options[:where] || {}).dup |
454 | 454 | if searchkick_options[:inheritance] && (options[:type] || (klass != searchkick_klass && searchkick_index)) |
455 | - where[:type] = [options[:type] || klass].flatten.map { |v| searchkick_index.klass_document_type(v) } | |
455 | + where[:type] = [options[:type] || klass].flatten.map { |v| searchkick_index.klass_document_type(v, true) } | |
456 | 456 | end |
457 | 457 | |
458 | 458 | # filters | ... | ... |