From 15469415857cbb9dd2e16771c5c852efdaea6bc7 Mon Sep 17 00:00:00 2001 From: Steven Niu Date: Mon, 30 Mar 2026 01:54:07 +0000 Subject: [PATCH 1/2] support pg_textsearch --- CN/modules/ROOT/nav.adoc | 1 + .../ecosystem_components/pg_textsearch.adoc | 91 +++++++++++++++++++ EN/modules/ROOT/nav.adoc | 1 + .../ecosystem_components/pg_textsearch.adoc | 88 ++++++++++++++++++ 4 files changed, 181 insertions(+) create mode 100644 CN/modules/ROOT/pages/master/ecosystem_components/pg_textsearch.adoc create mode 100644 EN/modules/ROOT/pages/master/ecosystem_components/pg_textsearch.adoc diff --git a/CN/modules/ROOT/nav.adoc b/CN/modules/ROOT/nav.adoc index 91a8efe..eb83b83 100644 --- a/CN/modules/ROOT/nav.adoc +++ b/CN/modules/ROOT/nav.adoc @@ -53,6 +53,7 @@ *** xref:master/ecosystem_components/wal2json.adoc[wal2json] *** xref:master/ecosystem_components/pg_stat_monitor.adoc[pg_stat_monitor] *** xref:master/ecosystem_components/pg_ai_query.adoc[pg_ai_query] +*** xref:master/ecosystem_components/pg_textsearch.adoc[pg_textsearch] * 监控运维 ** xref:master/getting-started/daily_monitoring.adoc[日常监控] ** xref:master/getting-started/daily_maintenance.adoc[日常维护] diff --git a/CN/modules/ROOT/pages/master/ecosystem_components/pg_textsearch.adoc b/CN/modules/ROOT/pages/master/ecosystem_components/pg_textsearch.adoc new file mode 100644 index 0000000..0ec867a --- /dev/null +++ b/CN/modules/ROOT/pages/master/ecosystem_components/pg_textsearch.adoc @@ -0,0 +1,91 @@ + +:sectnums: +:sectnumlevels: 5 + += pg_textsearch + +== 概述 +pg_textsearch 是由Timescale团队开发的一个PostgreSQL扩展,旨在为Postgres提供高性能、现代化的全文搜索能力,并针对AI工作负载和混合搜索进行了优化。 + +== 安装 + +[TIP] +源码安装环境为 Ubuntu 24.04(x86_64),环境中已经安装了IvorySQL5及以上版本,安装路径为/usr/ivory-5 + +=== 源码安装 + +[literal] +---- +# 从 wget https://github.com/timescale/pg_textsearch/archive/refs/tags/v0.6.1.tar.gz 下载源码包 + +tar xzvf v0.6.1.tar.gz +cd pg_textsearch-0.6.1 + +# 编译安装插件 +make PG_CONFIG=/usr/ivory-5/bin/pg_config +make PG_CONFIG=/usr/ivory-5/bin/pg_config install + +---- + +[TIP] +如果出现找不到xlocale.h的错误,需要手动修改 /usr/ivory-5/include/postgresql/server/pg_config.h +删除或者注释掉 #define HAVE_XLOCALE_H 1 这一行 + +=== 修改数据库配置文件 + +修改 ivorysql.conf 文件,添加 pg_textsearch 到 shared_preload_libraries + +[literal] +---- +shared_preload_libraries = 'gb18030_2022, liboracle_parser, ivorysql_ora, pg_textsearch' +---- + +重启数据库后配置生效。 + +=== 创建Extension + +[literal] +---- +postgres=# create extension pg_textsearch; +WARNING: pg_textsearch v0.6.1 is a prerelease. Do not use in production. +CREATE EXTENSION +---- + +== 使用 + +创建一个带有文本内容的表: +[literal] +---- +postgres=# CREATE TABLE documents (id bigserial PRIMARY KEY, content text); +CREATE TABLE + +postgres=# INSERT INTO documents (content) VALUES + ('PostgreSQL is a powerful database system'), + ('BM25 is an effective ranking function'), + ('Full text search with custom scoring'); +INSERT 0 3 +---- + +在文本列上创建 pg_textsearch 索引 +[literal] +---- +postgres=# CREATE INDEX docs_idx ON documents USING bm25(content) WITH (text_config='english'); +NOTICE: BM25 index build started for relation docs_idx +NOTICE: Using text search configuration: english +NOTICE: Using index options: k1=1.20, b=0.75 +NOTICE: BM25 index build completed: 3 documents, avg_length=4.33 +CREATE INDEX +---- + +使用@操作符获取最相关的文档: +[literal] +---- +postgres=# SELECT * FROM documents ORDER BY content <@> 'database system' LIMIT 5; + id | content +----+------------------------------------------ + 1 | PostgreSQL is a powerful database system + 2 | BM25 is an effective ranking function + 3 | Full text search with custom scoring +(3 rows) +---- + diff --git a/EN/modules/ROOT/nav.adoc b/EN/modules/ROOT/nav.adoc index 10f2ebd..e6b8e10 100644 --- a/EN/modules/ROOT/nav.adoc +++ b/EN/modules/ROOT/nav.adoc @@ -53,6 +53,7 @@ *** xref:master/ecosystem_components/pg_ai_query.adoc[pg_ai_query] *** xref:master/ecosystem_components/wal2json.adoc[wal2json] *** xref:master/ecosystem_components/pg_stat_monitor.adoc[pg_stat_monitor] +*** xref:master/ecosystem_components/pg_textsearch.adoc[pg_textsearch] * Monitor and O&M ** xref:master/getting-started/daily_monitoring.adoc[Monitoring] ** xref:master/getting-started/daily_maintenance.adoc[Maintenance] diff --git a/EN/modules/ROOT/pages/master/ecosystem_components/pg_textsearch.adoc b/EN/modules/ROOT/pages/master/ecosystem_components/pg_textsearch.adoc new file mode 100644 index 0000000..40c880a --- /dev/null +++ b/EN/modules/ROOT/pages/master/ecosystem_components/pg_textsearch.adoc @@ -0,0 +1,88 @@ + +:sectnums: +:sectnumlevels: 5 + += pg_textsearch + +== Overview +pg_textsearch is a PostgreSQL extension developed by the Timescale team. It is designed to provide high-performance, modern full-text search capabilities for Postgres, and is optimized for AI workloads and hybrid search. + +== Installation + +[TIP] +The source code installation environment is Ubuntu 24.04 (x86_64), in which IvorySQL 5 or a later version has been installed. The installation path is /usr/ivory-5. + +=== Source Code Installation + +[literal] +---- +# download source code package from: https://github.com/timescale/pg_textsearch/archive/refs/tags/v0.6.1.tar.gz + +tar xzvf v0.6.1.tar.gz +cd pg_textsearch-0.6.1 + +# compile and install the extension +make PG_CONFIG=/usr/ivory-5/bin/pg_config +make PG_CONFIG=/usr/ivory-5/bin/pg_config install +---- + +[TIP] +If there is error "xlocale.h: No such file or directory" during compilation, user should remove the +line of "#define HAVE_XLOCALE_H 1" from file /usr/ivory-5/include/postgresql/server/pg_config.h. + +=== Modify the configuration file + +Modify the ivorysql.conf file to add pg_textsearch into shared_preload_libraries. +[literal] +---- +shared_preload_libraries = 'gb18030_2022, liboracle_parser, ivorysql_ora, pg_textsearch' +---- + +Then restart the database. + +=== Create Extension + +[literal] +---- +postgres=# create extension pg_textsearch; +WARNING: pg_textsearch v0.6.1 is a prerelease. Do not use in production. +CREATE EXTENSION +---- + +== Use + +Create a table with text content: +[literal] +---- +postgres=# CREATE TABLE documents (id bigserial PRIMARY KEY, content text); +CREATE TABLE + +postgres=# INSERT INTO documents (content) VALUES + ('PostgreSQL is a powerful database system'), + ('BM25 is an effective ranking function'), + ('Full text search with custom scoring'); +INSERT 0 3 +---- + +Create a pg_textsearch index on the text column: +[literal] +---- +postgres=# CREATE INDEX docs_idx ON documents USING bm25(content) WITH (text_config='english'); +NOTICE: BM25 index build started for relation docs_idx +NOTICE: Using text search configuration: english +NOTICE: Using index options: k1=1.20, b=0.75 +NOTICE: BM25 index build completed: 3 documents, avg_length=4.33 +CREATE INDEX +---- + +Get the most relevant documents using the <@> operator: +[literal] +---- +postgres=# SELECT * FROM documents ORDER BY content <@> 'database system' LIMIT 5; + id | content +----+------------------------------------------ + 1 | PostgreSQL is a powerful database system + 2 | BM25 is an effective ranking function + 3 | Full text search with custom scoring +(3 rows) +---- From 9f2d1278302dd92e1b7f8c9216a74623629eeab4 Mon Sep 17 00:00:00 2001 From: Steven Niu Date: Mon, 30 Mar 2026 02:18:00 +0000 Subject: [PATCH 2/2] fix some wording --- .../ROOT/pages/master/ecosystem_components/pg_textsearch.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CN/modules/ROOT/pages/master/ecosystem_components/pg_textsearch.adoc b/CN/modules/ROOT/pages/master/ecosystem_components/pg_textsearch.adoc index 0ec867a..d888bca 100644 --- a/CN/modules/ROOT/pages/master/ecosystem_components/pg_textsearch.adoc +++ b/CN/modules/ROOT/pages/master/ecosystem_components/pg_textsearch.adoc @@ -16,7 +16,7 @@ pg_textsearch 是由Timescale团队开发的一个PostgreSQL扩展,旨在为Po [literal] ---- -# 从 wget https://github.com/timescale/pg_textsearch/archive/refs/tags/v0.6.1.tar.gz 下载源码包 +# 从 https://github.com/timescale/pg_textsearch/archive/refs/tags/v0.6.1.tar.gz 下载源码包 tar xzvf v0.6.1.tar.gz cd pg_textsearch-0.6.1 @@ -66,7 +66,7 @@ postgres=# INSERT INTO documents (content) VALUES INSERT 0 3 ---- -在文本列上创建 pg_textsearch 索引 +在文本列上创建 pg_textsearch 索引: [literal] ---- postgres=# CREATE INDEX docs_idx ON documents USING bm25(content) WITH (text_config='english');