Forum Moderators: coopster
I am trying to have a directory of businesses on my site, but I do not just want to rank via most hits or last viewed or clicked. I want to make a ranking algorithm like a search engine.
How does one go about creating a ranking algorithm in PHP and then order the data in a database based on the calculated weightage from the various rules.
For eg:
Business has website? if yes then 2 points or -1 if no
Business is verified? if yes then 3 points or -1 if no
Business has uploaded logo? then 2 point or -1 if no
then the total points for a listing is computed and then the results are ranked based on score.
Any pointers anyone?
Thanks!
-- Ashish
Did you find a solution for this? I would assume you would need to use sessions and total up as you go along, based on what input was entered. Then enter the total into the database with the rest of the information that was gathered. Then it would be a simple case of ordering by total.
dc
$query=mysql_query("select id, website, verified, logo from business");
while ($aquery=mysql_fetch_array($query))
{
$points=0;
$id=$aquery['id'];
$website=$aquery['website'];
$verified=$aquery['verified'];
$logo=$aquery['logo'];
$array[$id]['website']=$website;
//wesite
if (!empty($website)){
$points=$points+2;
}
else
{
$points=$points-1;
}
//verified
if ($verified==1){
$points=$points+3;
}
else
{
$points=$points-1;
}
//logo
if (!empty($logo)){
$points=$points+2;
}
else
{
$points=$points-1;
}
$business[$id]=$points;
}
//sort array
arsort($business, SORT_NUMERIC);
//create array with business ids
foreach ($business as $key => $row) {
$ids[]=$key;
}
now you have an array with ids sorted by rank
Thank you for enquiring. :)
and panos thank you for the reply.
I wrote a script that basically does what panos described, only it updates the score in the DB for each listing. I am now running that script weekly to compute the score.
sort of my own weekly google dance! ;)
I was wondering if any one else has any better idea or way to reduce the intensity of the task. it takes long/load currently.
Thanks again!
it takes long/load currently.
Instead of recalculating all 35,000 at one time, split up the task into more manageable chunks. Here's some different ideas for how to do that.
I especially love the timestamp idea I am combining that with everytime a record is changed.
Since the rank is based on information given by the user, everytime they update their profile, the rank gets updated and the timestamp will assign a rank to the existing ones. :)
I cant thank you enough, for helping me see the obvious! :)