This topic describes how to run full-text searches in Chinese to query data from an ApsaraDB RDS for PostgreSQL instance by using the pg_jieba plug-in.
Prerequisites
- Your RDS instance runs one of the following database engine versions:
- Major engine version: PostgreSQL 10, PostgreSQL 11, PostgreSQL 12, or PostgreSQL 13.
- Minor engine version: 20211130 or later. For more information about how to update the minor engine version, see Update the minor engine version of an ApsaraDB RDS for PostgreSQL instance.
- pg_jieba is added to the value of the shared_preload_libraries parameter of your RDS instance.
For more information about how to add pg_jieba to the value of the shared_preload_libraries parameter, see Manage the parameters of an ApsaraDB RDS for PostgreSQL instance.
Procedure
- Create the pg_jieba plug-in.
CREATE EXTENSION pg_jieba;
Note Only privileged accounts are authorized to run the preceding command. - Delete the pg_jieba plug-in.
DROP EXTENSION pg_jieba;
Note Only privileged accounts are authorized to run the preceding command. - Example 1:
select * from to_tsvector('jiebacfg', '小明硕士毕业于中国科学院计算所,后在日本京都大学深造'); to_tsvector -------------------------------------------------------------------------------------------------------------- '中国科学院':5 '于':4 '后':8 '在':9 '小明':1 '日本京都大学':10 '毕业':3 '深造':11 '硕士':2 '计算所':6 ',':7 (1 row)
- Example 2:
select * from to_tsvector('jiebacfg', '李小福是创新办主任也是云计算方面的专家'); to_tsvector ------------------------------------------------------------------------------------------- '专家':11 '主任':5 '也':6 '云计算':8 '创新':3 '办':4 '方面':9 '是':2,7 '李小福':1 '的':10 (1 row)