diff --git a/lib/searchkick/relation.rb b/lib/searchkick/relation.rb index c913409..de344fe 100644 --- a/lib/searchkick/relation.rb +++ b/lib/searchkick/relation.rb @@ -38,6 +38,16 @@ module Searchkick self end + def offset(value) + clone.offset!(value) + end + + def offset!(value) + check_loaded + @options[:offset] = value + self + end + def loaded? !@execute.nil? end diff --git a/test/pagination_test.rb b/test/pagination_test.rb index 7c52645..9b59381 100644 --- a/test/pagination_test.rb +++ b/test/pagination_test.rb @@ -34,6 +34,11 @@ class PaginationTest < Minitest::Test assert_order "product", ["Product C", "Product D"], order: {name: :asc}, offset: 2, limit: 100 end + def test_offset_relation + store_names ["Product A", "Product B", "Product C", "Product D"] + assert_equal ["Product C", "Product D"], Product.search("product", order: {name: :asc}).offset(2).limit(100).map(&:name) + end + def test_pagination store_names ["Product A", "Product B", "Product C", "Product D", "Product E", "Product F"] products = Product.search("product", order: {name: :asc}, page: 2, per_page: 2, padding: 1) -- libgit2 0.21.0