Cloudant/Couch db pagination in search API - How to skip n number of records
Asked Answered
C

1

6

I am building a typical pagination that allows the user to click on a particular page number and view the results (similar to the google search result view). I am using the cloudant search API for this. The cloudant search API provides the limit option but no skip option. How can I skip n number of results if the user is on page 1 and clicks on page 4 ?

I can see that the pagination is implemented using bookmarks. Does it mean that I need to first get the bookmark for page 4 by sending 3 additional requests one after another to the search api ?

Cosh answered 27/8, 2017 at 19:1 Comment(0)
O
2

There are a couple of different ways of handling this - one is the one you already suggested, which is just to fetch the pages as needed to get the bookmarks. I'm not sure there are many alternatives for search results where we can't pre-calculate the results.

Another alternative, and this depends a bit on the details of what you are trying to do, is to create a view containing the data and use the keys to narrow down the view to the results you need. View outputs support use of limit and skip which would enable you to implement pagination.

There's also a good example of pagination in the docs: http://docs.couchdb.org/en/2.1.0/ddocs/views/pagination.html

Oconner answered 29/8, 2017 at 14:7 Comment(1)
Thank you. I will experiment with the views but I am not sure if view is what I should use coz I am implementing a searchCosh

© 2022 - 2024 — McMap. All rights reserved.