Commit 9483e7d38f419e4a44649d231216300092d45c23
Committed by
Andrew Kane
1 parent
42be2748
Exists in
master
and in
17 other branches
Add prefix ability to searches (#1200)
allows direct leveraging of https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-prefix-query.html Co-authored-by: Daniel Carpenter <daniel.carpenter@omadahealth.com> Co-authored-by: Jonathan Wrobel <jonathan.wrobel@omadahealth.com>
Showing
2 changed files
with
7 additions
and
0 deletions
Show diff stats
lib/searchkick/query.rb
... | ... | @@ -895,6 +895,8 @@ module Searchkick |
895 | 895 | } |
896 | 896 | } |
897 | 897 | } |
898 | + when :prefix | |
899 | + filters << {prefix: {field => op_value}} | |
898 | 900 | when :regexp # support for regexp queries without using a regexp ruby object |
899 | 901 | filters << {regexp: {field => {value: op_value}}} |
900 | 902 | when :not, :_not # not equal | ... | ... |
test/where_test.rb
... | ... | @@ -74,6 +74,11 @@ class WhereTest < Minitest::Test |
74 | 74 | assert_search "*", ["Product A"], where: {name: /Pro.+/} |
75 | 75 | end |
76 | 76 | |
77 | + def test_prefix | |
78 | + store_names ["Product A", "Product B", "Item C"] | |
79 | + assert_search "*", ["Product A", "Product B"], where: { name: { prefix: 'Pro'}} | |
80 | + end | |
81 | + | |
77 | 82 | def test_alternate_regexp |
78 | 83 | store_names ["Product A", "Item B"] |
79 | 84 | assert_search "*", ["Product A"], where: {name: {regexp: "Pro.+"}} | ... | ... |