tsvector只支持英语?

Ada*_*ver 3 postgresql postgresql-9.2

我做了以下事情:

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);
Run Code Online (Sandbox Code Playgroud)

现在这个工作:

SELECT title FROM blog_entry WHERE body_tsv @@ plainto_tsquery('hello world');
Run Code Online (Sandbox Code Playgroud)

但是当试图搜索非英文文本时,它根本不起作用(没有结果).

我使用的是v9.2.2

请帮忙.

a_h*_*ame 8

我玩这个已经有一段时间了,但你需要用正确的语言创建ts_vector,而不是ts_query.

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

UPDATE blog_entry SET body_tsv=to_tsvector('german', body);
Run Code Online (Sandbox Code Playgroud)

您还可以扩展功能并使用ispell字典来更好地阻止文本搜索引擎(虽然它仍然不会像Solr那样复杂)

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

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

然后将文件复制de_DE_frami.dic到PostgreSQL"share/tsearch_data"目录,同时将扩展名更改为.dict(这是PostgreSQL所期望的).

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

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

然后使用以下方

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;
Run Code Online (Sandbox Code Playgroud)

完成后,您可以使用以下命令创建ts_vector:

UPDATE blog_entry SET body_tsv=to_tsvector('de_config', body);
Run Code Online (Sandbox Code Playgroud)

手册中也对此进行了描述:http://www.postgresql.org/docs/current/static/textsearch-dictionaries.html#TEXTSEARCH-ISPELL-DICTIONARY