> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Method name: search(phrase: string) # Method package: wixSearch # Method menu location: wixSearch --> search # Method Link: https://dev.wix.com/docs/velo/apis/wix-search/search.md # Method Description: Creates a search builder. The `search()` function builds a search for a site and returns a [`WixSearchBuilder`](wix-search.WixSearchBuilder.html) object. The returned object contains a search builder, which is used to run the search with the [`find()`](wix-search.WixSearchBuilder.html#find) function. Before running `find()`, you can refine the search by chaining [`WixSearchBuilder`](wix-search.WixSearchBuilder.html) functions on to the search. `WixSearchBuilder` functions enable you to filter, sort, apply facets, and control the results a search returns. `search()` runs with the following [`WixSearchBuilder`](wix-search.WixSearchBuilder.html) defaults that you can override: + [**documentType**](wix-search.WixSearchBuilder.html#documentType): `"Site/Pages"` + [**facets**](wix-search.WixSearchBuilder.html#facets): none + [**fuzzy**](wix-search.WixSearchBuilder.html#fuzzy): `true` + [**language**](wix-search.WixSearchBuilder.html#language): For multilingual sites, the current language. For single-language sites, the site language. + [**limit**](wix-search.WixSearchBuilder.html#limit): `25` + [**skip**](wix-search.WixSearchBuilder.html#skip): `0` + [**searchFields**](wix-search.WixSearchBuilder.html#searchFields): All searchable fields. `find()` returns results in the form of a [`WixSearchResult`](wix-search.WixSearchResult.html), which contains `documents` that match the search, faceting and paging information, and functions for paging through the search results. `search()` is not case sensitive. If a search `phrase` is not specified, `search` returns all documents refined by the search builder. You can leave out the search phrase if you want to filter, sort, and/or apply facets to your site content without searching for a particular phrase. # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Build a search ```javascript import wixSearch from 'wix-search'; // ... let search = wixSearch.search(phrase); ``` ## Build and perform a search ```javascript import wixSearch from 'wix-search'; // ... $w("#searchInput").onKeyPress((keyPress) => { if (keyPress.key === "Enter") { const phrase = $w("#searchInput").value; wixSearch.search(phrase) .find() .then((results) => { if (results.documents.length > 0) { let documents = results.documents; let firstDocument = documents[0]; let facets = results.facets; let totalCount = results.totalCount; let pageSize = results.pageSize; let currentPage = results.currentPage; let totalPages = results.totalPages; let hasNext = results.hasNext(); let hasPrev = results.hasPrev(); let length = results.length; } else { console.log("No matching results"); } }) .catch((error) => { console.log(error); }); } }); ``` ## Build and perform a search and get the first document in the search results ```javascript import wixSearch from 'wix-search'; // ... $w("#searchInput").onKeyPress((keyPress) => { if (keyPress.key === "Enter") { const phrase = $w("#searchInput").value; wixSearch.search(phrase) .find() .then((results) => { if (results.documents.length > 0) { let firstDocument = results.documents[0]; } else { console.log("No matching results"); } }) .catch((error) => { console.log(error); }); } }); /** Example firstDocument: * * { * "_id": "18176e85-ef8b-447c-b66f-f7b7ca360a5d", * "url": "/about", * "documentType" "Site/Pages", * "image": "wix:image://v1/67...4df7.jpg#originWidth=1920&originHeight=2891", * "title": "The Leader in Website Creation", * "description": "Create your own professional web presence—exactly the way you want. Our powerful..." * } */ ``` ## Build and perform a search and display the results in a repeater ```javascript import wixSearch from 'wix-search'; // ... // Before search runs, set the repeater data as empty $w('#repeater').data = []; $w("#searchInput").onKeyPress((keyPress) => { if (keyPress.key === "Enter") { const phrase = $w("#searchInput").value; wixSearch.search(phrase) .documentType("Stores/Products") .find() .then((results) => { if (results.documents.length > 0) { $w('#repeater').data = results.documents; } else { console.log("No matching results"); } }) .catch((error) => { console.log(error); }); } }); $w("#repeater").onItemReady(($item, itemData) => { $item("#title").text = itemData.title; $item("#description").text = itemData.description; $item("#image").src = itemData.image; $item("#button").link = itemData.url; }); ``` ---