postgresql文本搜索中的部分对比完全匹配排名

问题描述 投票:0回答:1

我正在尝试使用PostgreSQL实现增量搜索。我遇到的问题是结果排名。我希望完整比赛的排名高于部分比赛,但我真的不知道该怎么做。例如,在此查询中(以显示用户输入查询时事物的排名):

select
    ts_rank_cd(to_tsvector('hello jonathan'), to_tsquery('jon:*')),
    ts_rank_cd(to_tsvector('hello jonathan'), to_tsquery('jonath:*')),
    ts_rank_cd(to_tsvector('hello jonathan'), to_tsquery('jonathan:*'))

或反之(以显示不同文档如何对同一查询进行排名)

select
    ts_rank_cd(to_tsvector('hello jon'), to_tsquery('jon:*')),
    ts_rank_cd(to_tsvector('hello jonah'), to_tsquery('jon:*')),
    ts_rank_cd(to_tsvector('hello jonathan'), to_tsquery('jon:*'))

所有排名均返回0.1。我将如何使更完整的结果排名更高?

postgresql full-text-search postgresql-9.4
1个回答
0
投票

我会尝试使用pg_trgm中的运算符来打破ts_rank_cd之间的联系。也许“ >>”运算符(在v11中引入)将是我的首选:

select
    'hello jon' <->>>  'jon:*',
    'hello jonah' <->>> 'jon:*',
    'hello jonathan'<->>>'jon:*';
 ?column? |  ?column?  | ?column? 
----------+------------+----------
        0 | 0.57142854 |      0.7

请注意,这返回的是距离,而不是相似度,所以越低越好。

© www.soinside.com 2019 - 2024. All rights reserved.