Commit ca8b021fe93c44a9d92f492001a4500947a0ba1e
Exists in
master
and in
21 other branches
Renamed to in
Showing
2 changed files
with
12 additions
and
4 deletions
Show diff stats
lib/searchkick/query.rb
... | ... | @@ -352,6 +352,10 @@ module Searchkick |
352 | 352 | value = {gte: value.first, (value.exclude_end? ? :lt : :lte) => value.last} |
353 | 353 | end |
354 | 354 | |
355 | + if value.is_a?(Array) | |
356 | + value = {in: value} | |
357 | + end | |
358 | + | |
355 | 359 | if value.is_a?(Hash) |
356 | 360 | value.each do |op, op_value| |
357 | 361 | case op |
... | ... | @@ -377,6 +381,8 @@ module Searchkick |
377 | 381 | filters << {not: term_filters(field, op_value)} |
378 | 382 | when :all |
379 | 383 | filters << {terms: {field => op_value, execution: "and"}} |
384 | + when :in | |
385 | + filters << term_filters(field, op_value) | |
380 | 386 | else |
381 | 387 | range_query = |
382 | 388 | case op | ... | ... |
test/sql_test.rb
... | ... | @@ -40,7 +40,7 @@ class TestSql < Minitest::Unit::TestCase |
40 | 40 | store [ |
41 | 41 | {name: "Product A", store_id: 1, in_stock: true, backordered: true, created_at: now, orders_count: 4, user_ids: [1, 2, 3]}, |
42 | 42 | {name: "Product B", store_id: 2, in_stock: true, backordered: false, created_at: now - 1, orders_count: 3, user_ids: [1]}, |
43 | - {name: "Product C", store_id: 3, in_stock: false, backordered: true, created_at: now - 2, orders_count: 2}, | |
43 | + {name: "Product C", store_id: 3, in_stock: false, backordered: true, created_at: now - 2, orders_count: 2, user_ids: [1, 3]}, | |
44 | 44 | {name: "Product D", store_id: 4, in_stock: false, backordered: false, created_at: now - 3, orders_count: 1}, |
45 | 45 | ] |
46 | 46 | assert_search "product", ["Product A", "Product B"], where: {in_stock: true} |
... | ... | @@ -66,11 +66,13 @@ class TestSql < Minitest::Unit::TestCase |
66 | 66 | assert_search "product", ["Product A", "Product B", "Product C"], where: {or: [[{orders_count: [2, 4]}, {store_id: [1, 2]}]]} |
67 | 67 | assert_search "product", ["Product A", "Product D"], where: {or: [[{orders_count: 1}, {created_at: {gte: now - 1}, backordered: true}]]} |
68 | 68 | # all |
69 | - assert_search "product", ["Product A"], where: {user_ids: {all: [1, 3]}} | |
69 | + assert_search "product", ["Product A", "Product C"], where: {user_ids: {all: [1, 3]}} | |
70 | 70 | assert_search "product", [], where: {user_ids: {all: [1, 2, 3, 4]}} |
71 | + # any / nested terms | |
72 | + assert_search "product", ["Product B", "Product C"], where: {user_ids: {not: [2], in: [1,3]}} | |
71 | 73 | # not / exists |
72 | - assert_search "product", ["Product C", "Product D"], where: {user_ids: nil} | |
73 | - assert_search "product", ["Product A", "Product B"], where: {user_ids: {not: nil}} | |
74 | + assert_search "product", ["Product D"], where: {user_ids: nil} | |
75 | + assert_search "product", ["Product A", "Product B", "Product C"], where: {user_ids: {not: nil}} | |
74 | 76 | assert_search "product", ["Product A", "Product C", "Product D"], where: {user_ids: [3, nil]} |
75 | 77 | assert_search "product", ["Product B"], where: {user_ids: {not: [3, nil]}} |
76 | 78 | end | ... | ... |