Pagination: rows, start and cursorMark

Solr API

Solr sends results one page at a time: rows says how many, start says from which position, counting from 0.

01 · rows and start

PageParametersResults
1start=0&rows=101 to 10
2start=10&rows=1011 to 20
Nstart=(N−1)×rows
var rows = 10;
var pages = Math.ceil(data.response.numFound / rows);
var current = Math.floor(data.response.start / rows) + 1;

02 · Deep pages cost more

To answer start=100000&rows=20, Solr ranks the first 100,020 results again, on every request. Show a few hundred pages at most and refuse deeper requests in your own code. Opensolr checks the traffic of every index daily and emails you when it sees requests deeper than start=100000, which is how a scraper walking your index usually looks.

03 · Every document: cursorMark

To read a whole index (an export, a migration), use a cursor. Its cost stays the same on every page, however deep:

q=*:*&sort=id asc&rows=500&cursorMark=*
01

Each answer carries nextCursorMark. Send it as cursorMark in the next request, with the same query and sort.

02

When nextCursorMark comes back equal to the one you sent, you have every document.

03

The sort must end with id, and the request must not send start.

04 · Next

Sorting

Order results by date, price or any field.

Querying the Solr API

The request and the parameters that matter.

Results per page

How many results the hosted search page shows.