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
|
Source
pig build pkg pg_cjk_parser; # build rpm/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall 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 14Create 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, andprsd2_cjk_headline: support functions used byCREATE 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.0fixes incorrectcjk_zht2zhsscanning 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