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,8 +494,9 @@ Dog.reindex # equivalent | ||
494 | And to search, use: | 494 | And to search, use: |
495 | 495 | ||
496 | ```ruby | 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 | **Note:** The `suggest` option retrieves suggestions from the parent at the moment. | 502 | **Note:** The `suggest` option retrieves suggestions from the parent at the moment. |
lib/searchkick/search.rb
@@ -358,7 +358,9 @@ module Searchkick | @@ -358,7 +358,9 @@ module Searchkick | ||
358 | payload[:fields] = [] if load | 358 | payload[:fields] = [] if load |
359 | 359 | ||
360 | tire_options = {load: load, payload: payload, size: per_page, from: offset} | 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 | search = Tire::Search::Search.new(index_name, tire_options) | 364 | search = Tire::Search::Search.new(index_name, tire_options) |
363 | begin | 365 | begin |
364 | response = search.json | 366 | response = search.json |
@@ -385,11 +387,5 @@ module Searchkick | @@ -385,11 +387,5 @@ module Searchkick | ||
385 | Searchkick::Results.new(response, search.options.merge(term: term)) | 387 | Searchkick::Results.new(response, search.options.merge(term: term)) |
386 | end | 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 | end | 390 | end |
395 | end | 391 | end |
test/inheritance_test.rb
@@ -28,13 +28,14 @@ class TestInheritance < Minitest::Unit::TestCase | @@ -28,13 +28,14 @@ class TestInheritance < Minitest::Unit::TestCase | ||
28 | def test_force_one_type | 28 | def test_force_one_type |
29 | store_names ["Green Bear"], Dog | 29 | store_names ["Green Bear"], Dog |
30 | store_names ["Blue Bear"], Cat | 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 | end | 32 | end |
33 | 33 | ||
34 | def test_force_multiple_types | 34 | def test_force_multiple_types |
35 | store_names ["Green Bear"], Dog | 35 | store_names ["Green Bear"], Dog |
36 | store_names ["Blue Bear"], Cat | 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 | end | 39 | end |
39 | 40 | ||
40 | def test_child_autocomplete | 41 | def test_child_autocomplete |