Skip to content

Commit

Permalink
Fixed per_page method when paginating beyond max_result_window - fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jul 12, 2024
1 parent e1d3be0 commit 9b6e4ce
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Added experimental support for `_raw` to `where` option
- Added warning for `exists` with non-`true` values
- Added warning for full reindex and `:queue` mode
- Fixed `per_page` method when paginating beyond `max_result_window`
- Dropped support for Ruby < 3.1

## 5.3.1 (2023-11-28)
Expand Down
3 changes: 2 additions & 1 deletion lib/searchkick/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ def prepare
scroll = options[:scroll]

max_result_window = searchkick_options[:max_result_window]
original_per_page = per_page
if max_result_window
offset = max_result_window if offset > max_result_window
per_page = max_result_window - offset if offset + per_page > max_result_window
Expand Down Expand Up @@ -558,7 +559,7 @@ def prepare

@body = payload
@page = page
@per_page = per_page
@per_page = original_per_page
@padding = padding
@load = load
@scroll = scroll
Expand Down
5 changes: 4 additions & 1 deletion test/pagination_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ def test_no_deep_paging

def test_max_result_window
with_options({max_result_window: 10000}, Song) do
assert_empty Song.search("*", offset: 10000, limit: 1).to_a
relation = Song.search("*", offset: 10000, limit: 1)
assert_empty relation.to_a
assert_equal 1, relation.per_page
assert_equal 0, relation.total_pages
end
end

Expand Down

0 comments on commit 9b6e4ce

Please sign in to comment.