Using pagination

You can use the limit and offset parameters to paginate your query. Use limit to specify the maximum number of results you want in the response, and use offset to indicate how many results you want to skip.

For the data model of the limit and offset parameters, see the Search and Recommendation API reference.

Getting search results with multiple pages.

To get search results with multiple pages, set the limit parameter to the number of results you want to show per page and the offset parameter to the number of results you want to skip because you showed them on a previous page.

For example, you want to show page two of the search results, where each page has five items.

The following code sample shows how to create a request:

RequestResponse
{
    "widget": {
        "items": [
            {
                "rfk_id": "rfkid_7",
                "entity": "content",
                "search": {
                    "content": {},
                    "limit": 5,
                    "offset": 5
                },
                "sources": [
                    "407033",
                    "408162",
                    "406277",
                    "406278"
                ]
            }
        ]
    },
    "context": {
        "locale": {
            "country": "us",
            "language": "en"
        }
    }
}

Getting search results with infinite scroll

For search results with an infinite scroll, first send a request when the visitor lands on the search results page and then send modified requests each time the visitor scrolls past a certain number of results.

For example, you want a search results page with an infinite scroll. After the visitor passes 50 results, you want ten more results to appear. From here on, after the visitor passes every tenth result, you want ten more results to appear.

The following is the first call you make:

RequestResponse
{
    "widget": {
        "items": [
            {
                "rfk_id": "rfkid_7",
                "entity": "content",
                "search": {
                    "content": {},
                    "limit": 50,
                    "offset": 0
                },
                "sources": [
                    "407033",
                    "408162"
                ]
            }
        ]
    },
    "context": {
        "locale": {
            "country": "us",
            "language": "en"
        },
        "user": {
            "uuid": "159871551-io-0i-4e-1p-s6ill6vhenvysbu27bbk-1664389956369"
        }
    }
}

After the visitor scrolls past the fiftieth result, change the search object to the following:

RequestResponse
{
    "search": {
        "content": {},
        "limit": 10,
        "offset": 50
    }
}

After the visitor scrolls past the ten new results that appeared after you sent the previous request, change the search object to the following:

RequestResponse
{
    "search": {
        "content": {},
        "limit": 10,
        "offset": 60
    }
}

Do you have some feedback for us?

If you have suggestions for improving this article,