Commit cc2a694927b8a2622da4a733ffdac54c044436f7
1 parent
eb356914
Exists in
master
and in
21 other branches
Added ability to perform where nil queries
Showing
3 changed files
with
14 additions
and
2 deletions
Show diff stats
lib/searchkick/model.rb
lib/searchkick/search.rb
... | ... | @@ -218,7 +218,11 @@ module Searchkick |
218 | 218 | end |
219 | 219 | end |
220 | 220 | else |
221 | - filters << {term: {field => value}} | |
221 | + if value.nil? | |
222 | + filters << {missing: {"field" => field, existence: true, null_value: true}} | |
223 | + else | |
224 | + filters << {term: {field => value}} | |
225 | + end | |
222 | 226 | end |
223 | 227 | end |
224 | 228 | end | ... | ... |
test/sql_test.rb
... | ... | @@ -75,6 +75,14 @@ class TestSql < Minitest::Unit::TestCase |
75 | 75 | assert_search "product", ["Product A"], where: {color: ["RED"]} |
76 | 76 | end |
77 | 77 | |
78 | + def test_where_nil | |
79 | + store [ | |
80 | + {name: "Product A"}, | |
81 | + {name: "Product B", color: "red"} | |
82 | + ] | |
83 | + assert_search "product", ["Product A"], where: {color: nil} | |
84 | + end | |
85 | + | |
78 | 86 | def test_near |
79 | 87 | store [ |
80 | 88 | {name: "San Francisco", latitude: 37.7833, longitude: -122.4167}, | ... | ... |