diff --git a/README.md b/README.md index f8dcf8d..953c886 100644 --- a/README.md +++ b/README.md @@ -494,8 +494,9 @@ Dog.reindex # equivalent And to search, use: ```ruby -Animal.search "*" # all animals -Dog.search "*" # just dogs +Animal.search "*" # all animals +Dog.search "*" # just dogs +Animal.search "*", type: [Dog, Cat] # just cats and dogs ``` **Note:** The `suggest` option retrieves suggestions from the parent at the moment. diff --git a/lib/searchkick/search.rb b/lib/searchkick/search.rb index ba6dd02..4c95350 100644 --- a/lib/searchkick/search.rb +++ b/lib/searchkick/search.rb @@ -358,7 +358,9 @@ module Searchkick payload[:fields] = [] if load tire_options = {load: load, payload: payload, size: per_page, from: offset} - tire_options[:type] = handle_types(options[:types]) + if options[:type] or self != searchkick_klass + tire_options[:type] = [options[:type] || self].flatten.map(&:document_type) + end search = Tire::Search::Search.new(index_name, tire_options) begin response = search.json @@ -385,11 +387,5 @@ module Searchkick Searchkick::Results.new(response, search.options.merge(term: term)) end - private - def handle_types(types) - return types.map(&:document_type) if types - document_type if self != searchkick_klass - end - end end diff --git a/test/inheritance_test.rb b/test/inheritance_test.rb index 3706f4f..44e0633 100644 --- a/test/inheritance_test.rb +++ b/test/inheritance_test.rb @@ -28,13 +28,14 @@ class TestInheritance < Minitest::Unit::TestCase def test_force_one_type store_names ["Green Bear"], Dog store_names ["Blue Bear"], Cat - assert_equal ["Blue Bear"], Animal.search("bear", types: [Cat]).map(&:name) + assert_equal ["Blue Bear"], Animal.search("bear", type: [Cat]).map(&:name) end def test_force_multiple_types store_names ["Green Bear"], Dog store_names ["Blue Bear"], Cat - assert_equal ["Green Bear", "Blue Bear"], Animal.search("bear", types: [Dog, Cat]).map(&:name) + store_names ["Red Bear"], Animal + assert_equal ["Green Bear", "Blue Bear"], Animal.search("bear", type: [Dog, Cat]).map(&:name) end def test_child_autocomplete -- libgit2 0.21.0