From 9483e7d38f419e4a44649d231216300092d45c23 Mon Sep 17 00:00:00 2001 From: Ian Norris Date: Thu, 11 Oct 2018 11:59:55 -0700 Subject: [PATCH] Add prefix ability to searches (#1200) --- lib/searchkick/query.rb | 2 ++ test/where_test.rb | 5 +++++ 2 files changed, 7 insertions(+), 0 deletions(-) diff --git a/lib/searchkick/query.rb b/lib/searchkick/query.rb index 52819fc..876978f 100644 --- a/lib/searchkick/query.rb +++ b/lib/searchkick/query.rb @@ -895,6 +895,8 @@ module Searchkick } } } + when :prefix + filters << {prefix: {field => op_value}} when :regexp # support for regexp queries without using a regexp ruby object filters << {regexp: {field => {value: op_value}}} when :not, :_not # not equal diff --git a/test/where_test.rb b/test/where_test.rb index d323f8d..b6e324d 100644 --- a/test/where_test.rb +++ b/test/where_test.rb @@ -74,6 +74,11 @@ class WhereTest < Minitest::Test assert_search "*", ["Product A"], where: {name: /Pro.+/} end + def test_prefix + store_names ["Product A", "Product B", "Item C"] + assert_search "*", ["Product A", "Product B"], where: { name: { prefix: 'Pro'}} + end + def test_alternate_regexp store_names ["Product A", "Item B"] assert_search "*", ["Product A"], where: {name: {regexp: "Pro.+"}} -- libgit2 0.21.0