GBase 8c
其他
文章

GBase 8c解析文档(二)

发表于2023-12-06 17:23:3018次浏览1个评论

函数setweight可以给tsvector的记录加权重,权重是字母A、B、C、D之一。这通常用于标记来自文档不同部分的记录,比如标题、正文。之后,这些信息可以用于排序搜索结果。

因为to_tsvector(NULL)会返回空,当字段可能是空的时候,建议使用coalesce。以下是推荐的为结构化文档创建tsvector的方法:

gbase=#CREATE TABLE tsearch.tt (id int, title text, keyword text, abstract text, body text, ti tsvector);

gbase=#INSERT INTO tsearch.tt(id, title, keyword, abstract, body) VALUES (1, 'China', 'Beijing', 'China','China, officially the People''s Republic of China (PRC), located in Asia, is the world''s most populous state.');

gbase=#UPDATE tsearch.tt SET ti = setweight(to_tsvector(coalesce(title,'')), 'A') || setweight(to_tsvector(coalesce(keyword,'')), 'B') || setweight(to_tsvector(coalesce(abstract,'')), 'C') ||

setweight(to_tsvector(coalesce(body,'')), 'D'); gbase=#DROP TABLE tsearch.tt;

上例使用setweight标记已完成的tsvector中的每个词的来源,并且使用tsvector连接操 作符||合并标记过的tsvector值

评论

登录后才可以发表评论
用户头像
GBase用户28017发表于 6个月前
我的回复是以你最大的鼓励。