Re: Rating results after relevance. Difficult problem

From: Date: Wed, 08 May 2002 23:50:32 +0000
Subject: Re: Rating results after relevance. Difficult problem
References: 1  Groups: php.db php.general 
Request: Send a blank email to php-general+get-96715@lists.php.net to get a copy of this message
maybe it would speed up the whole thing if the DB itself would do all the calculations... here an example how this can be done.. (with mysql)... select news.id, if (news.text_short like '%test%', 50, 0) + if (user.name like '%woodoo%', 50, 0) as rating from news, user where user.id = news.creator order by rating DESC; explanation: > if (news.text_short like '%test%', 50, 0) returns 50 when in the field text_short the string "test" is found... else 0 is returned > + if (user.name like '%woodoo%', 50, 0) the same... just for the name.... the result of this is simply be added to the first result the result for this query looks like this: +----+--------+ | id | rating | +----+--------+ | 1 | 100 | | 8 | 100 | | 9 | 100 | | 10 | 100 | | 11 | 100 | | 2 | 50 | +----+--------+ so simply use PHP to build the query... and let the DB do the rest... so you've just to do 1 query and you can directly output the result.. ;-) Best regards, Sven

« previous php.general (#96715) next »