Commit d1bafaaa9641a476aa708673734c6c8163fd4d5f
1 parent
de10fd0b
Exists in
master
and in
21 other branches
Better or
Showing
3 changed files
with
6 additions
and
5 deletions
Show diff stats
README.md
@@ -50,9 +50,8 @@ where: { | @@ -50,9 +50,8 @@ where: { | ||
50 | store_id: {not: 2}, # not | 50 | store_id: {not: 2}, # not |
51 | aisle_id: {not: [25, 30]}, # not in | 51 | aisle_id: {not: [25, 30]}, # not in |
52 | or: [ | 52 | or: [ |
53 | - {in_stock: true}, | ||
54 | - {backordered: true} | ||
55 | - ] # TODO better or | 53 | + [{in_stock: true}, {backordered: true}] |
54 | + ] | ||
56 | } | 55 | } |
57 | ``` | 56 | ``` |
58 | 57 |
lib/searchkick/search.rb
@@ -55,7 +55,9 @@ module Searchkick | @@ -55,7 +55,9 @@ module Searchkick | ||
55 | # where | 55 | # where |
56 | (options[:where] || {}).each do |k, v| | 56 | (options[:where] || {}).each do |k, v| |
57 | if k == :or | 57 | if k == :or |
58 | - filter :or, v.map{|v2| {term: v2} } | 58 | + v.each do |v2| |
59 | + filter :or, v2.map{|v3| {term: v3} } | ||
60 | + end | ||
59 | else | 61 | else |
60 | if v.is_a?(Range) | 62 | if v.is_a?(Range) |
61 | v = {gte: v.first, (v.exclude_end? ? :lt : :lte) => v.last} | 63 | v = {gte: v.first, (v.exclude_end? ? :lt : :lte) => v.last} |
test/searchkick_test.rb
@@ -238,7 +238,7 @@ class TestSearchkick < Minitest::Unit::TestCase | @@ -238,7 +238,7 @@ class TestSearchkick < Minitest::Unit::TestCase | ||
238 | assert_search "product", ["Product A", "Product B"], where: {store_id: [1, 2]} | 238 | assert_search "product", ["Product A", "Product B"], where: {store_id: [1, 2]} |
239 | assert_search "product", ["Product B", "Product C", "Product D"], where: {store_id: {not: 1}} | 239 | assert_search "product", ["Product B", "Product C", "Product D"], where: {store_id: {not: 1}} |
240 | assert_search "product", ["Product C", "Product D"], where: {store_id: {not: [1, 2]}} | 240 | assert_search "product", ["Product C", "Product D"], where: {store_id: {not: [1, 2]}} |
241 | - assert_search "product", ["Product A", "Product B", "Product C"], where: {or: [{in_stock: true}, {store_id: 3}]} | 241 | + assert_search "product", ["Product A", "Product B", "Product C"], where: {or: [[{in_stock: true}, {store_id: 3}]]} |
242 | end | 242 | end |
243 | 243 | ||
244 | def test_order | 244 | def test_order |