Search.../

next( )

Retrieves the next page of search results.

Description

The next() function retrieves the next page of search results.

The page size is defined by the limit() function, can be retrieved using the pageSize property. You navigate through pages using the prev() and next() functions.

If items are added or removed between calls to next(), the values returned by WixSearchResult may change.

Syntax

function next(): Promise<WixSearchResult>

next Parameters

This function does not take any parameters.

Returns

Fulfilled - A search result object with the next page of search results. Rejected - The errors that caused the rejection.

Return Type:

Was this helpful?

Get the next page of a search result

Code Example

Copy Code
1oldResults.next()
2 .then( (results) => {
3 let newResults = results;
4 let documents = newResults.documents;
5 let firstDocument = documents[0];
6 let facets = results.facets;
7 let totalCount = newResults.totalCount;
8 let pageSize = newResults.pageSize;
9 let currentPage = newResults.currentPage;
10 let totalPages = newResults.totalPages;
11 let hasNext = newResults.hasNext();
12 let hasPrev = newResults.hasPrev();
13 let length = newResults.length;
14 } )
15 .catch( (error) => {
16 console.log(error);
17 } );
Iterate through all pages of search results

This example demonstrates how to get all search results, bypassing the maximum limit of 1000.

Code Example

Copy Code
1async function retrieveAllDocuments(phrase){
2 let allDocuments = [];
3
4 let results = await wixSearch.search(phrase)
5 .limit(1000)
6 .find();
7
8 allDocuments.push(results.documents);
9
10 while(results.hasNext()) {
11 results = await results.next();
12 allDocuments.push(results.documents);
13 }
14
15 return allDocuments;
16}