Question

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.

Was it helpful?

Solution

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top