跳转到主要内容

pg_jieba

基于 cppjieba 的中文全文检索分词器

pg_jieba · 基于 cppjieba 的中文全文检索分词器

概览

ID扩展软件包版本类别许可证编程语言
2250pg_jiebapg_jieba1.1.0FTSBSD-3-ClauseC++
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--s-d-r否是否是是否
Package 2.0.1 ships extension version 1.1.0, vendors cppjieba commit 45809955, and fixes the LexDescr terminator allocation.

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY1.1.019 18 17 16 15pg_jieba-
RPMPIGSTY2.0.119 18 17 16 15pg_jieba_$v-
DEBPIGSTY2.0.119 18 17 16 15postgresql-$v-pg-jieba-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1
el8.aarch64N/APIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1
el9.x86_64PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1
el9.aarch64PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1
el10.x86_64PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1
el10.aarch64PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1
d12.x86_64PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1
d12.aarch64PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1
d13.x86_64PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1
d13.aarch64PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1
u22.x86_64PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1
u22.aarch64PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1
u24.x86_64PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1
u24.aarch64PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1
u26.x86_64PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1
u26.aarch64PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1PIGSTY 2.0.1
软件包版本平台仓库大小下载
pg_jieba_182.0.1el8.x86_64pigsty3.7 MiBpg_jieba_18-2.0.1-2PGSTY.el8.x86_64.rpm
pg_jieba_182.0.1el8.aarch64pigsty3.7 MiBpg_jieba_18-2.0.1-2PGSTY.el8.aarch64.rpm
pg_jieba_182.0.1el9.x86_64pigsty3.1 MiBpg_jieba_18-2.0.1-2PGSTY.el9.x86_64.rpm
pg_jieba_182.0.1el9.aarch64pigsty3.1 MiBpg_jieba_18-2.0.1-2PGSTY.el9.aarch64.rpm
pg_jieba_182.0.1el10.x86_64pigsty3.2 MiBpg_jieba_18-2.0.1-2PGSTY.el10.x86_64.rpm
pg_jieba_182.0.1el10.aarch64pigsty3.1 MiBpg_jieba_18-2.0.1-2PGSTY.el10.aarch64.rpm
postgresql-18-pg-jieba2.0.1d12.x86_64pigsty3.0 MiBpostgresql-18-pg-jieba_2.0.1-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-jieba2.0.1d12.aarch64pigsty3.0 MiBpostgresql-18-pg-jieba_2.0.1-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-jieba2.0.1d13.x86_64pigsty3.0 MiBpostgresql-18-pg-jieba_2.0.1-1PGSTY~trixie_amd64.deb
postgresql-18-pg-jieba2.0.1d13.aarch64pigsty3.0 MiBpostgresql-18-pg-jieba_2.0.1-1PGSTY~trixie_arm64.deb
postgresql-18-pg-jieba2.0.1u22.x86_64pigsty3.1 MiBpostgresql-18-pg-jieba_2.0.1-1PGSTY~jammy_amd64.deb
postgresql-18-pg-jieba2.0.1u22.aarch64pigsty3.1 MiBpostgresql-18-pg-jieba_2.0.1-1PGSTY~jammy_arm64.deb
postgresql-18-pg-jieba2.0.1u24.x86_64pigsty3.1 MiBpostgresql-18-pg-jieba_2.0.1-1PGSTY~noble_amd64.deb
postgresql-18-pg-jieba2.0.1u24.aarch64pigsty3.1 MiBpostgresql-18-pg-jieba_2.0.1-1PGSTY~noble_arm64.deb
postgresql-18-pg-jieba2.0.1u26.x86_64pigsty3.1 MiBpostgresql-18-pg-jieba_2.0.1-1PGSTY~resolute_amd64.deb
postgresql-18-pg-jieba2.0.1u26.aarch64pigsty3.1 MiBpostgresql-18-pg-jieba_2.0.1-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_jieba_172.0.1el8.x86_64pigsty3.7 MiBpg_jieba_17-2.0.1-2PGSTY.el8.x86_64.rpm
pg_jieba_172.0.1el8.aarch64pigsty3.7 MiBpg_jieba_17-2.0.1-2PGSTY.el8.aarch64.rpm
pg_jieba_172.0.1el9.x86_64pigsty3.1 MiBpg_jieba_17-2.0.1-2PGSTY.el9.x86_64.rpm
pg_jieba_172.0.1el9.aarch64pigsty3.1 MiBpg_jieba_17-2.0.1-2PGSTY.el9.aarch64.rpm
pg_jieba_172.0.1el10.x86_64pigsty3.2 MiBpg_jieba_17-2.0.1-2PGSTY.el10.x86_64.rpm
pg_jieba_172.0.1el10.aarch64pigsty3.1 MiBpg_jieba_17-2.0.1-2PGSTY.el10.aarch64.rpm
postgresql-17-pg-jieba2.0.1d12.x86_64pigsty3.0 MiBpostgresql-17-pg-jieba_2.0.1-1PGSTY~bookworm_amd64.deb
postgresql-17-pg-jieba2.0.1d12.aarch64pigsty3.0 MiBpostgresql-17-pg-jieba_2.0.1-1PGSTY~bookworm_arm64.deb
postgresql-17-pg-jieba2.0.1d13.x86_64pigsty3.0 MiBpostgresql-17-pg-jieba_2.0.1-1PGSTY~trixie_amd64.deb
postgresql-17-pg-jieba2.0.1d13.aarch64pigsty3.0 MiBpostgresql-17-pg-jieba_2.0.1-1PGSTY~trixie_arm64.deb
postgresql-17-pg-jieba2.0.1u22.x86_64pigsty3.1 MiBpostgresql-17-pg-jieba_2.0.1-1PGSTY~jammy_amd64.deb
postgresql-17-pg-jieba2.0.1u22.aarch64pigsty3.1 MiBpostgresql-17-pg-jieba_2.0.1-1PGSTY~jammy_arm64.deb
postgresql-17-pg-jieba2.0.1u24.x86_64pigsty3.1 MiBpostgresql-17-pg-jieba_2.0.1-1PGSTY~noble_amd64.deb
postgresql-17-pg-jieba2.0.1u24.aarch64pigsty3.1 MiBpostgresql-17-pg-jieba_2.0.1-1PGSTY~noble_arm64.deb
postgresql-17-pg-jieba2.0.1u26.x86_64pigsty3.1 MiBpostgresql-17-pg-jieba_2.0.1-1PGSTY~resolute_amd64.deb
postgresql-17-pg-jieba2.0.1u26.aarch64pigsty3.1 MiBpostgresql-17-pg-jieba_2.0.1-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_jieba_162.0.1el8.x86_64pigsty3.7 MiBpg_jieba_16-2.0.1-2PGSTY.el8.x86_64.rpm
pg_jieba_162.0.1el8.aarch64pigsty3.7 MiBpg_jieba_16-2.0.1-2PGSTY.el8.aarch64.rpm
pg_jieba_162.0.1el9.x86_64pigsty3.1 MiBpg_jieba_16-2.0.1-2PGSTY.el9.x86_64.rpm
pg_jieba_162.0.1el9.aarch64pigsty3.1 MiBpg_jieba_16-2.0.1-2PGSTY.el9.aarch64.rpm
pg_jieba_162.0.1el10.x86_64pigsty3.2 MiBpg_jieba_16-2.0.1-2PGSTY.el10.x86_64.rpm
pg_jieba_162.0.1el10.aarch64pigsty3.1 MiBpg_jieba_16-2.0.1-2PGSTY.el10.aarch64.rpm
postgresql-16-pg-jieba2.0.1d12.x86_64pigsty3.0 MiBpostgresql-16-pg-jieba_2.0.1-1PGSTY~bookworm_amd64.deb
postgresql-16-pg-jieba2.0.1d12.aarch64pigsty3.0 MiBpostgresql-16-pg-jieba_2.0.1-1PGSTY~bookworm_arm64.deb
postgresql-16-pg-jieba2.0.1d13.x86_64pigsty3.0 MiBpostgresql-16-pg-jieba_2.0.1-1PGSTY~trixie_amd64.deb
postgresql-16-pg-jieba2.0.1d13.aarch64pigsty3.0 MiBpostgresql-16-pg-jieba_2.0.1-1PGSTY~trixie_arm64.deb
postgresql-16-pg-jieba2.0.1u22.x86_64pigsty3.1 MiBpostgresql-16-pg-jieba_2.0.1-1PGSTY~jammy_amd64.deb
postgresql-16-pg-jieba2.0.1u22.aarch64pigsty3.1 MiBpostgresql-16-pg-jieba_2.0.1-1PGSTY~jammy_arm64.deb
postgresql-16-pg-jieba2.0.1u24.x86_64pigsty3.1 MiBpostgresql-16-pg-jieba_2.0.1-1PGSTY~noble_amd64.deb
postgresql-16-pg-jieba2.0.1u24.aarch64pigsty3.1 MiBpostgresql-16-pg-jieba_2.0.1-1PGSTY~noble_arm64.deb
postgresql-16-pg-jieba2.0.1u26.x86_64pigsty3.1 MiBpostgresql-16-pg-jieba_2.0.1-1PGSTY~resolute_amd64.deb
postgresql-16-pg-jieba2.0.1u26.aarch64pigsty3.1 MiBpostgresql-16-pg-jieba_2.0.1-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_jieba_152.0.1el8.x86_64pigsty3.7 MiBpg_jieba_15-2.0.1-2PGSTY.el8.x86_64.rpm
pg_jieba_152.0.1el8.aarch64pigsty3.7 MiBpg_jieba_15-2.0.1-2PGSTY.el8.aarch64.rpm
pg_jieba_152.0.1el9.x86_64pigsty3.1 MiBpg_jieba_15-2.0.1-2PGSTY.el9.x86_64.rpm
pg_jieba_152.0.1el9.aarch64pigsty3.1 MiBpg_jieba_15-2.0.1-2PGSTY.el9.aarch64.rpm
pg_jieba_152.0.1el10.x86_64pigsty3.2 MiBpg_jieba_15-2.0.1-2PGSTY.el10.x86_64.rpm
pg_jieba_152.0.1el10.aarch64pigsty3.1 MiBpg_jieba_15-2.0.1-2PGSTY.el10.aarch64.rpm
postgresql-15-pg-jieba2.0.1d12.x86_64pigsty3.0 MiBpostgresql-15-pg-jieba_2.0.1-1PGSTY~bookworm_amd64.deb
postgresql-15-pg-jieba2.0.1d12.aarch64pigsty3.0 MiBpostgresql-15-pg-jieba_2.0.1-1PGSTY~bookworm_arm64.deb
postgresql-15-pg-jieba2.0.1d13.x86_64pigsty3.0 MiBpostgresql-15-pg-jieba_2.0.1-1PGSTY~trixie_amd64.deb
postgresql-15-pg-jieba2.0.1d13.aarch64pigsty3.0 MiBpostgresql-15-pg-jieba_2.0.1-1PGSTY~trixie_arm64.deb
postgresql-15-pg-jieba2.0.1u22.x86_64pigsty3.1 MiBpostgresql-15-pg-jieba_2.0.1-1PGSTY~jammy_amd64.deb
postgresql-15-pg-jieba2.0.1u22.aarch64pigsty3.1 MiBpostgresql-15-pg-jieba_2.0.1-1PGSTY~jammy_arm64.deb
postgresql-15-pg-jieba2.0.1u24.x86_64pigsty3.1 MiBpostgresql-15-pg-jieba_2.0.1-1PGSTY~noble_amd64.deb
postgresql-15-pg-jieba2.0.1u24.aarch64pigsty3.1 MiBpostgresql-15-pg-jieba_2.0.1-1PGSTY~noble_arm64.deb
postgresql-15-pg-jieba2.0.1u26.x86_64pigsty3.1 MiBpostgresql-15-pg-jieba_2.0.1-1PGSTY~resolute_amd64.deb
postgresql-15-pg-jieba2.0.1u26.aarch64pigsty3.1 MiBpostgresql-15-pg-jieba_2.0.1-1PGSTY~resolute_arm64.deb

源码

pig build pkg pg_jieba;		# build rpm/deb

安装

启用 PGDG 和 PIGSTY 仓库并更新缓存。

pig repo add pgsql -u   # add both repo and update cache

使用 pig 安装扩展。

pig install pg_jieba;		# install by package name

pig install pg_jieba -v 19;   # install for PG 19
pig install pg_jieba -v 18;   # install for PG 18
pig install pg_jieba -v 17;   # install for PG 17
pig install pg_jieba -v 16;   # install for PG 16
pig install pg_jieba -v 15;   # install for PG 15

在数据库中创建扩展。

CREATE EXTENSION pg_jieba;

用法

来源:

pg_jieba 将基于 Jieba 的中文分词功能添加到 PostgreSQL 全文搜索中。上游的 v2.0.1 源代码发布安装了 SQL 扩展版本 1.1.0,其控制文件记录了这一点。它提供了独立的文档和查询解析器以及现成可用的文字搜索配置。

核心工作流程

CREATE EXTENSION pg_jieba;

SELECT to_tsvector(
    'jiebacfg',
    '小明硕士毕业于中国科学院计算所,后在日本京都大学深造'
);

SELECT plainto_tsquery('jiebaqry', '云计算专家');

使用 jiebacfg 构建可搜索的文档向量,并使用 jiebaqry 分段用户查询:

ALTER TABLE articles
ADD COLUMN search_vector tsvector
GENERATED ALWAYS AS (to_tsvector('jiebacfg', body)) STORED;

CREATE INDEX articles_search_idx
ON articles USING GIN (search_vector);

SELECT title
FROM articles
WHERE search_vector @@ plainto_tsquery('jiebaqry', '中文全文检索');

对象索引

  • jieba: 文档文本搜索解析器。
  • jiebaqry: 查询导向的文字搜索解析器。
  • jiebacfg: 使用 jieba 和 jieba_stem 的文档文字搜索配置。
  • jiebaqry: 同名的查询解析器文字搜索配置。
  • jieba_stem: 包含 Jieba 停用词的简单字典,用于解析器的标记类别。

自定义词典和注意事项

上游从 PostgreSQL 的 jieba.user.dict.utf8 目录读取一个名为 tsearch_data 的自定义词典。条目可能包含一个单词及其可选的词性标签:

云计算
韩玉鉴赏
蓝翔 nz
  • v2.x 源代码需要 C++11 兼容编译器,因为其捆绑了 cppjieba 依赖。
  • 上游发布的兼容性测试已过时且有限。针对生产中使用的具体 PostgreSQL 主版本构建和回归测试该包。
  • 更改词典会改变分词结果。当字典输出变化时,请重新计算存储的 tsvector 值并重建相关索引。

表格阅读器