Pagination Is Still Relevant: Building Predictable Search Experiences with useSearch
A Solution Architect's perspective on search navigation, result consistency, and why traditional pagination still has a place in modern applications.
Not Every Search Experience Needs Infinite Scrolling
Imagine we are building an investment product directory for a SitecoreAI website.
Visitors can search across hundreds of investment products and educational resources.
During the initial design discussion, someone suggests infinite scrolling because it feels more modern.
Another team member raises a valid concern.
"Our users often compare results and return to a specific page. Would numbered pagination make navigation easier?"
This is where the discussion becomes interesting.
Infinite scrolling may work well for exploratory content, but for structured search experiences, traditional pagination can be more predictable.
SitecoreAI Content SDK provides the useSearch hook specifically for this kind of requirement.
Understanding useSearch
The useSearch hook allows React and Next.js applications to execute searches using conventional page-number-based navigation.
It supports search queries, sorting, page size, locale, and other parameters.
A basic implementation looks like this:
import { useSearch } from '@sitecore-content-sdk/nextjs/search';
const { results } = useSearch({
searchIndexId: 'YOUR_SEARCH_INDEX_ID',
query: 'investment',
page: 1,
pageSize: 10,
});Here, the application requests the first page containing up to ten matching results.
An important detail is that page numbering starts at 1 rather than 0.
This is easy to overlook when working with multiple pagination libraries or APIs that use different conventions.
Search Is Also About State Management
Now imagine the visitor enters a new keyword after reaching page five.
Should the application continue searching from page five?
Usually, that would create a confusing experience.
When the query changes, the application should generally reset the current page and present results from the beginning.
The same principle applies when filters change.
Content SDK supports options such as keepPreviousData, which allows the interface to retain earlier results while a new request is in progress.
This can make transitions feel smoother, but the interface should communicate when the displayed information belongs to a previous request.
Otherwise, visitors may think they are viewing results for the new query.
A Few Useful Capabilities
The hook supports sorting by one or more indexed fields.
For example, an insights page may allow visitors to order content by publication date.
It also supports controlled execution through the enabled option.
In Content SDK 2.3.0 and later, locale-aware searches and facets are supported.
Version 2.4.0 adds More Like This queries using a seed item.
These capabilities make useSearch useful beyond a simple search-results page.
What Would I Review as a Solution Architect?
I would focus on the complete navigation experience.
First, pagination should remain consistent when visitors change queries, filters, or sort order.
Second, results should have predictable ordering. When sorting by a field that contains duplicate values, a stable secondary sort may be worth considering.
Third, the application should handle an empty result set without displaying a broken pagination interface.
I would also consider whether the search state should appear in the URL.
For some business applications, preserving a query, selected filters, and page number in the URL improves navigation and sharing.
That is an application design decision rather than something the hook automatically guarantees.
Pagination may not be the most exciting feature in a modern frontend application.
But usability is not measured by how modern an interaction looks.
It is measured by how effectively it helps people complete their tasks.
The useSearch hook provides a practical foundation for building predictable, page-based search experiences.
As a Solution Architect, I would choose pagination when clarity, repeatability, and controlled navigation matter more than continuous browsing.
No comments:
Post a Comment