当前位置:首页 > 编程笔记 > 正文
已解决

postgresql中文分词插件安装

来自网友在路上 163863提问 提问时间:2023-10-01 22:10:58阅读次数: 63

最佳答案 问答题库638位专家为你答疑解惑

1.SCWS

      要使用 zhparser,首先需要安装 SCWS 分词库,SCWS 是 Simple Chinese Word Segmentation 的首字母缩写(即:简易中文分词系统)GitHub

http://www.xunsearch.com/scws/down/scws-1.2.3.tar.bz2
 

 

./configure 
make install

 

2.Zhparser

GitHub - amutu/zhparser: zhparser is a PostgreSQL extension for full-text search of Chinese language

 make && make install
遇到:pgxs.mk: 没有那个文件或目录,安装postgres-devel包
找不到pg_config:可以指定PG_CONFG=/usr/pgsql-14/bin/pg_config make

3.postgresql中文检索配置

 登录postgresql启用zhparser插件

create extension zhparser;

创建使用zhparser作为解析器的全文搜索的配置

-- 就是需要给zhparser解析器取一个在sql里面可以使用的名称,一下“zh”则为名称 CREATE create text search configuration chinese (parser=zhparser);

添加token映射

alter text search configuration chinese add mapping for a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z with simple;

 4、全文检索使用

索引创建 

 create index idx_name on table_name using gin(to_tsvector('zh', field_name));

查询 

SELECT * FROM table_name WHERE to_tsvector('zh', field_name) @@ 'keyword';

查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"postgresql中文分词插件安装":http://eshow365.cn/6-15556-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!