Commit 01afab1908e969d157db0938830592636e9bdaea
1 parent
e40108da
Exists in
master
and in
18 other branches
Added example for conditions for different indices
Showing
3 changed files
with
29 additions
and
6 deletions
Show diff stats
README.md
@@ -1505,6 +1505,12 @@ Search across multiple models/indices with: | @@ -1505,6 +1505,12 @@ Search across multiple models/indices with: | ||
1505 | Searchkick.search "milk", index_name: [Product, Category] | 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 | Boost specific indices with: | 1514 | Boost specific indices with: |
1509 | 1515 | ||
1510 | ```ruby | 1516 | ```ruby |
test/model_test.rb
@@ -31,10 +31,4 @@ class ModelTest < Minitest::Test | @@ -31,10 +31,4 @@ class ModelTest < Minitest::Test | ||
31 | 31 | ||
32 | assert_search "product", ["product a", "product b"] | 32 | assert_search "product", ["product a", "product b"] |
33 | end | 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 | end | 34 | end |
@@ -0,0 +1,23 @@ | @@ -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 |