search() function includes built-in pagination support. Results are sliced server-side (or client-side) and returned with metadata about total results, pages, and current position.
Overview
Pagination is controlled by thePaginationOptions parameter passed to search():
PaginationOptions type
Fromsrc/types/index.ts:62-65:
page?: number- Page number (1-indexed, defaults to 1)limit?: number- Results per page (defaults to 20)
Both fields are optional. If omitted, defaults are applied:
{ page: 1, limit: 20 }Default behavior
Fromsrc/core/search.ts:309:
- Returns first 20 results
- Current page is 1
- Total pages calculated based on total results
Pagination metadata
TheSearchResponse includes detailed pagination metadata:
src/types/index.ts:67-76:
Implementation details
Fromsrc/core/search.ts:366-374:
1
Normalize page and limit
Both values are clamped to minimum of 1:
2
Calculate offset
Convert page number to array offset (0-indexed):
3
Slice results
Extract the requested page from all sorted results:
4
Calculate metadata
Determine total pages and include in response:
Usage examples
First page (default)
Custom page size
Navigate to specific page
Get all results
Building pagination UI
React example
Page number buttons
Edge cases
Invalid page numbers
Zero or negative limit
No results
Performance considerations
Pagination happens after search and scoring. All results are computed first, then sliced. For very large result sets, consider implementing server-side pagination if performance becomes an issue.
Search flow
- Search runs across all verses (6,236 verses)
- Results are scored and sorted
- Then pagination slices the sorted results
- Only the requested page is returned
- ✓ Consistent scoring and ordering across pages
- ✓ Accurate total counts and page numbers
- ✗ All results must be computed even if only viewing page 1