---
title: "搜索"
description: "开箱即用的 Pagefind 全文搜索，也可接入自定义搜索服务。"
---

> Documentation Index
> Fetch the complete documentation index at: https://nimbus-docs.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 搜索

搜索功能默认启用，由 [Pagefind](https://pagefind.app/) 提供支持——一个静态的、构建时索引引擎。无需任何配置。

<h2 id="how-it-works">工作原理</h2>

在 `astro build` 之后，Nimbus 会对输出目录 `dist/` 运行 Pagefind，并将搜索索引写入页面旁边。索引以静态方式提供服务，因此搜索可在任何无后端的主机上运行。

将 Pagefind 安装为开发依赖，以便构建步骤能找到它：

```sh
npm install pagefind
pnpm add pagefind
yarn add pagefind
bun add pagefind
```

<h2 id="controlling-whats-indexed">控制索引内容</h2>

页面是否纳入搜索索引取决于 `noindex` 字段，除非你显式设置了 `searchable`：

```yaml
---
title: Internal note
noindex: true        # 不被搜索引擎收录……
searchable: true     # ……但仍可在站内搜索中找到
---
```

`draft: true` 的页面永远不会被索引。详见 [Frontmatter](/writing/frontmatter)。

<h2 id="disabling-or-replacing-search">禁用或替换搜索</h2>

完全关闭框架的搜索功能：

```ts title="astro.config.ts"
nimbus({ /* … */, search: false });
```

或者保留 UI 但提供自定义后端（Algolia、托管服务等），只需实现 `SearchProvider` 接口并设置 `search: { provider: "custom" }`——Nimbus 会跳过 Pagefind 构建步骤，由你的代码来渲染搜索结果。

Source: https://nimbus-docs.cn/navigation/search/index.mdx
