Skip to content
pg_cjk_parser

pg_cjk_parser

pg_cjk_parser : CJK bigram parser derived from PostgreSQL full-text search

Overview

ID Extension Package Version Category License Language
2230
pg_cjk_parser
pg_cjk_parser
0.1.0
FTS
PostgreSQL
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_jieba
zhparser
pg_bigm
pgroonga
pg_tokenizer

PGSTY applies a PG_CONFIG build-selection patch.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
PIGSTY
0.1.0
18
17
16
15
14
pg_cjk_parser -
RPM
PIGSTY
0.1.0
18
17
16
15
14
pg_cjk_parser_$v -
DEB
PIGSTY
0.1.0
18
17
16
15
14
postgresql-$v-pg-cjk-parser -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
el8.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
el9.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
el9.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
el10.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
el10.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
d12.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
d12.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
d13.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
d13.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
u22.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
u22.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
u24.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
u24.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
u26.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
u26.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
Package Version OS ORG SIZE File URL
pg_cjk_parser_18 0.1.0 el8.x86_64 pigsty 36.4 KiB pg_cjk_parser_18-0.1.0-1PIGSTY.el8.x86_64.rpm
pg_cjk_parser_18 0.1.0 el8.aarch64 pigsty 36.0 KiB pg_cjk_parser_18-0.1.0-1PIGSTY.el8.aarch64.rpm
pg_cjk_parser_18 0.1.0 el9.x86_64 pigsty 37.9 KiB pg_cjk_parser_18-0.1.0-1PIGSTY.el9.x86_64.rpm
pg_cjk_parser_18 0.1.0 el9.aarch64 pigsty 38.1 KiB pg_cjk_parser_18-0.1.0-1PIGSTY.el9.aarch64.rpm
pg_cjk_parser_18 0.1.0 el10.x86_64 pigsty 38.0 KiB pg_cjk_parser_18-0.1.0-1PIGSTY.el10.x86_64.rpm
pg_cjk_parser_18 0.1.0 el10.aarch64 pigsty 38.1 KiB pg_cjk_parser_18-0.1.0-1PIGSTY.el10.aarch64.rpm
postgresql-18-pg-cjk-parser 0.1.0 d12.x86_64 pigsty 68.1 KiB postgresql-18-pg-cjk-parser_0.1.0-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-cjk-parser 0.1.0 d12.aarch64 pigsty 67.6 KiB postgresql-18-pg-cjk-parser_0.1.0-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-cjk-parser 0.1.0 d13.x86_64 pigsty 68.1 KiB postgresql-18-pg-cjk-parser_0.1.0-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-cjk-parser 0.1.0 d13.aarch64 pigsty 67.8 KiB postgresql-18-pg-cjk-parser_0.1.0-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-cjk-parser 0.1.0 u22.x86_64 pigsty 73.9 KiB postgresql-18-pg-cjk-parser_0.1.0-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-cjk-parser 0.1.0 u22.aarch64 pigsty 73.7 KiB postgresql-18-pg-cjk-parser_0.1.0-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-cjk-parser 0.1.0 u24.x86_64 pigsty 72.6 KiB postgresql-18-pg-cjk-parser_0.1.0-1PIGSTY~noble_amd64.deb
postgresql-18-pg-cjk-parser 0.1.0 u24.aarch64 pigsty 72.5 KiB postgresql-18-pg-cjk-parser_0.1.0-1PIGSTY~noble_arm64.deb
postgresql-18-pg-cjk-parser 0.1.0 u26.x86_64 pigsty 71.7 KiB postgresql-18-pg-cjk-parser_0.1.0-1PIGSTY~resolute_amd64.deb
postgresql-18-pg-cjk-parser 0.1.0 u26.aarch64 pigsty 71.6 KiB postgresql-18-pg-cjk-parser_0.1.0-1PIGSTY~resolute_arm64.deb

Source

pig build pkg pg_cjk_parser;		# 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_cjk_parser;		# install via package name, for the active PG version

pig install pg_cjk_parser -v 18;   # install for PG 18
pig install pg_cjk_parser -v 17;   # install for PG 17
pig install pg_cjk_parser -v 16;   # install for PG 16
pig install pg_cjk_parser -v 15;   # install for PG 15
pig install pg_cjk_parser -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION pg_cjk_parser;

Usage

Sources:

pg_cjk_parser is a PostgreSQL full-text-search parser derived from the built-in parser. In a UTF-8 database it keeps the default behavior for non-CJK text while emitting overlapping 2-gram tokens for Chinese, Japanese, and Korean text. The extension installs parser support functions; you create the text-search parser and configuration that use them.

Core Workflow

CREATE EXTENSION pg_cjk_parser;

CREATE TEXT SEARCH PARSER public.pg_cjk_parser (
    START = prsd2_cjk_start,
    GETTOKEN = prsd2_cjk_nexttoken,
    END = prsd2_cjk_end,
    LEXTYPES = prsd2_cjk_lextype,
    HEADLINE = prsd2_cjk_headline
);

CREATE TEXT SEARCH CONFIGURATION public.config_2_gram_cjk (
    PARSER = public.pg_cjk_parser
);

SELECT alias, description, token
FROM ts_debug(
    'public.config_2_gram_cjk',
    'PostgreSQL 全文検索和中文检索'
);

Use the configuration explicitly in generated tsvector columns and queries, or set it as the session default:

SET default_text_search_config = 'public.config_2_gram_cjk';

SELECT to_tsvector('public.config_2_gram_cjk', '日本語全文検索');

Important Objects

  • prsd2_cjk_start, prsd2_cjk_nexttoken, prsd2_cjk_end, prsd2_cjk_lextype, and prsd2_cjk_headline: support functions used by CREATE TEXT SEARCH PARSER.
  • cjk_zht2zhs(text): converts mapped Traditional Chinese characters to Simplified Chinese while leaving other characters unchanged.
  • Parser token type cjk: emits overlapping CJK bigrams; CJK punctuation is emitted as a unigram.
SELECT cjk_zht2zhs('漢語');
-- 汉语

Version Notes and Caveats

  • Version 0.1.0 fixes incorrect cjk_zht2zhs scanning across mixed-width UTF-8 characters and corrects handling of four-byte CJK code points.
  • Upstream supports PostgreSQL 11 through 18 at this release.
  • The database must use UTF-8 for CJK bigram behavior. With another encoding, the parser behaves like the PostgreSQL default parser.
  • Creating a text-search parser requires elevated privileges. Decide mappings, dictionaries, stop words, and ranking separately; the example configuration defines only the parser.
Last updated on