【发布时间】:2020-06-30 07:49:13
【问题描述】:
我使用 PostgreSQL 11.8。对于 Postgres,我使用 docker 镜像 postgres:11-alpine。我想为基于某些单词的表达式创建自定义全文搜索字典,例如 hello world 应该变为 hw。
首先我有一个自定义全文搜索配置my_swedish:
CREATE TEXT SEARCH CONFIGURATION my_swedish (
COPY = swedish
);
ALTER TEXT SEARCH CONFIGURATION my_swedish
DROP MAPPING FOR hword_asciipart;
ALTER TEXT SEARCH CONFIGURATION my_swedish
DROP MAPPING FOR hword_part;
对于这个配置,我想创建和使用字典。为此,我遵循 PostgreSQL 手册:
CREATE TEXT SEARCH DICTIONARY thesaurus_my_swedish (
TEMPLATE = thesaurus,
DictFile = thesaurus_my_swedish,
Dictionary = pg_catalog.swedish_stem
);
我面临着
ERROR: could not open thesaurus file "/usr/local/share/postgresql/tsearch_data/thesaurus_my_swedish.ths": No such file or directory
然后我手动创建了文件:
touch /usr/local/share/postgresql/tsearch_data/thesaurus_astro.ths
然后:
ALTER TEXT SEARCH CONFIGURATION my_swedish
ALTER MAPPING FOR asciiword, asciihword, hword_asciipart
WITH thesaurus_my_swedish;
ERROR: text search configuration "my_swedish" does not exist
当我把它改成默认swedish
ALTER TEXT SEARCH CONFIGURATION swedish
ALTER MAPPING FOR asciiword, asciihword, hword_asciipart
WITH thesaurus_my_swedish;
我得到了错误:
ERROR: text search dictionary "thesaurus_my_swedish" does not exist
如何为我的自定义测试搜索配置正确创建同义词词典?
更新
我在我的文件中添加了thesaurus_my_swedish.ths 数据hello world : hw 现在
SELECT to_tsvector('my_swedish', 'hello world');
返回'hw':1,
但是其他词呢?因为to_tsvector('my_swedish', 'hello test')返回空,所以应该像默认瑞典一样返回
SELECT to_tsvector('swedish', 'hello test');
'hello':1 'test':2
怎么了?
更新
我明白了,也需要加pg_catalog.swedish_stem
ALTER TEXT SEARCH CONFIGURATION my_swedish
ALTER MAPPING FOR asciihword, asciiword, hword, word
WITH thesaurus_my_swedish, pg_catalog.swedish_stem;
【问题讨论】:
标签: postgresql full-text-search