问题
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