Sunday 6 January 2013

How does one order results for a MySQL Query by how well they matched a given query.

How does one order results for a MySQL Query by how well they matched a given query.



Use the following ORDER rule


ORDER 
BY case when `ColumnName` LIKE 'FirstRelevance' then 1 else 0 end
+ case when `ColumnName` LIKE 'SecondRelevance' then 1 else 0 end
+ case when `ColumnName` LIKE 'ThirdRelevance' then 1 else 0 end
...
DESC


No comments:

Post a Comment