Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Whoosh Pagination: What to Know About Pages and Result Counts

Build accurate Whoosh pagination labels from ResultsPage metadata: distinguish one-based page numbers, zero-based offsets, page hits, and total matches.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Searcher.search_page(query, pagenum, pagelen=...) for fixed-size pages, then build the range and page label from the returned ResultsPage. Whoosh page numbers start at 1; offsets start at 0. Keeping those conventions separate prevents off-by-one errors and avoids mistaking the current page’s hits for the total matches.

Paginate fixed-size results with search_page

Whoosh’s Searcher.search_page(query, pagenum, pagelen=...) returns a ResultsPage that can be iterated like a result set and also exposes metadata for the requested page. The page number is one-based, and the default page length is 10. Set pagelen explicitly when your interface uses a different fixed page size.

As an Amazon Associate I earn from qualifying purchases.

page_number = 3
page_size = 10
page = searcher.search_page(query, page_number, pagelen=page_size)

start = page.offset + 1
end = page.offset + page.pagelen

label = f"Page {page.pagenum} of {page.pagecount}"
range_label = f"Showing {start}–{end} of {page.total}"

for hit in page:
    print(hit)

This example follows the API’s one-based page convention and uses the returned metadata for the displayed values. See the Whoosh 2.7.4 searching API reference.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What the page metadata means

Field Meaning Use in the interface
pagenum The current, one-based page number. Display as the current page.
pagecount The number of pages available for the query at the requested page length. Display as the total page count.
offset The zero-based index of the first result on this page. Add 1 for the first displayed result number.
pagelen The number of hits actually present on this page; the final page may be shorter than the requested page length. Calculate the displayed end from the actual page length.
total The total number of matching hits. Display as the total matches, not as the current page’s hit count.

For a page beginning at offset 20 with 10 hits, the displayed range is 21–30. If the final page begins at offset 20 but contains only 4 hits, display 21–24—not 21–30. The formulas are start = page.offset + 1 and end = page.offset + page.pagelen.

Validate the page parameter at the application boundary

Parse a page value from the query string as an integer and validate it before calling Whoosh. Since page numbers begin at 1, a user-facing page parameter should not be treated as a zero-based offset. The API reference says that requesting a page beyond the available count may return the last available page, with pagenum adjusted accordingly. If your application depends on how zero or negative values behave, verify that behavior against the installed Whoosh release rather than assuming it.

Use search_range for arbitrary offsets

search_page fits page-number navigation where each page starts at a multiple of a fixed page length. If your interface instead requests an arbitrary start and end—for example, a window that begins at result 7—use search_range(query, start, end) when supported by your installed version. Converting an unaligned start offset into a page number can shift the window and cause rows to be skipped or repeated. The Whoosh search guide describes this distinction.

Keep result windows bounded

The standard search() method returns at most the first 10 results by default. Specify an appropriate limit when retrieving a larger window, and avoid requesting an unbounded result set if the interface only needs one page. Pagination does not make deep pages free: the Whoosh guide illustrates that page 100 at 10 results per page takes work comparable to finding the first 1,000 results. That is a documentation example, not an independent benchmark. Keep page lengths bounded and consider limiting how deep users can navigate.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check the installed Whoosh version

The API reference is for Whoosh 2.7.4, while the search guide is hosted separately. Confirm the distribution and version used by your application before relying on search_range or details that may vary between releases. The project’s searching documentation is another reference for result retrieval behavior.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.