diff --git a/README.md b/README.md index f6f8fb1..f35c74f 100644 --- a/README.md +++ b/README.md @@ -99,17 +99,18 @@ Where ```ruby where: { - expires_at: {gt: Time.now}, # lt, gte, lte also available - orders_count: 1..10, # equivalent to {gte: 1, lte: 10} - aisle_id: [25, 30], # in - store_id: {not: 2}, # not - aisle_id: {not: [25, 30]}, # not in - user_ids: {all: [1, 3]}, # all elements in array - category: /frozen .+/, # regexp - store_id: {_exists: true}, # exists [master] + expires_at: {gt: Time.now}, # lt, gte, lte also available + orders_count: 1..10, # equivalent to {gte: 1, lte: 10} + aisle_id: [25, 30], # in + store_id: {not: 2}, # not + aisle_id: {not: [25, 30]}, # not in + user_ids: {all: [1, 3]}, # all elements in array + category: /frozen .+/, # regexp + store_id: {exists: true}, # exists [master] + category: {prefix: "Frozen"}, # prefix _or: [{in_stock: true}, {backordered: true}], _and: [{in_stock: true}, {backordered: true}], - _not: {store_id: 1} # negate a condition + _not: {store_id: 1} # negate a condition } ``` diff --git a/lib/searchkick/query.rb b/lib/searchkick/query.rb index 621b038..fe5a965 100644 --- a/lib/searchkick/query.rb +++ b/lib/searchkick/query.rb @@ -945,7 +945,7 @@ module Searchkick end when :in filters << term_filters(field, op_value) - when :_exists + when :exists filters << {exists: {field: field}} else range_query = diff --git a/test/where_test.rb b/test/where_test.rb index b40ff96..b1c590b 100644 --- a/test/where_test.rb +++ b/test/where_test.rb @@ -68,8 +68,8 @@ class WhereTest < Minitest::Test assert_search "product", ["Product B", "Product C"], where: {user_ids: {_not: [2], in: [1, 3]}} # exists - assert_search "product", ["Product A", "Product B", "Product C"], where: {user_ids: {_exists: true}} - assert_search "product", ["Product A", "Product B", "Product C", "Product D"], where: {store_id: {_exists: true}} + assert_search "product", ["Product A", "Product B", "Product C"], where: {user_ids: {exists: true}} + assert_search "product", ["Product A", "Product B", "Product C", "Product D"], where: {store_id: {exists: true}} # not assert_search "product", ["Product D"], where: {user_ids: nil} -- libgit2 0.21.0