Re: scoring/sorting db search results based on score
| From: | Marek Kilimajer | Date: | Mon, 21 Jul 2003 10:11:14 +0000 |
| Subject: | Re: scoring/sorting db search results based on score | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-156034@lists.php.net to get a copy of this message | ||
I use mysql, so this was for mysql - LIKE is case insesitive and returns 0 for false and 1 for true.
Dean E. Weimer wrote:
Try SELECT ...., (((keywords LIKE '%$search%') * 5) + ((title LIKE '%$search%') * 3) + (description LIKE '%$search%')) score FROM ..... ORDER BY score DESCPostgreSQL cannot type cast the Boolean type so you have to use a case statement, also changing like to ilike will get results regardless of case. SELECT ...., ((CASE WHEN (keywords ILIKE '%$search%') THEN 5 ELSE 0 END) + (CASE WHEN (title ILIKE '%$search%') THEN 3 ELSE 0 END) + (CASE WHEN (description ILIKE '%$search%') THEN 1 ELSE 0 END)) AS score FROM .... ORDER BY score DESC