> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> 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`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - 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`](https://dev.wix.com/docs/velo/apis/wix-search/wix-search-builder/introduction.md) object.

 The returned object contains a search builder, which is used
 to run the search with the [`find()`](https://dev.wix.com/docs/velo/apis/wix-search/wix-search-builder/find.md)
 function.

 Before running `find()`, you can refine the search by chaining [`WixSearchBuilder`](https://dev.wix.com/docs/velo/apis/wix-search/wix-search-builder/introduction.md)
 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`](https://dev.wix.com/docs/velo/apis/wix-search/wix-search-builder/introduction.md)
 defaults that you can override:

 + [**documentType**](https://dev.wix.com/docs/velo/apis/wix-search/wix-search-builder/document-type.md): `"Site/Pages"`
 + [**facets**](https://dev.wix.com/docs/velo/apis/wix-search/wix-search-builder/facets.md): none
 + [**fuzzy**](https://dev.wix.com/docs/velo/apis/wix-search/wix-search-builder/fuzzy.md): `true`
 + [**language**](https://dev.wix.com/docs/velo/apis/wix-search/wix-search-builder/language.md): For multilingual sites, the current language. For single-language sites, the site language.
 + [**limit**](https://dev.wix.com/docs/velo/apis/wix-search/wix-search-builder/limit.md): `25`
 + [**skip**](https://dev.wix.com/docs/velo/apis/wix-search/wix-search-builder/skip.md): `0`
 + [**searchFields**](https://dev.wix.com/docs/velo/apis/wix-search/wix-search-builder/search-fields.md): All searchable fields.


`find()` returns results in the form of a [`WixSearchResult`](https://dev.wix.com/docs/velo/apis/wix-search/wix-search-result/introduction.md), 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;
});

```

---