Commit d1bafaaa9641a476aa708673734c6c8163fd4d5f

Authored by Andrew Kane
1 parent de10fd0b

Better or

README.md
... ... @@ -50,9 +50,8 @@ where: {
50 50 store_id: {not: 2}, # not
51 51 aisle_id: {not: [25, 30]}, # not in
52 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 55 # where
56 56 (options[:where] || {}).each do |k, v|
57 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 61 else
60 62 if v.is_a?(Range)
61 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 238 assert_search "product", ["Product A", "Product B"], where: {store_id: [1, 2]}
239 239 assert_search "product", ["Product B", "Product C", "Product D"], where: {store_id: {not: 1}}
240 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 242 end
243 243  
244 244 def test_order
... ...