EDIT : my question is not clear, so I've reformulated it here : Order sql result by occurrence of a set of keywords in a string
I'm improving my search system for my website. I'm trying to use and increment variables in sql request, like that...
SET @titlematch = 0;
SELECT *,
CASE
when title like '%apple%' then (SET @titlematch = @titlematch+1)
when title like '%orange%' then (SET @titlematch = @titlematch+1)
when title like '%other_keyword_searched%' then (SET @titlematch = @titlematch+1)
(...)
END,
(...)
FROM pages
(...)
ORDER by @titlematch desc
In fact, titlematch should be incremented each time that a keyword is in the title. If there's "apple" and "orange" in the title, titlematch should be equal to 2. But actually, it doesn't work...
(sorry for my english)