I'm trying to order my search results more accurately. I specify a search string - e.g. "Beijing Olympics"
- If the title column contains "Beijing Olympics" then the score 100 is added to the score, otherwise nothing is added
- If the shortDescription column contains "Beijing Olympics" then 50 is added to the score, otherwise nothing is added
- If the longDescription column contains "Beijing Olympics" then 10 is added to the score, otherwise nothing is added
In the end the maximum score possible per record would be 160 and I want the results to be ordered by highest score first and limited to a maximum of 10 results.
Below is definitely wrong, but it should illustrate what I am hoping to achieve!
SELECT
title,
id,
(
IF((match 'Beijing Olympics' against title)*100) +
IF((match 'Beijing Olympics' against shortDescription)*50) +
IF((match 'Beijing Olympics' against longDescription)*10)
) as score
from listings
order by score desc limit 10