# Search

> Static full-text search, with no server and no search service.

Source: https://aymericchaverot.github.io/zenith-docs/search/

ZenithDocs indexes your pages at build time with [Pagefind](https://pagefind.app), and ships a search dialog that loads its index only when a reader opens it.

Nothing else is needed: no API key, no search service, no server. The index is written to `dist/pagefind` and served as static files, like the rest of the site.

## Using it

Press <kbd>Ctrl</kbd> + <kbd>K</kbd>, or <kbd>Cmd</kbd> + <kbd>K</kbd> on a Mac, or click the search field in the header. Results list the matching pages, with the matching sections below them. Move through them with the arrow keys and open one with <kbd>Enter</kbd>.

:::note
The index is created by the build, `zenith build` or `astro build`. In the development server, the dialog opens but reports that search is only available once the site has been built: run the build, then `zenith preview` or `astro preview`, to try it.
:::

## What gets indexed

Only the article of each page: the title, the description and the content. The header, the sidebar, the table of contents, the breadcrumb and the page footer are left out, so navigation labels never pollute the results.

Exclude part of a page with Pagefind's own attribute:

```mdx
<div data-pagefind-ignore>
  This section is not searchable.
</div>
```

## Turning it off

```js title="astro.config.mjs"
zenith({
  title: 'My Docs',
  search: false, // [!code highlight]
});
```

The search field disappears from the header, and no index is built.

## Weight and privacy

The dialog itself is about 1 kB of JavaScript, inlined in the page. Pagefind is only downloaded when the dialog is opened: about 25 kB for its script and worker, and 70 kB for its WebAssembly module, all compressed. It then loads the parts of the index a query needs, between 7 and 35 kB each on this site, and about 1 kB per result shown. The index is static and queried in the browser, so searches never leave it.