How to implement pagination

To implement pagination, we need to configure two parameters in the query request.

  • start: Indicates from where the results should be returned from the complete result set
  • rows: Indicates how many results must be returned from the complete result set

We have to specify some value if we have used the start parameter in a request. Keep in mind that the value of the start parameter should be less than the total number of matching results. If we set start higher than the total number of matching results found, the query will not return anything.

Example: Search for a query q=*:* and get the first five results sorted by ID in ascending order.

URLhttp://localhost:8983/solr/techproducts/select?q=*:*&fl=id,name&start=0&rows=5&sort=id asc:

{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"*:*",
"fl":"id,name",
"start":"0",
"sort":"id asc",
"rows":"5"}},
"response":{"numFound":32,"start":0,"docs":[
{
"id":"0579B002",
"name":"Canon PIXMA MP500 All-In-One Photo Printer"},
{
"id":"100-435805",
"name":"ATI Radeon X1900 XTX 512 MB PCIE Video Card"},
{
"id":"3007WFP",
"name":"Dell Widescreen UltraSharp 3007WFP"},
{
"id":"6H500F0",
"name":"Maxtor DiamondMax 11 - hard drive - 500 GB - SATA-300"},
{
"id":"9885A004",
"name":"Canon PowerShot SD500"}]
}
}

Only five results are returned in the response. Now, if we want the next five results, we set start=5 and rows=5. Please note that the response index starts with zero.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.20.87