在PostgreSQL中,我有一个带有同义词词典的文本搜索配置,然后我使用english_stem文件。问题是,例如,我把"电视"这个词作为"电视"的同义词。因此,当我输入时:
SELECT to_tsvector('my_config', 'tv') returns 'television':1
然而
SELECT to_tsvector('my_config', 'television') returns 'televis':1
因此,我们可以看到,在单词被传递到同义词词典后,词干词典会忽略它
我的文本搜索配置写为:
ALTER TEXT SEARCH CONFIGURATION test_config
ALTER MAPPING FOR asciiword, word, hword, asciihword
WITH syn_file, english_stem
主要的问题是我的搜索结果没有同义词。
有两种解决方案:
- 您可以这样创建同义词文件:
电视
-
你可以使用同义词词典来代替同义词词典:
- 在目录$SHAREDIR/tsearch_data中创建文件english.ths
电视
- 执行查询:
CREATE TEXT SEARCH DICTIONARY en_ths (
Template = thesaurus,
DictFile = mythesaurus,
Dictionary = pg_catalog.english_stem);
CREATE TEXT SEARCH CONFIGURATION en_ths(COPY='simple');
ALTER TEXT SEARCH CONFIGURATION en_ths
ALTER MAPPING FOR asciiword, asciihword, hword_asciipart,
word, hword, hword_part
WITH en_ths, english_stem;
现在你可以测试它:
test=# SELECT to_tsvector('en_ths', 'tv');
to_tsvector
-------------
'televis':1
(1 row)
test=# SELECT to_tsvector('en_ths', 'television');
to_tsvector
-------------
'televis':1
(1 row)