Commit 0a9bfdd2433c9aba64ac4f9d600882ba5e99f708

Authored by Andrew Kane
1 parent 798397df

Added like query

@@ -105,6 +105,7 @@ where: { @@ -105,6 +105,7 @@ where: {
105 store_id: {not: 2}, # not 105 store_id: {not: 2}, # not
106 aisle_id: {not: [25, 30]}, # not in 106 aisle_id: {not: [25, 30]}, # not in
107 user_ids: {all: [1, 3]}, # all elements in array 107 user_ids: {all: [1, 3]}, # all elements in array
  108 + category: {like: "%frozen%"}, # like [master]
108 category: /frozen .+/, # regexp 109 category: /frozen .+/, # regexp
109 store_id: {exists: true}, # exists [master] 110 store_id: {exists: true}, # exists [master]
110 category: {prefix: "Frozen"}, # prefix 111 category: {prefix: "Frozen"}, # prefix
lib/searchkick/query.rb
@@ -935,6 +935,9 @@ module Searchkick @@ -935,6 +935,9 @@ module Searchkick
935 } 935 }
936 } 936 }
937 } 937 }
  938 + when :like
  939 + regex = Regexp.escape(op_value).gsub("%", ".*").gsub("_", ".")
  940 + filters << {regexp: {field => {value: regex}}}
938 when :prefix 941 when :prefix
939 filters << {prefix: {field => op_value}} 942 filters << {prefix: {field => op_value}}
940 when :regexp # support for regexp queries without using a regexp ruby object 943 when :regexp # support for regexp queries without using a regexp ruby object
test/where_test.rb
@@ -128,6 +128,16 @@ class WhereTest &lt; Minitest::Test @@ -128,6 +128,16 @@ class WhereTest &lt; Minitest::Test
128 assert_search "product", ["Product A"], where: {user_ids: {exists: true}} 128 assert_search "product", ["Product A"], where: {user_ids: {exists: true}}
129 end 129 end
130 130
  131 + def test_like
  132 + store_names ["Product ABC", "Product DEF"]
  133 + assert_search "product", ["Product ABC"], where: {name: {like: "%ABC%"}}
  134 + assert_search "product", ["Product ABC"], where: {name: {like: "%ABC"}}
  135 + assert_search "product", [], where: {name: {like: "ABC"}}
  136 + assert_search "product", [], where: {name: {like: "ABC%"}}
  137 + assert_search "product", [], where: {name: {like: "ABC%"}}
  138 + assert_search "product", ["Product ABC"], where: {name: {like: "Product_ABC"}}
  139 + end
  140 +
131 # def test_script 141 # def test_script
132 # store [ 142 # store [
133 # {name: "Product A", store_id: 1}, 143 # {name: "Product A", store_id: 1},