Commit 01afab1908e969d157db0938830592636e9bdaea

Authored by Andrew
1 parent e40108da

Added example for conditions for different indices

README.md
... ... @@ -1505,6 +1505,12 @@ Search across multiple models/indices with:
1505 1505 Searchkick.search "milk", index_name: [Product, Category]
1506 1506 ```
1507 1507  
  1508 +Specify conditions for different indices
  1509 +
  1510 +```ruby
  1511 +where: {_or: [{_type: "product", in_stock: true}, {_type: "category", active: true}]}
  1512 +```
  1513 +
1508 1514 Boost specific indices with:
1509 1515  
1510 1516 ```ruby
... ...
test/model_test.rb
... ... @@ -31,10 +31,4 @@ class ModelTest < Minitest::Test
31 31  
32 32 assert_search "product", ["product a", "product b"]
33 33 end
34   -
35   - def test_multiple_models
36   - store_names ["Product A"]
37   - store_names ["Product B"], Speaker
38   - assert_equal Product.all.to_a + Speaker.all.to_a, Searchkick.search("product", index_name: [Product, Speaker], fields: [:name], order: "name").to_a
39   - end
40 34 end
... ...
test/multi_indices_test.rb 0 → 100644
... ... @@ -0,0 +1,23 @@
  1 +require_relative "test_helper"
  2 +
  3 +class MultiIndicesTest < Minitest::Test
  4 + def test_basic
  5 + store_names ["Product A"]
  6 + store_names ["Product B"], Speaker
  7 + assert_search_multi "product", ["Product A", "Product B"]
  8 + end
  9 +
  10 + def test_where
  11 + store [{name: "Product A", color: "red"}, {name: "Product B", color: "blue"}]
  12 + store_names ["Product C"], Speaker
  13 + assert_search_multi "product", ["Product A", "Product C"], where: {_or: [{_type: "product", color: "red"}, {_type: "speaker"}]}
  14 + end
  15 +
  16 + private
  17 +
  18 + def assert_search_multi(term, expected, options = {})
  19 + options[:index_name] = [Product, Speaker]
  20 + options[:fields] = [:name]
  21 + assert_search(term, expected, options, Searchkick)
  22 + end
  23 +end
... ...