正如您所指出的,您可以连接 tsvector:
# select to_tsvector('job description') ||
to_tsvector('company as keyword') ||
to_tsvector('job description as body') as vector;
vector
-----------------------------------------------------------
'bodi':9 'compani':3 'descript':2,7 'job':1,6 'keyword':5
(1 row)
您还可以为它们分配权重:
# select (setweight(to_tsvector('job description'), 'A') ||
setweight(to_tsvector('company as keyword'), 'B') ||
setweight(to_tsvector('job description as body'), 'D')) as vector;
vector
---------------------------------------------------------------
'bodi':9 'compani':3B 'descript':2A,7 'job':1A,6 'keyword':5B
(1 row)
你也可以玩弄ts_rank_cd()
. 特别是,您可以更改分数归一化的方式。
http://www.postgresql.org/docs/current/static/textsearch-controls.html
在您的情况下,您似乎想要组合两个单独的查询。一个丑陋但可能足够的解决方案可能如下所示:
select sum(rank) as rank, ...
from (
select ...
union all
select ...
) as sub
group by ...
order by sum(rank) desc
limit 10
如您所见,它不是很漂亮。它也是聚合潜在的大量匹配行的大道。恕我直言,如果需要,您最好坚持使用内置的 tsvector 算法并调整权重。