@byline/search-mysql

中文文档
6.13.3发布于 2026/11/09MPL-2.0TypeScriptESM + CJS近 30 天下载 1771

Byline CMS built-in MySQL full-text search provider

原始使用文档
文档目录5 节
  1. Install
  2. Register
  3. Schema and migrations
  4. Capabilities
  5. Language and locale

@byline/search-mysql

The built-in MySQL full-text SearchProvider for Byline CMS. It combines the portable multilingual analyzer from @byline/search-analysis with weighted MySQL FULLTEXT indexes, providing ranked search with no additional service and reusing the existing MySQL connection pool.

It stores one row per (collection_path, document_id, locale). Searchable logical terms are encoded into parser-safe ASCII tokens before MySQL sees them, which preserves Byline's normalization, identifier, expansion, and Han-gram semantics without depending on server stopword lists or minimum token lengths. Four physical indexes retain the A–D field-weight classes used by the built-in PostgreSQL provider.

See docs/06-search/06-postgres-and-mysql.md for the built-in provider comparison and operational reference.

Install

pnpm add @byline/search-mysql

mysql2 is a peer dependency. An installation using @byline/db-mysql already has it.

Register

The provider reuses the host's existing promise pool (db.pool from mysqlAdapter), so the index lives in the same database:

import { defineServerConfig } from '@byline/core'
import { mysqlAdapter } from '@byline/db-mysql'
import { mysqlSearch } from '@byline/search-mysql'

const db = mysqlAdapter({ connectionString, collections, defaultContentLocale })

defineServerConfig({
  db,
  search: mysqlSearch({ pool: db.pool }),
  // …
})

A collection opts into indexing through its search config ({ body, facets, filters, zones }). initBylineCore() fails fast if a collection opts in but no provider is registered.

Schema and migrations

This driver owns a disposable search projection. Its numbered SQL files under migrations/ are independent of the host database adapter's Drizzle migrations and are tracked in byline_search_migrations.

For production, apply pending migrations deliberately before serving traffic:

import { migrate } from '@byline/search-mysql'

const { applied } = await migrate(db.pool, { log: (message) => logger.info(message) })

MySQL auto-commits DDL. The migrator therefore uses a server advisory lock, idempotent DDL, and records a version only after every statement succeeds. Migration files must contain ordinary semicolon-delimited statements, not stored routines with internal delimiters.

For local development, mysqlSearch({ pool: db.pool, autoMigrate: true }) starts migration in the background. Prefer an explicit awaited migrate() call whenever deterministic startup matters.

There is no compatibility migration for earlier experimental schemas. Drop only the search-owned tables, apply 0001_init.sql, and rebuild searchable collections from their published versions:

DROP TABLE IF EXISTS byline_search_index_metadata;
DROP TABLE IF EXISTS byline_search_documents;
DROP TABLE IF EXISTS byline_search_migrations;

Capabilities

The adapter supports portable analysis, all and any matching, minimum-should-match, phrase constraints, field weighting, and highlighted snippets built from stored original body text with the shared portable token offsets. Facet data and typed filters are retained in JSON for future query features.

Facet aggregation, structured filtering, typo tolerance, semantic retrieval, and BM25 are currently reported as unsupported. MySQL's native relevance score contributes term frequency and inverse document frequency, but the provider does not claim BM25 because MySQL does not expose a stable BM25 contract.

Language and locale

The portable analyzer applies Unicode normalization, ICU word segmentation, identifier preservation, optional language expanders, and Han bigrams before the adapter writes physical terms. defaultLocale supplies the fallback when content or a query does not declare a usable locale:

mysqlSearch({ pool: db.pool, defaultLocale: 'en' })

Custom analyzers must have stable, versioned fingerprints. The provider stores the fingerprint per collection and rejects mixed analysis pipelines. Clear and reindex an affected collection after changing its analyzer.

版本与发布记录

@byline/search-mysql 共发布 49 个版本,首次发布于 2026/07/27;过去 12 个月发布了 49 个版本。

版本发布日期距今
6.13.3latest2026/11/09今天
6.13.22026/11/09今天
6.13.12026/11/09今天
6.13.02026/11/045 天前
6.12.12026/11/027 天前
6.12.02026/10/319 天前

关于 @byline/search-mysql 的常见问题

@byline/search-mysql 是什么?

Byline CMS built-in MySQL full-text search provider

如何安装 @byline/search-mysql?

在项目目录运行 npm install @byline/search-mysql,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:mysql2(^3.23.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@byline/search-mysql 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@byline/search-mysql 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@byline/search-mysql 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.22.2。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@byline/search-mysql 可以商用吗?

@byline/search-mysql 使用 MPL-2.0 许可。弱 Copyleft:可以商用,也可以和闭源代码一起使用;但如果分发时修改了 MPL 授权的文件,这些文件的修改需以 MPL 开源。以上为概括,不构成法律意见,请以许可原文为准。

@byline/search-mysql 的下载量有多少?

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

@byline/search-mysql 还在维护吗?

最新版本 6.13.3 发布于 2026/11/09(今天);至今共发布 49 个版本,其中过去 12 个月发布了 49 个;首次发布于 2026/07/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。