Commit 141e3f1a4a67d3a4a2a3e79ffa59ee0f91101b6c
1 parent
13d63c85
Exists in
master
and in
21 other branches
Added basic support for regexp - closes #330
Showing
2 changed files
with
7 additions
and
0 deletions
Show diff stats
lib/searchkick/query.rb
@@ -531,6 +531,8 @@ module Searchkick | @@ -531,6 +531,8 @@ module Searchkick | ||
531 | end | 531 | end |
532 | elsif value.nil? | 532 | elsif value.nil? |
533 | {missing: {"field" => field, existence: true, null_value: true}} | 533 | {missing: {"field" => field, existence: true, null_value: true}} |
534 | + elsif value.is_a?(Regexp) | ||
535 | + {regexp: {field => {value: value.source}}} | ||
534 | else | 536 | else |
535 | {term: {field => value}} | 537 | {term: {field => value}} |
536 | end | 538 | end |
test/sql_test.rb
@@ -93,6 +93,11 @@ class TestSql < Minitest::Test | @@ -93,6 +93,11 @@ class TestSql < Minitest::Test | ||
93 | assert_search "product", ["Product B"], where: {user_ids: {not: [3, nil]}} | 93 | assert_search "product", ["Product B"], where: {user_ids: {not: [3, nil]}} |
94 | end | 94 | end |
95 | 95 | ||
96 | + def test_regexp | ||
97 | + store_names ["Product A"] | ||
98 | + assert_search "*", ["Product A"], where: {name: /Pro.+/} | ||
99 | + end | ||
100 | + | ||
96 | def test_where_string | 101 | def test_where_string |
97 | store [ | 102 | store [ |
98 | {name: "Product A", color: "RED"} | 103 | {name: "Product A", color: "RED"} |