For each rows, I want to get the relevance of each description compared to an undefined number of keywords. I know that "THEN +1" does not work, but I would like to come to this result (...to have a number (starting from 0 each rows) that is incremented for each keyword present)
SELECT *,
(CASE description LIKE '%keyword1%' THEN +1
description LIKE '%keyword2%' THEN +1
(...)
ELSE 0
END) as relevance_description
FROM (...)
ORDER BY relevance_description DESC
So, if a description contains "keyword1" and "keyword2", relevance_description should be 2 for this row.
You can do this with separate clauses, and add them together:
In some databases, booleans are treated as integers, so you could just write: