Commit 33bc3ee662be14d4cc04278613fe4d1d011dcad7

Authored by Andrew Kane
1 parent bbc2217f

Added exists

README.md
... ... @@ -106,6 +106,7 @@ where: {
106 106 aisle_id: {not: [25, 30]}, # not in
107 107 user_ids: {all: [1, 3]}, # all elements in array
108 108 category: /frozen .+/, # regexp
  109 + store_id: {_exists: true}, # exists [master]
109 110 _or: [{in_stock: true}, {backordered: true}],
110 111 _and: [{in_stock: true}, {backordered: true}],
111 112 _not: {store_id: 1} # negate a condition
... ...
lib/searchkick/query.rb
... ... @@ -945,6 +945,8 @@ module Searchkick
945 945 end
946 946 when :in
947 947 filters << term_filters(field, op_value)
  948 + when :_exists
  949 + filters << {exists: {field: field}}
948 950 else
949 951 range_query =
950 952 case op
... ...
test/where_test.rb
... ... @@ -67,7 +67,11 @@ class WhereTest &lt; Minitest::Test
67 67 assert_search "product", ["Product B", "Product C"], where: {user_ids: {not: [2], in: [1, 3]}}
68 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 75 assert_search "product", ["Product D"], where: {user_ids: nil}
72 76 assert_search "product", ["Product A", "Product B", "Product C"], where: {user_ids: {not: nil}}
73 77 assert_search "product", ["Product A", "Product B", "Product C"], where: {user_ids: {_not: nil}}
... ...