mysql按照字段相关性查找,我如何操纵MySQL全文搜索相关性使一个字段比另一个字段更“有价值”?...

Suppose I have two columns, keywords and content. I have a fulltext index across both. I want a row with foo in the keywords to have more relevance than a row with foo in the content. What do I need to do to cause MySQL to weight the matches in keywords higher than those in content?

I'm using the "match against" syntax.

SOLUTION:

Was able to make this work in the following manner:

SELECT *,

CASE when Keywords like '%watermelon%' then 1 else 0 END as keywordmatch,

CASE when Content like '%watermelon%' then 1 else 0 END as contentmatch,

MATCH (Title, Keywords, Content) AGAINST ('watermelon') AS relevance

FROM about_data

WHERE MATCH(Title, Keywords, Content) AGAINST ('watermelon' IN BOOLEAN MODE)

HAVING relevance > 0

ORDER by keywordmatch desc, contentmatch desc, relevance desc

解决方案

Actually, using a case statement to make a pair of flags might be a better solution:

select

...

, case when keyword like '%' + @input + '%' then 1 else 0 end as keywordmatch

, case when content like '%' + @input + '%' then 1 else 0 end as contentmatch

-- or whatever check you use for the matching

from

...

and here the rest of your usual matching query

...

order by keywordmatch desc, contentmatch desc

Again, this is only if all keyword matches rank higher than all the content-only matches. I also made the assumption that a match in both keyword and content is the highest rank.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值