|
| 1 | + |
| 2 | +:sectnums: |
| 3 | +:sectnumlevels: 5 |
| 4 | + |
| 5 | += pg_jieba |
| 6 | + |
| 7 | +== Overview |
| 8 | + |
| 9 | +pg_jieba is a Chinese word segmentation extension for PostgreSQL, developed based on the well-known Jieba (结巴分词) segmentation library. It can split continuous Chinese text into meaningful sequences of words, providing foundational support for Chinese full-text search. |
| 10 | + |
| 11 | +== Features |
| 12 | + |
| 13 | +* *Supports three segmentation modes*: precise mode, full mode, and search engine mode. |
| 14 | +* *Seamless integration with PostgreSQL/IvorySQL* |
| 15 | +* *Supports custom dictionaries* |
| 16 | +* *Supports part-of-speech tagging* |
| 17 | + |
| 18 | +== Installation and Deployment |
| 19 | + |
| 20 | +=== Building and Installing pg_jieba |
| 21 | + |
| 22 | +Assume IvorySQL has already been installed in the `~/ivy_5/inst` directory. |
| 23 | + |
| 24 | +[source,shell] |
| 25 | +---- |
| 26 | +git clone https://github.com/jaiminpan/pg_jieba.git |
| 27 | +cd pg_jieba |
| 28 | +git submodule update --init --recursive |
| 29 | +mkdir build;cd build |
| 30 | +cmake -DCMAKE_PREFIX_PATH=~/ivy_5/inst .. |
| 31 | +make; make install |
| 32 | +---- |
| 33 | + |
| 34 | +After a successful installation, files such as `pg_jieba.so` will be placed into IvorySQL's installation directory. |
| 35 | + |
| 36 | +=== Creating and Verifying the Extension |
| 37 | + |
| 38 | +[source,sql] |
| 39 | +---- |
| 40 | +CREATE EXTENSION IF NOT EXISTS pg_jieba; |
| 41 | +SELECT name, |
| 42 | + default_version, |
| 43 | + installed_version, |
| 44 | + comment |
| 45 | + FROM pg_available_extensions |
| 46 | + WHERE name = 'pg_jieba'; |
| 47 | +---- |
| 48 | + |
| 49 | +== Usage |
| 50 | + |
| 51 | +Run the following SQL example: |
| 52 | + |
| 53 | +[source,sql] |
| 54 | +---- |
| 55 | +select * from to_tsquery('jiebacfg', '是拖拉机学院手扶拖拉机专业的。不用多久,我就会升职加薪,当上CEO,走上人生巅峰。'); |
| 56 | + to_tsquery |
| 57 | +----------------------------------------------------------------------------------------------- |
| 58 | +'拖拉机' & '学院' & '手扶拖拉机' & '专业' & '不用' & '多久' & '会' & '升职' & '加薪' & '当上' & 'ceo' & '走上' & '人生' & '巅峰' |
| 59 | +(1 row) |
| 60 | + |
| 61 | +select * from to_tsvector('jiebacfg', '是拖拉机学院手扶拖拉机专业的。不用多久,我就会升职加薪,当上CEO,走上人生巅峰。'); |
| 62 | + to_tsvector |
| 63 | +----------------------------------------------------------------------------------------------------- |
| 64 | +'ceo':18 '不用':8 '专业':5 '人生':21 '会':13 '加薪':15 '升职':14 '多久':9 '学院':3 '巅峰':22 '当上':17 '手扶拖拉机':4 '拖拉机':2 '走上':20 |
| 65 | +(1 row) |
| 66 | +---- |
| 67 | + |
0 commit comments