# Site Search

## Site Search

**Files:** `src/config/config.toml`, page frontmatter, `src/i18n/<language>.json` · **Skill level:** Beginner

Visitors open search with <kbd>⌘</kbd> + <kbd>K</kbd> (Mac), <kbd>Ctrl</kbd> + <kbd>K</kbd> (Windows and Linux), or <kbd>/</kbd> when they aren't typing in a field. They can also click **Search** in the strip along the bottom of the **Pages** menu, in the header and in the phone menu, or the search button on the journal page. Results are grouped into projects, services, journal, and pages, and each language searches its own pages: on `/fr/`, search finds French pages.

With the field still empty, search works as a quick menu: the pages of the header menu, then a light or dark switch, copy email, and a link to the other language.

Search is powered by [Pagefind](https://pagefind.app/). It runs in the browser from an index made at the end of `npm run build`, so there is no search service to pay for or set up.

<Aside type="note">
  In `npm run dev`, search says the index is missing, because the index only
  exists after a build. Test it with `npm run preview` or on your deployed site.
</Aside>

### Settings
```toml
# src/config/config.toml
[settings.search]
  enable  = true
  exclude = ["/components/"] # path prefixes to leave out of the index
```

Prefixes ignore the language, so `"/team/"` also leaves out `/fr/team/` and `/ar/team/`. `/components/` is a sample page of the Markdown shortcodes, left out on purpose.

### Leave A Page Out
Add `excludeFromSearch: true` to the page's frontmatter. Some pages are left out automatically:

- pages marked `noindex`, such as `/elements/`, and pages without the site header
- paginated, category, and tag listings of the journal, because they only repeat their entries

Only the main content of each page is indexed. The header, the footer, and the call to action are not, so every result points to real content.

### Change The Wording
The texts of the search window (placeholder, "no results", the group names) are under `search` in `src/i18n/<language>.json`, for example `search.placeholder` ("Search or jump to a page"). Change them in every language.

### Turn Search Off
Set `enable = false`. The search window and its buttons disappear, including the **Search** link in the Pages menu.

That link is a quick link in the menu file: an item in `bar.links` with `"action": "search"` and `"shortcut": "⌘K"`, the key hint shown beside it. You can move it to another mega menu or remove it in each `src/config/menu.<language>.json`. See [Navigation](/margo/features/navigation/). The build still runs Pagefind, which costs a few seconds and does no harm.

### Do It With AI
```text
Leave these pages out of site search on my Margo site: [PAGES]. Add excludeFromSearch: true to
their content files in every language folder of src/content/, or add their path prefix to
exclude under [settings.search] in src/config/config.toml if it is a whole folder. Then run
npm run build and npm run preview, and tell me how to check it.
```