I have the following query:
SELECT * FROM table_name
WHERE (col_1 LIKE '%$keyword%'
OR col_2 LIKE '%$keyword%'
OR col_3 LIKE '%$keyword%')
AND .... <some optional filters> ...
is there a strategy to sort based on the most relevant results?
When you talk about “relevance”, you really want natural language search, which is supported by MySQL full-text searches. The syntax is different than normal like queries, and you need to add a special index to the table, but ordering by relevance is possible this way.
Here’s how MySQL computes relevance (from the link):
To create a full-text index on an existing table, use the FULLTEXT modifier:
Then you can perform a query like this to retrieve results in order of relevance: