Permalink
Browse files

Added support for endless ranges

  • Loading branch information...
ankane committed Jan 23, 2019
1 parent 2ca8cbd commit e50570a41c36ce7b6e6fb84a22b664a4bc2bde87
Showing with 12 additions and 1 deletion.
  1. +1 −0 CHANGELOG.md
  2. +6 −1 lib/searchkick/query.rb
  3. +5 −0 test/where_test.rb
@@ -1,5 +1,6 @@
## 3.1.3 [unreleased]

- Added support for endless ranges
- Added `prefix` to `where`
- Fixed error with some language stemmers and Elasticsearch 6.5

@@ -843,7 +843,12 @@ def where_filters(where)
else
# expand ranges
if value.is_a?(Range)
value = {gte: value.first, (value.exclude_end? ? :lt : :lte) => value.last}
# infinite? added in Ruby 2.4
if value.end.nil? || (value.end.respond_to?(:infinite?) && value.end.infinite?)
value = {gte: value.first}
else
value = {gte: value.first, (value.exclude_end? ? :lt : :lte) => value.last}
end
end

value = {in: value} if value.is_a?(Array)
@@ -35,6 +35,11 @@ def test_where
assert_search "product", ["Product C", "Product D"], where: {store_id: {not: [1, 2]}}
assert_search "product", ["Product C", "Product D"], where: {store_id: {_not: [1, 2]}}
assert_search "product", ["Product A"], where: {user_ids: {lte: 2, gte: 2}}
assert_search "product", ["Product C", "Product D"], where: {store_id: 3..Float::INFINITY}
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.6.0")
# use eval to prevent parse error
assert_search "product", ["Product C", "Product D"], where: {store_id: 3..eval("0..")}
end

# or
assert_search "product", ["Product A", "Product B", "Product C"], where: {or: [[{in_stock: true}, {store_id: 3}]]}

0 comments on commit e50570a

Please sign in to comment.