Skip to content

Commit

Permalink
change custom word location.
Browse files Browse the repository at this point in the history
move custom word from /base/${DATABASE_ID}/zhprs_dict_${DATABASE_NAME}.txt to
/base/zhprs_dict_${DATABASE_NAME}.txt(data dir don't have /base/${DATABASE_ID} when tablespace is setted)
  • Loading branch information
zlianzhuang committed Nov 8, 2021
1 parent e909539 commit 26b4cfa
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2.2 (2021-11-08)
-- move custom word from /base/${DATABASE_ID}/zhprs_dict_${DATABASE_NAME}.txt to /base/zhprs_dict_${DATABASE_NAME}.txt(data don't have /base/${DATABASE_ID} when tablespace is setted)

2.1 (2019-04-23)
-- custom word store in DataDir.

Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ OBJS = zhparser.o

EXTENSION = zhparser
DATA = zhparser--1.0.sql zhparser--unpackaged--1.0.sql \
zhparser--1.0--2.0.sql zhparser--2.0.sql \
zhparser--2.0--2.1.sql zhparser--2.1.sql
zhparser--1.0--2.0.sql zhparser--2.0.sql zhparser--2.0--2.1.sql zhparser--2.1.sql zhparser--2.1--2.2.sql
DATA_TSEARCH = dict.utf8.xdb rules.utf8.ini

REGRESS = zhparser
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ zhparser.multi_zmain = f
全部单字复合:
zhparser.multi_zall = f

除了zhparser自带的词典,用户可以增加自定义词典,自定义词典的优先级高于自带的词典。自定义词典的文件必须放在share/postgresql/tsearch_data目录中,zhparser根据文件扩展名确定词典的格式类型,.txt扩展名表示词典是文本格式,.xdb扩展名表示这个词典是xdb格式,多个文件使用逗号分隔,词典的分词优先级由低到高,如:
除了zhparser自带的词典,用户可以增加自定义词典,自定义词典的优先级高于自带的词典。自定义词典的文件必须放在share/tsearch_data目录中,zhparser根据文件扩展名确定词典的格式类型,.txt扩展名表示词典是文本格式,.xdb扩展名表示这个词典是xdb格式,多个文件使用逗号分隔,词典的分词优先级由低到高,如:

zhparser.extra_dicts = 'dict_extra.txt,mydict.xdb'

Expand Down
21 changes: 21 additions & 0 deletions zhparser--2.1--2.2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CREATE or REPLACE FUNCTION sync_zhprs_custom_word() RETURNS void LANGUAGE plpgsql AS
$$
declare
data_dir text;
dict_path text;
time_tag_path text;
query text;
begin
select setting from pg_settings where name='data_directory' into data_dir;

select data_dir || '/base/' || '/zhprs_dict_' || current_database() || '.txt' into dict_path;
select data_dir || '/base/' || '/zhprs_dict_' || current_database() || '.tag' into time_tag_path;

query = 'copy (select word, tf, idf, attr from zhparser.zhprs_custom_word) to ' || chr(39) || dict_path || chr(39) || ' encoding ' || chr(39) || 'utf8' || chr(39) ;
execute query;
query = 'copy (select now()) to ' || chr(39) || time_tag_path || chr(39) ;
execute query;
end;
$$;

select sync_zhprs_custom_word();
4 changes: 2 additions & 2 deletions zhparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ static void init(){
)));
}

snprintf(dict_path, MAXPGPATH, "%s/base/%u/zhprs_dict_%s.txt",
DataDir, MyDatabaseId, get_database_name(MyDatabaseId));
snprintf(dict_path, MAXPGPATH, "%s/base/zhprs_dict_%s.txt",
DataDir, get_database_name(MyDatabaseId));
if(scws_add_dict(scws, dict_path, load_dict_mem_mode | SCWS_XDICT_TXT) != 0 ){
ereport(NOTICE,
(errcode(ERRCODE_INTERNAL_ERROR),
Expand Down
2 changes: 1 addition & 1 deletion zhparser.control
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
comment = 'a parser for full-text search of Chinese'
default_version = '2.1'
default_version = '2.2'
module_pathname = '$libdir/zhparser'
relocatable = true

0 comments on commit 26b4cfa

Please sign in to comment.