mysql 匹配程度,MySQL - 使用部分词汇匹配和相关度得分进行高效搜索(FULLTEXT)...

How can I do a MySQL search which will match partial words but also provide accurate relevancy sorting?

SELECT name, MATCH(name) AGAINST ('math*' IN BOOLEAN MODE) AS relevance

FROM subjects

WHERE MATCH(name) AGAINST ('math*' IN BOOLEAN MODE)

The problem with boolean mode is the relevancy always returns 1, so the sorting of results isn't very good. For example, if I put a limit of 5 on the search results the ones returned don't seem to be the most relevant sometimes.

If I search in natural language mode, my understanding is that the relevancy score is useful but I can't match partial words.

Is there a way to perform a query which fulfils all of these criteria:

Can match partial words

Results are returned with accurate relevancy

Is efficient

The best I've got so far is:

SELECT name

FROM subjects

WHERE name LIKE 'mat%'

UNION ALL

SELECT name

FROM subjects

WHERE name LIKE '%mat%' AND name NOT LIKE 'mat%'

But I would prefer not to be using LIKE.

解决方案

I obtained a good solution in this (somewhat) dupliate question a year later:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值