Skip to content
pg_jieba

pg_jieba

pg_jieba : Chinese full-text search parser based on cppjieba

Overview

ID Extension Package Version Category License Language
2240
pg_jieba
pg_jieba
1.1.0
FTS
BSD-3-Clause
C++
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
See Also
pg_cjk_parser
zhparser
pg_bigm
pgroonga
pg_tokenizer

Package 2.0.1 ships extension version 1.1.0, vendors cppjieba commit 45809955, and fixes the LexDescr terminator allocation.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
PIGSTY
1.1.0
18
17
16
15
14
pg_jieba -
RPM
PIGSTY
2.0.1
18
17
16
15
14
pg_jieba_$v -
DEB
PIGSTY
2.0.1
18
17
16
15
14
postgresql-$v-pg-jieba -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
el8.aarch64
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
el9.x86_64
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
el9.aarch64
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
el10.x86_64
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
el10.aarch64
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
d12.x86_64
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
d12.aarch64
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
d13.x86_64
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
d13.aarch64
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
u22.x86_64
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
u22.aarch64
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
u24.x86_64
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
u24.aarch64
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
u26.x86_64
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
u26.aarch64
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
Package Version OS ORG SIZE File URL
pg_jieba_18 2.0.1 el8.x86_64 pigsty 3.7 MiB pg_jieba_18-2.0.1-1PIGSTY.el8.x86_64.rpm
pg_jieba_18 2.0.1 el8.aarch64 pigsty 3.7 MiB pg_jieba_18-2.0.1-1PIGSTY.el8.aarch64.rpm
pg_jieba_18 2.0.1 el9.x86_64 pigsty 3.1 MiB pg_jieba_18-2.0.1-1PIGSTY.el9.x86_64.rpm
pg_jieba_18 2.0.1 el9.aarch64 pigsty 3.1 MiB pg_jieba_18-2.0.1-1PIGSTY.el9.aarch64.rpm
pg_jieba_18 2.0.1 el10.x86_64 pigsty 3.2 MiB pg_jieba_18-2.0.1-1PIGSTY.el10.x86_64.rpm
pg_jieba_18 2.0.1 el10.aarch64 pigsty 3.1 MiB pg_jieba_18-2.0.1-1PIGSTY.el10.aarch64.rpm
postgresql-18-pg-jieba 2.0.1 d12.x86_64 pigsty 3.0 MiB postgresql-18-pg-jieba_2.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-jieba 2.0.1 d12.aarch64 pigsty 3.0 MiB postgresql-18-pg-jieba_2.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-jieba 2.0.1 d13.x86_64 pigsty 3.0 MiB postgresql-18-pg-jieba_2.0.1-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-jieba 2.0.1 d13.aarch64 pigsty 3.0 MiB postgresql-18-pg-jieba_2.0.1-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-jieba 2.0.1 u22.x86_64 pigsty 3.1 MiB postgresql-18-pg-jieba_2.0.1-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-jieba 2.0.1 u22.aarch64 pigsty 3.1 MiB postgresql-18-pg-jieba_2.0.1-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-jieba 2.0.1 u24.x86_64 pigsty 3.1 MiB postgresql-18-pg-jieba_2.0.1-1PIGSTY~noble_amd64.deb
postgresql-18-pg-jieba 2.0.1 u24.aarch64 pigsty 3.1 MiB postgresql-18-pg-jieba_2.0.1-1PIGSTY~noble_arm64.deb
postgresql-18-pg-jieba 2.0.1 u26.x86_64 pigsty 3.1 MiB postgresql-18-pg-jieba_2.0.1-1PIGSTY~resolute_amd64.deb
postgresql-18-pg-jieba 2.0.1 u26.aarch64 pigsty 3.1 MiB postgresql-18-pg-jieba_2.0.1-1PIGSTY~resolute_arm64.deb

Source

pig build pkg pg_jieba;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

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

Install this extension with pig:

pig install pg_jieba;		# install via package name, for the active PG version

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
pig install pg_jieba -v 14;   # install for PG 14

Create this extension with:

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 using jieba and jieba_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 cppjieba dependency.
  • 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 tsvector values and rebuild dependent indexes when dictionary output changes.
Last updated on