Search...
limit( )
Limits the number of documents the search returns.
Description
Syntax
function limit(limit: number): WixSearchBuilder
limit Parameters
NAME
TYPE
DESCRIPTION
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';23// ...45$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 = [];34 let results = await wixSearch.search(phrase)5 .limit(1000)6 .find();78 allDocuments.push(results.documents);910 while(results.hasNext()) {11 results = await results.next();12 allDocuments.push(results.documents);13 }1415 return allDocuments;16}