pg_jieba
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_jieba | 1.1.0 | FTS | BSD-3-Clause | C++ |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 2240 | pg_jieba | No | Yes | No | Yes | No | Yes | - |
| Related | pg_cjk_parser pgroonga pg_tokenizer zhparser pg_bigm pg_pinyin pg_tiktoken pg_tiktoken_c unaccent dict_xsyn |
|---|
Package 2.0.1 ships extension version 1.1.0, vendors cppjieba commit 45809955, and fixes the LexDescr terminator allocation.
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.1.0 | 1817161514 | pg_jieba | - |
| RPM | PIGSTY | 2.0.1 | 1817161514 | pg_jieba_$v | - |
| DEB | PIGSTY | 2.0.1 | 1817161514 | postgresql-$v-pg-jieba | - |
Build
You can build the RPM / DEB packages for pg_jieba using pig build:
pig build pkg pg_jieba # build RPM / DEB packages
Install
You can install pg_jieba directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
pig repo add pgsql -u # Add repo and update cache
Install the extension using pig or apt/yum/dnf:
pig install pg_jieba; # Install for current active PG version
pig ext install -y pg_jieba -v 18 # PG 18
pig ext install -y pg_jieba -v 17 # PG 17
pig ext install -y pg_jieba -v 16 # PG 16
pig ext install -y pg_jieba -v 15 # PG 15
pig ext install -y pg_jieba -v 14 # PG 14
dnf install -y pg_jieba_18 # PG 18
dnf install -y pg_jieba_17 # PG 17
dnf install -y pg_jieba_16 # PG 16
dnf install -y pg_jieba_15 # PG 15
dnf install -y pg_jieba_14 # PG 14
apt install -y postgresql-18-pg-jieba # PG 18
apt install -y postgresql-17-pg-jieba # PG 17
apt install -y postgresql-16-pg-jieba # PG 16
apt install -y postgresql-15-pg-jieba # PG 15
apt install -y postgresql-14-pg-jieba # PG 14
Create Extension:
CREATE EXTENSION pg_jieba;
Usage
Sources:
pg_jieba adds Jieba-based Chinese word segmentation to PostgreSQL full-text search. The upstream v2.0.1 source release installs SQL extension version 1.1.0, as recorded by its control file. It provides separate document and query parsers plus ready-to-use text-search configurations.
Core Workflow
CREATE EXTENSION pg_jieba;
SELECT to_tsvector(
'jiebacfg',
'小明硕士毕业于中国科学院计算所,后在日本京都大学深造'
);
SELECT plainto_tsquery('jiebaqry', '云计算专家');
Use jiebacfg to build searchable document vectors and jiebaqry to segment user queries:
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', '中文全文检索');
Object Index
jieba: document text-search parser.jiebaqry: query-oriented text-search parser.jiebacfg: document text-search configuration usingjiebaandjieba_stem.jiebaqry: text-search configuration of the same name using the query parser.jieba_stem: simple dictionary with Jieba stop words used for the parser’s token categories.
Custom Dictionary and Caveats
Upstream reads a custom dictionary named jieba.user.dict.utf8 from PostgreSQL’s tsearch_data directory. Entries may contain a word and optional part-of-speech tag:
云计算
韩玉鉴赏
蓝翔 nz
- The v2.x source requires a C++11-capable compiler because of its bundled
cppjiebadependency. - Upstream’s published compatibility testing is old and limited. Build and regression-test the package against the exact PostgreSQL major version used in production.
- Changing dictionaries changes tokenization. Recompute stored
tsvectorvalues and rebuild dependent indexes when dictionary output changes.
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.