The {@link Paginator} makes it possible to iterate over a{@link ViewResponse} in pages.
It is possible to iterate over both reduced and non-reduced results, but iterating over non-reduced results is considerably faster, because a more efficient pagination approach can be used.
Usage:
{@code View view = client.getView("design_doc", "view_name"); Query query = new Query(); int docsPerPage = 20; Paginator paginator = client.paginatedQuery(view, query, docsPerPage);}while(paginator.hasNext()) ViewResponse response = paginator.next(); for(ViewRow row : response) { System.out.println(row.getKey()); } } }
Note that if a custom limit is set on the {@link Query} object when itgets passed in into the {@link Paginator}, then it is considered as an absolute limit. The {@link Paginator} will stop iterating once this absolutelimit is reached. If no limit is provided, the {@link Paginator} will moveforward until no more documents are returned by the view.
If you encounter an infinite loop when emitting stringified numbers from your View, see the {@link Paginator#forcedKeyType} method for instructionsto remedy this situation.