我使用PostgreSQL 11.8。对于Postgres,我使用了码头图像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 data 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;发布于 2020-06-30 08:29:25
你把一切都做对了,只有几个例外:
thesaurus_my_swedish.ths不应该是空的,而是包含这样的规则(取自您的示例):hello : hw
swedish_stem的所有令牌类型使用新的字典,即更改文本搜索配置my_swedish用于asciihword,asciiword,hword,word与thesaurus_my_swedish,swedish_stem;的更改映射
这个错误是神秘的,不应该发生的:
ERROR: text search configuration "my_swedish" does not exist您可能连接到了错误的数据库,或者再次删除了配置,或者它不在search_path上,您必须用它的模式对其进行限定。使用psql中的psql列出所有现有配置。
当然,在文本搜索配置中使用字典之前,您必须创建字典。
不要修改pg_catalog中的配置,这种修改将在升级后丢失。
https://stackoverflow.com/questions/62652659
复制相似问题