tsvector只支持英文吗? [英] tsvector only supports English?

查看:178
本文介绍了tsvector只支持英文吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了以下事情:

ALTER TABLE blog_entry ADD COLUMN body_tsv tsvector;

CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON blog_entry 
    FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger(body_tsv, 'pg_catalog.english', body);

CREATE INDEX blog_entry_tsv ON blog_entry USING gin(body_tsv);

UPDATE blog_entry SET body_tsv=to_tsvector(body);

现在可以使用了:

SELECT title FROM blog_entry WHERE body_tsv @@ plainto_tsquery('hello world');

但是当尝试搜索非英文文本时,它根本无法工作(没有结果)。

But when trying to search for non-English text, it's not working at all (no results).

我正在使用v9.2.2

I am using v9.2.2

请帮助。

推荐答案

自从我玩这个游戏已经有一段时间了,但是您需要使用正确的语言而不是ts_query创建ts_vector。

It's been a while since I played with this, but you need to create the ts_vector in the correct language, not the ts_query.

因此,当您更新表时,请使用:

So when you update your table, use:

UPDATE blog_entry SET body_tsv=to_tsvector('german', body);

您还可以扩展功能并使用ispell词典来使词干更好地适合文本搜索引擎(尽管它仍然不如Solr复杂)

You can also extend the functionality and use an ispell dictionary to make stemming better to the text search engine (although it still won't be as sophisticated as e.g. Solr)

为此,请下载ISPELL字典,例如包含在 OpenOffice德语词典

To do that, download the ISPELL dictionary that is e.g. contained in the OpenOffice German dictionary

.oxt文件实际上是一个.zip文件,因此您只需提取其内容即可。

The .oxt file is actually a .zip file, so you can simply extract its content.

然后复制文件将扩展名更改为 .dict (这是PostgreSQL期望的。

Then copy the file de_DE_frami.dic to the PostgreSQL "share/tsearch_data" directory while changing the extension to .dict (which is what PostgreSQL expects.

然后将文件 de_DE_frami.aff 复制到同一目录,将扩展名更改为 .affix

Then copy the file de_DE_frami.aff to the same directory, changing the extension to .affix.

您需要将两个(文本)文件都转换为UTF-8,才能与PostgreSQL一起使用

然后使用以下命令注册该字典:

Then register that dictionary using:

CREATE TEXT SEARCH CONFIGURATION de_config (copy=german);

CREATE TEXT SEARCH DICTIONARY german_stem (
    TEMPLATE = snowball,
    Language = german
);

CREATE TEXT SEARCH DICTIONARY german_ispell (
    TEMPLATE = ispell,
    dictfile = de_DE_frami,
    afffile = de_de_frami
);

alter text search configuration de_config 
     alter mapping for asciiword WITH german_ispell, german_stem;

完成后,您可以使用以下方式创建ts_vector:

Once that is done, you can create your ts_vector using:

UPDATE blog_entry SET body_tsv=to_tsvector('de_config', body);

这在手册中也有描述: http://www.postgresql.org/docs/current/static/textsearch-dictionaries.html#TEXTSEARCH- ISPELL-字典

This is also described in the manual: http://www.postgresql.org/docs/current/static/textsearch-dictionaries.html#TEXTSEARCH-ISPELL-DICTIONARY

这篇关于tsvector只支持英文吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆