# @cmfcmf/docusaurus-search-local 中文文档

规范地址：https://npmcn.com/package/%40cmfcmf/docusaurus-search-local/

版本：2\.0\.1
npm 元数据更新时间：2025-10-25T18:54:03.858Z
中文译文更新时间：2026-11-10T04:06:09.643Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40cmfcmf/docusaurus-search-local
原文对照：https://npmcn.com/package/%40cmfcmf/docusaurus-search-local/?lang=original
项目主页：https://github.com/cmfcmf/docusaurus-search-local#readme
源码仓库：https://github.com/cmfcmf/docusaurus-search-local

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：344 kB，74 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：9 个
- peer 依赖：@docusaurus/core ^3\.0\.0，nodejieba ^2\.5\.0 \|\| ^3\.0\.0，react ^18 \|\| ^19，react-dom ^18 \|\| ^19
- 首次发布：2020-01-15T20:40:58.931Z
- 最新版本发布：2025-10-25T18:54:03.425Z
- 近 30 天下载量：140045（2026-10-10 至 2026-11-08，npm 官方下载统计）
- 已发布版本数：36（近 12 个月 0 个）

## 中文简介

本地 / 离线搜索 Docusaurus

## 安装

```sh
npm install @cmfcmf/docusaurus-search-local
```

也可以使用：`pnpm add @cmfcmf/docusaurus-search-local`、`yarn add @cmfcmf/docusaurus-search-local`、`bun add @cmfcmf/docusaurus-search-local`

## README

# 下行 / 本地搜索 docusaurus v3+

[![Version](https://img.shields.io/npm/v/@cmfcmf/docusaurus-search-local?style=flat-square)](https://www.npmjs.com/package/@cmfcmf/docusaurus-search-local) [![License](https://img.shields.io/npm/l/@cmfcmf/docusaurus-search-local?style=flat-square)](https://github.com/cmfcmf/docusaurus-search-local/blob/main/LICENSE) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) [![GitHub issues](https://img.shields.io/github/issues/cmfcmf/docusaurus-search-local?style=flat-square)](https://github.com/cmfcmf/docusaurus-search-local/issues) [![GitHub last commit](https://img.shields.io/github/last-commit/cmfcmf/docusaurus-search-local?style=flat-square)](https://github.com/cmfcmf/docusaurus-search-local/commits)

离线/ 本地搜索 Docusaurus **3+ 时间轴** 在防火墙后面工作.

特性要领 :

-   支持多个文档版本
-   支持以英文以外的语文编写的文件
-   突出显示搜索结果
-   文件、博客和一般页面的自定义解析器
-   懒惰地装入索引

![Search in Action](https://npmcn.com/package/%40cmfcmf/docusaurus-search-local/docs/preview.gif)

> 注:我们使用开源 [阿尔戈利亚/自动完成](https://github.com/algolia/autocomplete) 用于搜索框的库. 这个图书馆只是用作前端,和, 不同于默认 Docusaurus 搜索体验([阿尔戈利亚/搜索](https://docsearch.algolia.com/), (中文(简体) ), **没有连接到任何 Algolia 或第三方服务器**。 。 。 .

## 安装

```bash
npm install @cmfcmf/docusaurus-search-local
```

或者说

```bash
yarn add @cmfcmf/docusaurus-search-local
```

## 使用量

将此插件添加到 `plugins` 阵列 `docusaurus.config.js`。 。 。 .

```js
const config = {
  // ...
  plugins: ["@cmfcmf/docusaurus-search-local"],

  // or, if you want to specify options:

  // ...
  plugins: [
    [
      "@cmfcmf/docusaurus-search-local",
      {
        // Options here
      },
    ],
  ],
};

export default config;
```

以下选项可供选择(默认情况如下):

```js
{
  // whether to index docs pages
  indexDocs: true,

  // Whether to also index the titles of the parent categories in the sidebar of a doc page.
  // 0 disables this feature.
  // 1 indexes the direct parent category in the sidebar of a doc page
  // 2 indexes up to two nested parent categories of a doc page
  // 3...
  //
  // Do _not_ use Infinity, the value must be a JSON-serializable integer.
  indexDocSidebarParentCategories: 0,

  // Includes parent categories path in search result
  includeParentCategoriesInPageTitle: false,

  // whether to index blog pages
  indexBlog: true,

  // whether to index static pages
  // /404.html is never indexed
  indexPages: false,

  // language of your documentation, see next section
  language: "en",

  // setting this to "none" will prevent the default CSS to be included. The default CSS
  // comes from autocomplete-theme-classic, which you can read more about here:
  // https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-theme-classic/
  // When you want to overwrite CSS variables defined by the default theme, make sure to suffix your
  // overwrites with `!important`, because they might otherwise not be applied as expected. See the
  // following comment for more information: https://github.com/cmfcmf/docusaurus-search-local/issues/107#issuecomment-1119831938.
  style: undefined,

  // The maximum number of search results shown to the user. This does _not_ affect performance of
  // searches, but simply does not display additional search results that have been found.
  maxSearchResults: 8,

  // lunr.js-specific settings
  lunr: {
    // When indexing your documents, their content is split into "tokens".
    // Text entered into the search box is also tokenized.
    // This setting configures the separator used to determine where to split the text into tokens.
    // By default, it splits the text at whitespace and dashes.
    //
    // Note: Does not work for "ja" and "th" languages, since these use a different tokenizer.
    tokenizerSeparator: /[\s\-]+/,
    // https://lunrjs.com/guides/customising.html#similarity-tuning
    //
    // This parameter controls the importance given to the length of a document and its fields. This
    // value must be between 0 and 1, and by default it has a value of 0.75. Reducing this value
    // reduces the effect of different length documents on a term’s importance to that document.
    b: 0.75,
    // This controls how quickly the boost given by a common word reaches saturation. Increasing it
    // will slow down the rate of saturation and lower values result in quicker saturation. The
    // default value is 1.2. If the collection of documents being indexed have high occurrences
    // of words that are not covered by a stop word filter, these words can quickly dominate any
    // similarity calculation. In these cases, this value can be reduced to get more balanced results.
    k1: 1.2,
    // By default, we rank pages where the search term appears in the title higher than pages where
    // the search term appears in just the text. This is done by "boosting" title matches with a
    // higher value than content matches. The concrete boosting behavior can be controlled by changing
    // the following settings.
    titleBoost: 5,
    contentBoost: 1,
    tagsBoost: 3,
    parentCategoriesBoost: 2, // Only used when indexDocSidebarParentCategories > 0
  }
}
```

您现在可以使用搜索栏搜索您的文档 .

**重要: 只搜索静态构建的文档( 即您运行后) `npm run docusaurus build` 文档文件夹中.**

**搜索确实 **没有** 发展工作(即运行时) `npm run docusaurus start`) (中文(简体) ).** 如果您想要测试本地搜索, 请先使用 `npm run docusaurus build`,然后通过 `npm run docusaurus serve`。 。 。 .

### 非英语文档

使用 `language` 选项,如果文档不是用英语编写的。 您可以指定一种单一语言或多种语言的数组. 现有语言如下:

```
ar, da, de, en, es, fi, fr, hi, hu, it, ja, nl, no, pt, ro, ru, sv, th, tr, vi, zh
```

**重要内容:中文支持(`zh`),您还必须安装 `nodejieba` npm 软件包在 `^2.5.0 || ^3.0.0`。 。 。 .**

### 文档版本

支持使用正式 Docusaurus Docs 插件创建的文档版本 . 搜索栏默认为最新版本( 不) `next`,但最新版本定义于 `versions.json`),当不是在文档页面上(例如,当查看博客帖或静态页面时). 如果用户访问一个文件页面,则从页面中取出该版本,只搜索该版本的文件. 搜索栏占位符文本总是反映当前检测到的文档版本.

### 国际化

此插件支持使用 [Docusaurus i18n (英语)](https://docusaurus.io/docs/i18n/introduction) 从盒子里出来. 请在 [代码翻译](https://npmcn.com/package/%40cmfcmf/docusaurus-search-local/packages/docusaurus-search-local/codeTranslations) 子文件夹并提交 PR.

您也可以通过 modifiing 来调整翻译 `<yourfolder>/i18n/<locale>/code.json` 开始 `cmfcmf/d-s-l.`。 。 。 . 更多信息: [https://docusaurus.io/docs/i18n/tutorial# translate-json-files (中文(简体) )](https://docusaurus.io/docs/i18n/tutorial#translate-json-files)

### 调试

如果构建文档时产生出错, 您可以以调试模式构建以解析 由哪一页引起。 要做到这一点,只需设置 `DEBUG` 建筑时的环境变量 文档 : `DEBUG=1 npm run docusaurus build`。 。 。 .

## 捐款

请看 [捐款额](https://npmcn.com/package/%40cmfcmf/docusaurus-search-local/CONTRIBUTING.md) 以备进一步资料.

## 许可证

麻省理工学院

## 常见问题

### @cmfcmf/docusaurus-search-local 是什么？

本地 / 离线搜索 Docusaurus

### 如何安装 @cmfcmf/docusaurus-search-local？

在项目目录运行 npm install @cmfcmf/docusaurus-search-local，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：@docusaurus/core（^3\.0\.0）、react（^18 \|\| ^19）、react-dom（^18 \|\| ^19）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @cmfcmf/docusaurus-search-local 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/cmfcmf\_\_docusaurus-search-local 是否存在。

### @cmfcmf/docusaurus-search-local 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @cmfcmf/docusaurus-search-local 可以商用吗？

@cmfcmf/docusaurus-search-local 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @cmfcmf/docusaurus-search-local 的下载量有多少？

根据 npm 官方下载统计，@cmfcmf/docusaurus-search-local 在 2026/10/10 – 2026/11/08 这 30 天内被下载 140,045 次，日均约 4,668 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @cmfcmf/docusaurus-search-local 还在维护吗？

最新版本 2\.0\.1 发布于 2025/10/26（1 年前）；至今共发布 36 个版本，其中过去 12 个月发布了 0 个；首次发布于 2020/01/16。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

