我假设我们可以使用这个老菜谱,只将语言german替换为language simple (即“无语言”).但这是行不通的。
CREATE TEXT SEARCH DICTIONARY my_synonym (
TEMPLATE = synonym,
SYNONYMS = synonym_sample
-- default /usr/share/postgresql/12/tsearch_data/synonym_sample.syn
);
CREATE TEXT SEARCH CONFIGURATION my_synonym(COPY='simple'); -- need it??
ALTER TEXT SEARCH CONFIGURATION my_synonym
ALTER MAPPING FOR asciiword, asciihword, hword_asciipart, word, hword, hword_part
WITH my_synonym -- make sense??
;
SELECT to_tsvector('my_synonym', 'Postgresql')
@@ to_tsquery('my_synonym', 'Postgresql'); -- true
SELECT to_tsvector('my_synonym', 'Postgresql')
@@ to_tsquery('my_synonym', 'pgsql'); -- false. NOTICE:
-- text-search query contains only stop words or doesn't contain lexemes, ignored
SELECT to_tsvector('my_synonym', 'Postgresql pgsql')
@@ to_tsquery('my_synonym', 'pgsql'); -- false. Same NOTICE.synonym_sample.syn在当前的导游12.6.3号。同义词词典部分中进行了描述。它将"pgsql“缩写转换为"postgres”字..。所以很多问题
发布于 2020-02-05 20:28:41
完成了同义词替换之后,需要将产生的词汇传递给词干分析器。这在您链接到的两个示例中都会发生,但在您的示例中没有发生。您可以使用“简单”作为一个虚拟词干器,它只是传递它的输出,而不执行任何实际的词干。
ALTER TEXT SEARCH CONFIGURATION my_synonym
ALTER MAPPING FOR asciiword, asciihword, hword_asciipart, word, hword, hword_part
WITH my_synonym, simple;发布于 2020-02-06 03:42:53
我同意“杰恩斯”的回答。您需要将synonym字典的结果传递给simple字典。
如果不将结果传递给simple字典,则如下所示:
SELECT to_tsvector('my_synonym', 'Postgresql'), to_tsquery('my_synonym', 'pgsql');
to_tsvector | to_tsquery
-------------+------------
'pgsql':1 |这是如果你通过它的结果:
SELECT to_tsvector('my_synonym', 'Postgresql'), to_tsquery('my_synonym', 'pgsql');
to_tsvector | to_tsquery
-------------+------------
'pgsql':1 | 'pgsql'但是,如果您不想使用除以外的其他字典,则可以使用另一种方法。您可以使用dict_xsyn控制模块。这是它的文档:https://www.postgresql.org/docs/current/dict-xsyn.html
只需做以下几点:
CREATE EXTENSION dict_xsyn;
ALTER TEXT SEARCH DICTIONARY xsyn(
RULES='xsyn_sample', KEEPORIG=false, MATCHSYNONYMS=true);
CREATE TEXT SEARCH CONFIGURATION xsyn(COPY='simple');
ALTER TEXT SEARCH CONFIGURATION xsyn
ALTER MAPPING FOR
asciiword, asciihword, hword_asciipart, word, hword, hword_part
WITH xsyn;这里我不使用simple字典。创建dict_xsyn扩展还会创建xsyn字典。但是它不会创建配置,所以您需要创建适当的配置。
您还需要使用适当的选项配置xsyn字典,或者创建新的选项。我的xsyn_sample.rules文件是:
supernova sn sne 1987a
postgresql pgsql以下是研究结果:
SELECT to_tsvector('xsyn', 'Postgresql'), to_tsquery('xsyn', 'pgsql');
to_tsvector | to_tsquery
-------------+------------
'pgsql':1 | 'pgsql'
SELECT to_tsvector('xsyn', 'Postgresql') @@ to_tsquery('xsyn', 'pgsql');
?column?
----------
thttps://stackoverflow.com/questions/60082663
复制相似问题