Commit e50570a41c36ce7b6e6fb84a22b664a4bc2bde87
1 parent
2ca8cbd4
Exists in
master
and in
17 other branches
Added support for endless ranges
Showing
3 changed files
with
12 additions
and
1 deletions
Show diff stats
CHANGELOG.md
lib/searchkick/query.rb
... | ... | @@ -843,7 +843,12 @@ module Searchkick |
843 | 843 | else |
844 | 844 | # expand ranges |
845 | 845 | if value.is_a?(Range) |
846 | - value = {gte: value.first, (value.exclude_end? ? :lt : :lte) => value.last} | |
846 | + # infinite? added in Ruby 2.4 | |
847 | + if value.end.nil? || (value.end.respond_to?(:infinite?) && value.end.infinite?) | |
848 | + value = {gte: value.first} | |
849 | + else | |
850 | + value = {gte: value.first, (value.exclude_end? ? :lt : :lte) => value.last} | |
851 | + end | |
847 | 852 | end |
848 | 853 | |
849 | 854 | value = {in: value} if value.is_a?(Array) | ... | ... |
test/where_test.rb
... | ... | @@ -35,6 +35,11 @@ class WhereTest < Minitest::Test |
35 | 35 | assert_search "product", ["Product C", "Product D"], where: {store_id: {not: [1, 2]}} |
36 | 36 | assert_search "product", ["Product C", "Product D"], where: {store_id: {_not: [1, 2]}} |
37 | 37 | assert_search "product", ["Product A"], where: {user_ids: {lte: 2, gte: 2}} |
38 | + assert_search "product", ["Product C", "Product D"], where: {store_id: 3..Float::INFINITY} | |
39 | + if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.6.0") | |
40 | + # use eval to prevent parse error | |
41 | + assert_search "product", ["Product C", "Product D"], where: {store_id: 3..eval("0..")} | |
42 | + end | |
38 | 43 | |
39 | 44 | # or |
40 | 45 | assert_search "product", ["Product A", "Product B", "Product C"], where: {or: [[{in_stock: true}, {store_id: 3}]]} | ... | ... |