本文介绍了PostgreSQL全文搜索缩写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用德语创建了Postgresql全文搜索。当我搜索 Bezirk时,该如何配置包含 Bez的行。也是比赛吗? (反之亦然)

I created a Postgresql full text search using 'german'. How can I configer, that when I search for "Bezirk", lines containing "Bez." are also a match? (And vice-versa)

推荐答案

@pozs是正确的。您需要使用同义词字典

@pozs is right. You need to use a synonym dictionary.

1-在$ SHAREDIR / tsearch_data目录中,创建文件german.syn,其内容如下:

1 - In the directory $SHAREDIR/tsearch_data create the file german.syn with the following contents:

Bez Bezirk

2-执行查询:

CREATE TEXT SEARCH DICTIONARY german_syn (
    template = synonym,
    synonyms = german);
CREATE TEXT SEARCH CONFIGURATION german_syn(COPY='simple');
ALTER TEXT SEARCH CONFIGURATION german_syn
    ALTER MAPPING FOR asciiword, asciihword, hword_asciipart,
        word, hword, hword_part
    WITH german_syn, german_stem;

现在您可以对其进行测试。执行查询:

Now you can test it. Execute queries:

test=# SELECT to_tsvector('german_syn', 'Bezirk') @@ to_tsquery('german_syn', 'Bezirk & Bez');
 ?column?
----------
 t
(1 row)

test=# SELECT to_tsvector('german_syn', 'Bez Bez.') @@ to_tsquery('german_syn', 'Bezirk');
 ?column?
----------
 t
(1 row)

附加链接:


  1. (已过期)

这篇关于PostgreSQL全文搜索缩写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 12:32