From 01afab1908e969d157db0938830592636e9bdaea Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 9 Aug 2018 02:30:17 -0700 Subject: [PATCH] Added example for conditions for different indices --- README.md | 6 ++++++ test/model_test.rb | 6 ------ test/multi_indices_test.rb | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 test/multi_indices_test.rb diff --git a/README.md b/README.md index e49262e..9118910 100644 --- a/README.md +++ b/README.md @@ -1505,6 +1505,12 @@ Search across multiple models/indices with: Searchkick.search "milk", index_name: [Product, Category] ``` +Specify conditions for different indices + +```ruby +where: {_or: [{_type: "product", in_stock: true}, {_type: "category", active: true}]} +``` + Boost specific indices with: ```ruby diff --git a/test/model_test.rb b/test/model_test.rb index 168011e..b8e0008 100644 --- a/test/model_test.rb +++ b/test/model_test.rb @@ -31,10 +31,4 @@ class ModelTest < Minitest::Test assert_search "product", ["product a", "product b"] end - - def test_multiple_models - store_names ["Product A"] - store_names ["Product B"], Speaker - assert_equal Product.all.to_a + Speaker.all.to_a, Searchkick.search("product", index_name: [Product, Speaker], fields: [:name], order: "name").to_a - end end diff --git a/test/multi_indices_test.rb b/test/multi_indices_test.rb new file mode 100644 index 0000000..61bf51b --- /dev/null +++ b/test/multi_indices_test.rb @@ -0,0 +1,23 @@ +require_relative "test_helper" + +class MultiIndicesTest < Minitest::Test + def test_basic + store_names ["Product A"] + store_names ["Product B"], Speaker + assert_search_multi "product", ["Product A", "Product B"] + end + + def test_where + store [{name: "Product A", color: "red"}, {name: "Product B", color: "blue"}] + store_names ["Product C"], Speaker + assert_search_multi "product", ["Product A", "Product C"], where: {_or: [{_type: "product", color: "red"}, {_type: "speaker"}]} + end + + private + + def assert_search_multi(term, expected, options = {}) + options[:index_name] = [Product, Speaker] + options[:fields] = [:name] + assert_search(term, expected, options, Searchkick) + end +end -- libgit2 0.21.0