编辑:我的问题不清楚,所以我在这里重新表述:Order sql result by occurrence of a set of a keyword in a string
我正在改进我的网站的搜索系统。我正在尝试在sql请求中使用和增加变量,就像那样......
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
事实上,每次标题中有关键字时,titlematch 都应该增加。如果标题中有“apple”和“orange”,titlematch应该等于2。但实际上,它不起作用......
(对不起我的英语不好)