Getting EXACT matches from full-text search returned first?

廉价感情. 提交于 2020-01-17 02:53:28

问题


I am using the below code for example:

SELECT *, (MATCH (`wm`, `locn`, `gns`) AGAINST('foot locker')) AS score FROM `example_table` WHERE MATCH (`wm`, `locn`, `gns`) AGAINST('foot locker')) order by score DESC;

However even though EXACT matches exist in the wm column, the EXACT match doesn't appear untiil the 8th result. The ones ahead of it all have the phrase too, but also some following text. I checked the locn, gns fields to see how they compared and nothing really stands out that should make the others score higher.

I did some reading about using BOOLEAN MODE but nothing I read there seemed like it would help my needs.


回答1:


Ok, if this helps anyone else I was able to achieve what I wanted by doing this:

SELECT *, 
  CASE WHEN wm = 'foot locker' THEN 1 ELSE 0 END AS score, 
  MATCH (`wm`, `locn`, `gns`) AGAINST('foot locker') AS score2 
FROM 
  `example_table` 
WHERE 
  MATCH (`wm`, `locn`, `gns`) AGAINST('foot locker')) 
ORDER BY
  score DESC, score2 DESC;


来源:https://stackoverflow.com/questions/7217887/getting-exact-matches-from-full-text-search-returned-first

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!