【发布时间】:2011-04-25 13:21:47
【问题描述】:
我正在开发一个简单的巴西葡萄牙语文章网站。搜索功能基于全文搜索,但未返回预期结果。
我在 postgresql 上做了这个。这是简化表:
Artigos
-id
-title -- article title
-intro -- article introduction
-content -- article body
-publishdate -- date of launch
-artigosts -- this will work as our fts index.
创建表后,我运行:
UPDATE artigos SET artigosts =
setweight(to_tsvector('pg_catalog.portuguese', coalesce(title,'')), 'A') ||
setweight(to_tsvector('pg_catalog.portuguese', coalesce(intro,'')), 'B') ||
setweight(to_tsvector('pg_catalog.portuguese', coalesce(content,'')), 'C');
CREATE INDEX artigosts_idx ON artigos USING gist (artigosts);
CREATE TRIGGER artigosts_tg
BEFORE INSERT OR UPDATE ON artigos
FOR EACH ROW EXECUTE PROCEDURE
tsvector_update_trigger('artigosts', 'pg_catalog.portuguese', 'title', 'intro', 'content');
是的,我打算对搜索使用简单的加权。做了一个索引来加速,一个触发器,所以我可以插入和更新,而不用担心重新制作索引等等。
嗯,根据我的理解,一切都很好。但结果并非如此。一个简单的例子。
假设我有 "... banco de dados ... no banco ..." 作为一篇文章内容。当我这样做时:
SELECT title, intro, content FROM artigos WHERE plainto_tsquery('banco de dados') @@ artigosts;
它返回一个空集。我检查了 ts_vector 列并看到了谓词“banc”和“dad”。但我仍然不明白为什么它不返回包含所提到文章的行。
有人能解释一下这个问题吗?
【问题讨论】:
-
正在使用服务器上可用的不同配置。我认为这是可用字典和单词停止的问题。有谁知道如何将上层字符(如 áéóôú)映射到向量?
标签: postgresql internationalization full-text-search full-text-indexing