Commit 28322ca1716dcea0da5d6370ab5c50a1253990bc
1 parent
53382b7c
Exists in
master
and in
21 other branches
Renamed option to type
Showing
3 changed files
with
9 additions
and
11 deletions
Show diff stats
README.md
... | ... | @@ -494,8 +494,9 @@ Dog.reindex # equivalent |
494 | 494 | And to search, use: |
495 | 495 | |
496 | 496 | ```ruby |
497 | -Animal.search "*" # all animals | |
498 | -Dog.search "*" # just dogs | |
497 | +Animal.search "*" # all animals | |
498 | +Dog.search "*" # just dogs | |
499 | +Animal.search "*", type: [Dog, Cat] # just cats and dogs | |
499 | 500 | ``` |
500 | 501 | |
501 | 502 | **Note:** The `suggest` option retrieves suggestions from the parent at the moment. | ... | ... |
lib/searchkick/search.rb
... | ... | @@ -358,7 +358,9 @@ module Searchkick |
358 | 358 | payload[:fields] = [] if load |
359 | 359 | |
360 | 360 | tire_options = {load: load, payload: payload, size: per_page, from: offset} |
361 | - tire_options[:type] = handle_types(options[:types]) | |
361 | + if options[:type] or self != searchkick_klass | |
362 | + tire_options[:type] = [options[:type] || self].flatten.map(&:document_type) | |
363 | + end | |
362 | 364 | search = Tire::Search::Search.new(index_name, tire_options) |
363 | 365 | begin |
364 | 366 | response = search.json |
... | ... | @@ -385,11 +387,5 @@ module Searchkick |
385 | 387 | Searchkick::Results.new(response, search.options.merge(term: term)) |
386 | 388 | end |
387 | 389 | |
388 | - private | |
389 | - def handle_types(types) | |
390 | - return types.map(&:document_type) if types | |
391 | - document_type if self != searchkick_klass | |
392 | - end | |
393 | - | |
394 | 390 | end |
395 | 391 | end | ... | ... |
test/inheritance_test.rb
... | ... | @@ -28,13 +28,14 @@ class TestInheritance < Minitest::Unit::TestCase |
28 | 28 | def test_force_one_type |
29 | 29 | store_names ["Green Bear"], Dog |
30 | 30 | store_names ["Blue Bear"], Cat |
31 | - assert_equal ["Blue Bear"], Animal.search("bear", types: [Cat]).map(&:name) | |
31 | + assert_equal ["Blue Bear"], Animal.search("bear", type: [Cat]).map(&:name) | |
32 | 32 | end |
33 | 33 | |
34 | 34 | def test_force_multiple_types |
35 | 35 | store_names ["Green Bear"], Dog |
36 | 36 | store_names ["Blue Bear"], Cat |
37 | - assert_equal ["Green Bear", "Blue Bear"], Animal.search("bear", types: [Dog, Cat]).map(&:name) | |
37 | + store_names ["Red Bear"], Animal | |
38 | + assert_equal ["Green Bear", "Blue Bear"], Animal.search("bear", type: [Dog, Cat]).map(&:name) | |
38 | 39 | end |
39 | 40 | |
40 | 41 | def test_child_autocomplete | ... | ... |