Commit 3bb0f7b31f60398123a79da40285b3668af651ee

Authored by Andrew Kane
1 parent 33bc3ee6

Added docs for prefix and remove _ with exists

README.md
... ... @@ -99,17 +99,18 @@ Where
99 99  
100 100 ```ruby
101 101 where: {
102   - expires_at: {gt: Time.now}, # lt, gte, lte also available
103   - orders_count: 1..10, # equivalent to {gte: 1, lte: 10}
104   - aisle_id: [25, 30], # in
105   - store_id: {not: 2}, # not
106   - aisle_id: {not: [25, 30]}, # not in
107   - user_ids: {all: [1, 3]}, # all elements in array
108   - category: /frozen .+/, # regexp
109   - store_id: {_exists: true}, # exists [master]
  102 + expires_at: {gt: Time.now}, # lt, gte, lte also available
  103 + orders_count: 1..10, # equivalent to {gte: 1, lte: 10}
  104 + aisle_id: [25, 30], # in
  105 + store_id: {not: 2}, # not
  106 + aisle_id: {not: [25, 30]}, # not in
  107 + user_ids: {all: [1, 3]}, # all elements in array
  108 + category: /frozen .+/, # regexp
  109 + store_id: {exists: true}, # exists [master]
  110 + category: {prefix: "Frozen"}, # prefix
110 111 _or: [{in_stock: true}, {backordered: true}],
111 112 _and: [{in_stock: true}, {backordered: true}],
112   - _not: {store_id: 1} # negate a condition
  113 + _not: {store_id: 1} # negate a condition
113 114 }
114 115 ```
115 116  
... ...
lib/searchkick/query.rb
... ... @@ -945,7 +945,7 @@ module Searchkick
945 945 end
946 946 when :in
947 947 filters << term_filters(field, op_value)
948   - when :_exists
  948 + when :exists
949 949 filters << {exists: {field: field}}
950 950 else
951 951 range_query =
... ...
test/where_test.rb
... ... @@ -68,8 +68,8 @@ class WhereTest &lt; Minitest::Test
68 68 assert_search "product", ["Product B", "Product C"], where: {user_ids: {_not: [2], in: [1, 3]}}
69 69  
70 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}}
  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 73  
74 74 # not
75 75 assert_search "product", ["Product D"], where: {user_ids: nil}
... ...