如何在openGauss中使用zhparser

如何在 openGauss 中使用 zhparser

准备

  1. 一个装有 openGauss 数据库的环境
  2. 下载 scws 代码到任意位置: https://github.com/hightman/scws master
  3. 下载 zhparser 代码到任意位置: GitHub - amutu/zhparser: zhparser is a PostgreSQL extension for full-text search of Chinese language master

步骤

  1. 登录环境并 source openGauss 的环境变量
  2. 编译安装 scws
    1. 解压并进入文件夹: unzip scws-master.zip && cd scws-master
    2. 生成 configure 文件并执行编译: ./acprep && ./configure && make
    3. 安装 scws 到相关 lib 目录(需要 root 权限):make install
    4. 修改刚刚安装的 scws lib 的到合适的权限(需要 root 权限):chmod 777 /usr/local/include/scws -R
  3. 编译安装 zhparser
    1. 解压并进入文件夹:unzip zhparser-master.zip && cd zhparser-master
    2. 按照下文 patch 修改 zhparser 代码。
    3. 编译安装(若报错见 Q&A):make && make install

PATCH

复制代码
diff --git a/zhparser-master/Makefile b/zhparser-master/Makefile
index ae048c3..20b1830 100644
--- a/zhparser-master/Makefile
--- b/zhparser-master/Makefile
@@ -12,7 +12,7 @@ DATA_TSEARCH = dict.utf8.xdb rules.utf8.ini
 REGRESS = zhparser

 SCWS_HOME ?= /usr/local
-PG_CPPFLAGS = -I$(SCWS_HOME)/include/scws
+PG_CPPFLAGS = -I$(SCWS_HOME)/include/scws -fpic
 SHLIB_LINK = -lscws -L$(SCWS_HOME)/lib -Wl,-rpath -Wl,$(SCWS_HOME)/lib

 PG_CONFIG ?= pg_config
diff --git a/zhparser-master/zhparser.c b/zhparser-master/zhparser.c
index 527cef0..6212533 100644
--- a/zhparser-master/zhparser.c
--- b/zhparser-master/zhparser.c
@@ -57,16 +57,16 @@ static void init_type(LexDescr descr[]);
  * prototypes
  */
 PG_FUNCTION_INFO_V1(zhprs_start);
-Datum          zhprs_start(PG_FUNCTION_ARGS);
+extern "C" Datum zhprs_start(PG_FUNCTION_ARGS);

 PG_FUNCTION_INFO_V1(zhprs_getlexeme);
-Datum          zhprs_getlexeme(PG_FUNCTION_ARGS);
+extern "C" Datum zhprs_getlexeme(PG_FUNCTION_ARGS);

 PG_FUNCTION_INFO_V1(zhprs_end);
-Datum          zhprs_end(PG_FUNCTION_ARGS);
+extern "C" Datum zhprs_end(PG_FUNCTION_ARGS);

 PG_FUNCTION_INFO_V1(zhprs_lextype);
-Datum          zhprs_lextype(PG_FUNCTION_ARGS);
+extern "C" Datum               zhprs_lextype(PG_FUNCTION_ARGS);

 static scws_t scws = NULL;
 static ParserState parser_state;
@@ -213,7 +213,7 @@ static void init(){
        }

        snprintf(dict_path, MAXPGPATH, "%s/base/%u/zhprs_dict_%s.txt",
-                       DataDir, MyDatabaseId, get_database_name(MyDatabaseId));
+                       t_thrd.proc_cxt.DataDir, u_sess->proc_cxt.MyDatabaseId, get_database_name(u_sess->proc_cxt.MyDatabaseId));
        if(scws_add_dict(scws, dict_path, load_dict_mem_mode | SCWS_XDICT_TXT) != 0 ){
                ereport(NOTICE,
                            (errcode(ERRCODE_INTERNAL_ERROR),

DIFF 复制 全屏

Q&A

1、编译 zhparser 时报错 error: access/ustore/undo/knl_uundotype.h: No such file or directory

​ 解决方法:将 openGauss-server/src/include/access/ustore/undo/knl_uundotype.h 拷贝到 $GAUSSHOME/include/postgresql/server/access/ustore/undo/中,若没有目标位置没有这个文件夹,需要自行创建。

2、编译 zhparser 时报错 error: communication/commproxy_basic.h: No such file or directory

​ 参考上一个。

相关推荐
fengye20716114 分钟前
在MYSQL中导入cookbook.sql文件
数据库·mysql·adb
Ailovelearning44 分钟前
neo4j框架:ubuntu系统中neo4j安装与使用教程
数据库·neo4j
_星辰大海乀1 小时前
表的设计、聚合函数
java·数据结构·数据库·sql·mysql·数据库开发
未来之窗软件服务2 小时前
solidwors插件 开发————仙盟创梦IDE
前端·javascript·数据库·ide·仙盟创梦ide
yc_12242 小时前
SqlHelper 实现类,支持多数据库,提供异步操作、自动重试、事务、存储过程、分页、缓存等功能。
数据库·c#
Leo.yuan3 小时前
基于地图的数据可视化:解锁地理数据的真正价值
大数据·数据库·信息可视化·数据挖掘·数据分析
好吃的肘子3 小时前
MongoDB入门
数据库·mongodb
noravinsc3 小时前
人大金仓数据库 与django结合
数据库·python·django
代码配咖啡4 小时前
《Navicat之外的新选择:实测支持国产数据库的SQLynx核心功能解析》
数据库
懒大王爱吃狼4 小时前
怎么使用python进行PostgreSQL 数据库连接?
数据库·python·postgresql