我已经有一段时间没有玩过这个了,但是您需要用正确的语言创建 ts_vector,而不是 ts_query。
因此,当您更新表时,请使用:
UPDATE blog_entry SET body_tsv=to_tsvector('german', body);
您还可以扩展功能并使用 ispell 字典来更好地对文本搜索引擎进行词干提取(尽管它仍然不会像 Solr 那样复杂)
为此,请下载 ISPELL 词典,例如包含在OpenOffice 德语词典 http://extensions.services.openoffice.org/en/project/dict-de_DE_frami
.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;
完成后,您可以使用以下命令创建 ts_vector:
UPDATE blog_entry SET body_tsv=to_tsvector('de_config', body);
这在手册中也有描述:http://www.postgresql.org/docs/current/static/textsearch-dictionaries.html#TEXTSEARCH-ISPELL-DICTIONARY http://www.postgresql.org/docs/current/static/textsearch-dictionaries.html#TEXTSEARCH-ISPELL-DICTIONARY