如何让 postgresql 文本搜索在排名中使用搜索词顺序
以下 PostgreSQL 文本搜索,
select
ID, DISPLAY_NAME,
ts_rank_cd(to_tsvector('english', display_name), query) as RANK
from
my_table,
to_tsquery('english', 'John:*&Bernard:*') as query
where
to_tsvector('english', display_name) @@ query
order by RANK DESC
生成
ID DISPLAY_NAME RANK
=====================================
82683 "BERNARD JOHN SMBZh" 0.05
63815 "BERNARD JOHN []zkP" 0.05
68204 "BERNARD JOHN uPmYB" 0.05
29666 "John Bernard iECx" 0.05
44256 "John Bernard DpIff" 0.05
52601 "BERNARD JOHN ivRTX" 0.05
80250 "BERNARD JOHN b'nVp" 0.0430677
但我真正希望的是“John Bernard*”记录具有更高的排名,因为“文档”中的术语与查询的出现顺序相同。这可能吗?
例如这样的结果:
ID DISPLAY_NAME RANK
=====================================
29666 "John Bernard iECx" 0.10
44256 "John Bernard DpIff" 0.10
82683 "BERNARD JOHN SMBZh" 0.05
63815 "BERNARD JOHN []zkP" 0.05
68204 "BERNARD JOHN uPmYB" 0.05
52601 "BERNARD JOHN ivRTX" 0.05
80250 "BERNARD JOHN b'nVp" 0.0430677
干杯 克雷格
The following PostgreSQL text search
select
ID, DISPLAY_NAME,
ts_rank_cd(to_tsvector('english', display_name), query) as RANK
from
my_table,
to_tsquery('english', 'John:*&Bernard:*') as query
where
to_tsvector('english', display_name) @@ query
order by RANK DESC
produces
ID DISPLAY_NAME RANK
=====================================
82683 "BERNARD JOHN SMBZh" 0.05
63815 "BERNARD JOHN []zkP" 0.05
68204 "BERNARD JOHN uPmYB" 0.05
29666 "John Bernard iECx" 0.05
44256 "John Bernard DpIff" 0.05
52601 "BERNARD JOHN ivRTX" 0.05
80250 "BERNARD JOHN b'nVp" 0.0430677
but what I really would like is for the "John Bernard*" records to have a higher rank because the terms in the "document" appear in the same order as the query. Is this possible?
e.g. A result like this:
ID DISPLAY_NAME RANK
=====================================
29666 "John Bernard iECx" 0.10
44256 "John Bernard DpIff" 0.10
82683 "BERNARD JOHN SMBZh" 0.05
63815 "BERNARD JOHN []zkP" 0.05
68204 "BERNARD JOHN uPmYB" 0.05
52601 "BERNARD JOHN ivRTX" 0.05
80250 "BERNARD JOHN b'nVp" 0.0430677
Cheers
Craig
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您将不得不考虑与 tsearch 一起涉及另一种排名机制的解决方案,因为它 不处理短语。
怎么样:
生产:
I think you will have to consider a solution involving another ranking mechanism alongside tsearch as it does not handle phrases.
How about something like:
producing: