Skip to content

Fix fulltext search pagination: all pages returned identical results#11797

Merged
RayBB merged 7 commits intomasterfrom
copilot/fix-fulltext-search-pagination
Feb 3, 2026
Merged

Fix fulltext search pagination: all pages returned identical results#11797
RayBB merged 7 commits intomasterfrom
copilot/fix-fulltext-search-pagination

Conversation

Copy link
Contributor

Copilot AI commented Feb 2, 2026

Fulltext search pagination (/search/inside?page=N) returned identical results for all page numbers due to incorrect default parameter preventing offset calculation.

Technical

Root cause: fulltext_search_async used offset=0 as default parameter. The condition if offset is None: never triggered, so offset = (page - 1) * limit never executed.

Fix: Changed default from offset=0 to offset=None.

# Before: offset always 0 regardless of page parameter
async def fulltext_search_async(q, page=1, offset=0, limit=100, ...):
    if offset is None:  # Never true when offset defaults to 0
        offset = (page - 1) * limit

# After: offset correctly calculated from page
async def fulltext_search_async(q, page=1, offset=None, limit=100, ...):
    if offset is None:  # Now triggers when offset not provided
        offset = (page - 1) * limit

Backward compatible: explicit offset values still override page calculation.

Testing

Added test_pagination_offset_calculation verifying:

  • Page 1 → offset 0
  • Page 10 → offset 180
  • Explicit offset parameter works

Test initially failed due to incorrect usage of httpx_mock.reset(False). Fixed by removing the invalid parameter as httpx_mock.reset() doesn't accept arguments.

Screenshot

N/A - backend pagination logic only

Stakeholders

cc @mekarpeles

Original prompt

This section details on the original issue you should resolve

<issue_title>Bug with Fulltext Search Results Pagination</issue_title>
<issue_description>### Problem

When performing a fulltext search, pagination of results is not working correctly. For example, https://openlibrary.org/search/inside?q=%22New+York+City%22&page=1 and https://openlibrary.org/search/inside?q=%22New+York+City%22&page=10 show the same results, even though they should display different pages. The UI pagination appears to be functional, but it seems the backend search logic is not handling the page parameter properly.

Relevant URLs:

Reproducing the bug

  1. Go to https://openlibrary.org/search/inside?q=%22New+York+City%22&page=1
  2. Go to https://openlibrary.org/search/inside?q=%22New+York+City%22&page=10
  • Expected behavior: Each page should display unique results corresponding to the page number.
  • Actual behavior: Both pages display the same results.

Context

  • Browser: All (tested on Chrome and Firefox)
  • OS: Any
  • Logged in: N/A
  • Environment: prod

Breakdown

Requirements Checklist

  • Diagnose where pagination breaks in backend search logic
  • Ensure different pages show unique results

Related files

  • core/search/solr.py
  • templates/search_inside.html
  • openlibrary/plugins/upstream/search.py

Testing

  • Confirm that pagination returns unique results on different pages
  • Add unit/integration tests if appropriate</issue_description>

<agent_instructions>Investigate why fulltext search pagination is not working, pinpoint where the page is not getting passed through correctly, create a fix.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: mekarpeles <978325+mekarpeles@users.noreply.github.com>
@github-project-automation github-project-automation bot moved this to Waiting Review/Merge from Staff in Ray's Project Feb 2, 2026
@mekarpeles mekarpeles marked this pull request as ready for review February 2, 2026 16:19
Copilot AI review requested due to automatic review settings February 2, 2026 16:19
@mekarpeles mekarpeles added the Priority: 1 Do this week, receiving emails, time sensitive, . [managed] label Feb 2, 2026
Copilot AI changed the title [WIP] Fix bug with fulltext search results pagination Fix fulltext search pagination: all pages returned identical results Feb 2, 2026
Copilot AI requested a review from mekarpeles February 2, 2026 16:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a pagination bug in the fulltext search functionality where different page numbers were returning the same search results.

Changes:

  • Fixed offset calculation logic in fulltext_search_async by changing the default parameter from offset=0 to offset=None
  • Added comprehensive test coverage for pagination offset calculation including edge cases

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
openlibrary/core/fulltext.py Changed default offset parameter from 0 to None to enable page-based offset calculation
openlibrary/tests/core/test_fulltext.py Added test to verify pagination offset calculation for different pages and explicit offset override

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Collaborator

@RayBB RayBB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mekarpeles @copilot the tests and pre-commit are both failing for this PR.

@cdrini
Copy link
Collaborator

cdrini commented Feb 3, 2026

@copilot the tests and pre-commit are both failing for this PR.

Co-authored-by: cdrini <6251786+cdrini@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 3, 2026

@mekarpeles @copilot the tests and pre-commit are both failing for this PR.

Fixed in de90d7f. The test was calling httpx_mock.reset(False) but the method doesn't accept any arguments. Removed the parameter and tests should now pass.

@copilot the tests and pre-commit are both failing for this PR.

Fixed in de90d7f. The test was calling httpx_mock.reset(False) but the method doesn't accept any arguments. Removed the parameter and tests should now pass.

Copilot AI requested a review from cdrini February 3, 2026 03:43
@github-actions github-actions bot added the Needs: Response Issues which require feedback from lead label Feb 3, 2026
@RayBB RayBB removed the Needs: Response Issues which require feedback from lead label Feb 3, 2026
@RayBB RayBB self-requested a review February 3, 2026 17:35
Copy link
Collaborator

@RayBB RayBB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the tests to be useful. Put it on testing, and it's working great.

@RayBB RayBB merged commit 1968a4b into master Feb 3, 2026
7 checks passed
@github-project-automation github-project-automation bot moved this from Waiting Review/Merge from Staff to Done in Ray's Project Feb 3, 2026
@RayBB RayBB deleted the copilot/fix-fulltext-search-pagination branch February 3, 2026 17:36
@RayBB RayBB removed the On Testing label Feb 3, 2026
bhardwajparth51 added a commit to bhardwajparth51/openlibrary that referenced this pull request Feb 17, 2026
…/fix-fulltext-search-pagination

Fix fulltext search pagination: all pages returned identical results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: 1 Do this week, receiving emails, time sensitive, . [managed]

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Bug with Fulltext Search Results Pagination

5 participants