Search.../

limit( )

Limits the number of documents the search returns.

Description

The limit() function defines the number of results a search returns in each page. Only one page of results is retrieved at a time. The next() and prev() functions are used to navigate the pages of a search result.

By default, limit is set to 25.

The maximum value that limit() can accept is 1000.

Syntax

function limit(limit: number): WixSearchBuilder

limit Parameters

NAME
TYPE
DESCRIPTION
limit
number

The number of documents to return, which is also the pageSize of the results object.

Returns

A WixSearchBuilder object representing the refined search.

Return Type:

Was this helpful?

Add a limit to a search

Copy Code
1let newSearch = search.limit(10);
Create a search, add a limit, and run it

Copy Code
1import wixSearch from 'wix-search';
2
3// ...
4
5$w("#searchInput").onKeyPress((keyPress) => {
6 if (keyPress.key === "Enter") {
7 const phrase = $w("#searchInput").value;
8 wixSearch.search(phrase)
9 .limit(10)
10 .find()
11 .then((results) => {
12 if (results.documents.length > 0) {
13 let documents = results.documents;
14 } else {
15 console.log("No matching results");
16 }
17 })
18 .catch((error) => {
19 console.log(error);
20 });
21 }
22});
Iterate through all pages of search results

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

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}