跳转到主要内容

pg_icu_parser

使用 ICU 边界分析的全文搜索解析器

概览

扩展包名版本分类许可证语言
pg_icu_parser1.0FTSMPL-2.0C
ID扩展名BinLibLoadCreateTrustReloc模式
2300pg_icu_parser否是否是否是-

SQL/control version 1.0; upstream release 1.0.0. Local RPM/DEB builds support PG14-18 with a PG18 encoding-API compatibility patch and explicit ICU linkage. ts_headline is unsupported. PIGSTY PG14-18 packages verified across EL8/9/10, Debian 12/13 and Ubuntu 22.04/24.04/26.04 on x86_64/amd64 and aarch64/arm64; all 16 platforms imported into the local PIGSTY repository.

版本

类型仓库版本PG 大版本包名依赖
EXTPIGSTY1.01817161514pg_icu_parser-
RPMPIGSTY1.0.01817161514pg_icu_parser_$v-
DEBPIGSTY1.0.01817161514postgresql-$v-pg-icu-parser-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
el9.x86_64
el9.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
el10.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
el10.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
d12.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
d12.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
d13.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
d13.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
u22.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
u22.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
u24.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
u24.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
u26.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
u26.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0

构建

您可以使用 pig build 命令构建 pg_icu_parser 扩展的 RPM / DEB 包:

pig build pkg pg_icu_parser         # 构建 RPM / DEB 包

安装

您可以直接安装 pg_icu_parser 扩展包的预置二进制包,首先确保 PGDG 和 PIGSTY 仓库已经添加并启用:

pig repo add pgsql -u          # 添加仓库并更新缓存

使用 pig 或者是 apt/yum/dnf 安装扩展:

安装
pig install pg_icu_parser;          # 当前活跃 PG 版本安装
pig
pig ext install -y pg_icu_parser -v 18  # PG 18
pig ext install -y pg_icu_parser -v 17  # PG 17
pig ext install -y pg_icu_parser -v 16  # PG 16
pig ext install -y pg_icu_parser -v 15  # PG 15
pig ext install -y pg_icu_parser -v 14  # PG 14
dnf
dnf install -y pg_icu_parser_18       # PG 18
dnf install -y pg_icu_parser_17       # PG 17
dnf install -y pg_icu_parser_16       # PG 16
dnf install -y pg_icu_parser_15       # PG 15
dnf install -y pg_icu_parser_14       # PG 14
apt
apt install -y postgresql-18-pg-icu-parser   # PG 18
apt install -y postgresql-17-pg-icu-parser   # PG 17
apt install -y postgresql-16-pg-icu-parser   # PG 16
apt install -y postgresql-15-pg-icu-parser   # PG 15
apt install -y postgresql-14-pg-icu-parser   # PG 14

创建扩展:

CREATE EXTENSION pg_icu_parser;

用法

来源:

pg_icu_parser 提供采用 ICU Unicode 单词边界分析的 icu_parser 全文搜索解析器。它适用于中文、日文、韩文和希伯来文等语言,因为 PostgreSQL 默认解析器以空白和模式为中心,可能无法产生合适的单词边界。

核心流程

服务器必须是 PostgreSQL 10 或更高版本,并且构建时已经启用 ICU。创建扩展后,建立使用该解析器的文本搜索配置,再映射所需的词元类型:

CREATE EXTENSION pg_icu_parser;

CREATE TEXT SEARCH CONFIGURATION sample (PARSER = icu_parser);
ALTER TEXT SEARCH CONFIGURATION sample
  ADD MAPPING FOR word WITH english_stem;
ALTER TEXT SEARCH CONFIGURATION sample
  ADD MAPPING FOR number, ideo, kana WITH simple;

SELECT to_tsvector('sample', '東京でPostgreSQLを使う');

应为实际语言选择词典;上面的 english_stem 只用于演示映射语法。

解析器接口

  • word、number、kana、ideo 和 blank 是 icu_parser 输出的词元类型。
  • pg_icu_parser.locale 选择 ICU locale,默认值为 en。上游指出单词边界规则通常不依赖 locale,因此只有在验证了具体需求后才应修改。
  • 任意 PostgreSQL 文本搜索词典都可以映射到这些输出词元类型。

取舍

  • 解析器要求 PostgreSQL 构建已经包含 ICU;创建扩展无法为未启用 ICU 的服务器补上该能力。
  • 与默认解析器相比,它输出的词元类型更少、更粗,也不会把 URL、电子邮件等特殊模式识别为独立类别。
  • 当前审阅的版本不支持 ts_headline。
  • 上游报告其速度慢于默认解析器,而数据库编码为 UTF-8 时转换开销会较低。应在目标系统上用有代表性的文档和查询形态进行基准测试。
  • 修改解析器映射或 locale 行为后,应重建已存储的 tsvector 值和依赖索引,避免新旧行采用不同分词规则。

这个页面对您有帮助吗?