Pagination

Implement faster search results using the pagination support

This feature is only available for the Search API

Parameters

Pagination is supported using 2 parameters: limit and offset. As their name suggests, the first one defines the number of results per request's response, and the second defines the index of the first result to fetch.

Name

Type

Is Required?

Default value

limit

integer

10

offset

integer

0

limit

Set the number of results you want to fetch for each request.

Minimum ValueMaximum Value

0

1000

Notes

  • If the specified limit is out of bounds, the maximum value is used.

offset

This option allows you to set the index of the first retrieved item.

Minimum ValueMaximum Value

0

10 000

Notes

  • Indexes are 0-based: offset=0 will return the first item and offset=9 the tenth.

  • To have a proper pagination, the offset should always be a multiple of the limit parameter.

Response

All responses from XO Search uses the same format. Check API Reference page for a more detailed description of this format.

pageAPI Reference

Usage example

  • Fetch the 3rd page of results, with each page containing 10 elements (ie. offset is set to 20 and limit is set to 10)

NodeJS / NPM example

import { search } from '@attraqt/search';

const query = 'T-shirt';

search.init({ token: SEARCH_API_TOKEN });

const response = await search.query(query, {
  offset: 20,
  limit: 10
});

console.log(response);

HTML example

<script type="text/javascript">
    xo.init({
        search: {
            token: SEARCH_API_TOKEN
        }
    });

    xo.search.query('T-Shirt', {
        offset: 20,
        limit: 10
    }).then((response) => {
        console.log(response);
    });
</script>

Last updated