Commit 33bc3ee662be14d4cc04278613fe4d1d011dcad7
1 parent
bbc2217f
Exists in
master
and in
17 other branches
Added exists
Showing
3 changed files
with
8 additions
and
1 deletions
Show diff stats
README.md
@@ -106,6 +106,7 @@ where: { | @@ -106,6 +106,7 @@ where: { | ||
106 | aisle_id: {not: [25, 30]}, # not in | 106 | aisle_id: {not: [25, 30]}, # not in |
107 | user_ids: {all: [1, 3]}, # all elements in array | 107 | user_ids: {all: [1, 3]}, # all elements in array |
108 | category: /frozen .+/, # regexp | 108 | category: /frozen .+/, # regexp |
109 | + store_id: {_exists: true}, # exists [master] | ||
109 | _or: [{in_stock: true}, {backordered: true}], | 110 | _or: [{in_stock: true}, {backordered: true}], |
110 | _and: [{in_stock: true}, {backordered: true}], | 111 | _and: [{in_stock: true}, {backordered: true}], |
111 | _not: {store_id: 1} # negate a condition | 112 | _not: {store_id: 1} # negate a condition |
lib/searchkick/query.rb
@@ -945,6 +945,8 @@ module Searchkick | @@ -945,6 +945,8 @@ module Searchkick | ||
945 | end | 945 | end |
946 | when :in | 946 | when :in |
947 | filters << term_filters(field, op_value) | 947 | filters << term_filters(field, op_value) |
948 | + when :_exists | ||
949 | + filters << {exists: {field: field}} | ||
948 | else | 950 | else |
949 | range_query = | 951 | range_query = |
950 | case op | 952 | case op |
test/where_test.rb
@@ -67,7 +67,11 @@ class WhereTest < Minitest::Test | @@ -67,7 +67,11 @@ class WhereTest < Minitest::Test | ||
67 | assert_search "product", ["Product B", "Product C"], where: {user_ids: {not: [2], in: [1, 3]}} | 67 | assert_search "product", ["Product B", "Product C"], where: {user_ids: {not: [2], in: [1, 3]}} |
68 | assert_search "product", ["Product B", "Product C"], where: {user_ids: {_not: [2], in: [1, 3]}} | 68 | assert_search "product", ["Product B", "Product C"], where: {user_ids: {_not: [2], in: [1, 3]}} |
69 | 69 | ||
70 | - # not / exists | 70 | + # exists |
71 | + assert_search "product", ["Product A", "Product B", "Product C"], where: {user_ids: {_exists: true}} | ||
72 | + assert_search "product", ["Product A", "Product B", "Product C", "Product D"], where: {store_id: {_exists: true}} | ||
73 | + | ||
74 | + # not | ||
71 | assert_search "product", ["Product D"], where: {user_ids: nil} | 75 | assert_search "product", ["Product D"], where: {user_ids: nil} |
72 | assert_search "product", ["Product A", "Product B", "Product C"], where: {user_ids: {not: nil}} | 76 | assert_search "product", ["Product A", "Product B", "Product C"], where: {user_ids: {not: nil}} |
73 | assert_search "product", ["Product A", "Product B", "Product C"], where: {user_ids: {_not: nil}} | 77 | assert_search "product", ["Product A", "Product B", "Product C"], where: {user_ids: {_not: nil}} |