RE: [PHP] scoring/sorting db search results based on score
| From: | Dave [Hawk-Systems] | Date: | Thu, 17 Jul 2003 17:44:15 +0000 |
| Subject: | RE: [PHP] scoring/sorting db search results based on score | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-155657@lists.php.net to get a copy of this message | ||
Appreciate the responses...
>> Try
>> SELECT ...., (((keywords LIKE '%$search%') * 5) + ((title LIKE
>> '%$search%') * 3) + (description LIKE '%$search%')) score FROM .....
>> ORDER BY score DESC
>
>PostgreSQL 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
We are talking a db of under 10k records where the search would take place on.
what are the ramifications of this as a load on the postgres server? Wouldn't
want to have a great search query that grinds the server to a halt everytime
someone searches regardless of the accuracy of the end result :)
Thanks
Dave