Gossamer Forum
Home : Products : Links 2.0 : Discussions :

For Alex.. BUG FIX

Quote Reply
For Alex.. BUG FIX
Hi Alex!

I've been modifying Links alot recently and I wanted to Sort my search results in Multiple ways..

go to: http://www.widgetz.com/index.htm (messy Smile) and search for "test" under software or in all..

you will see you can select any of them.. "date", "hits" etc..

in the process of making this mod.. I found that you couldn't sort the date or the hits correct.. hits would sort like this:

100000
1200
13000
150000
etc.. because it starts with the first number to the second.. so on..

anyways.. i think you should swap the current links sub build_sorthit in db_utils.pl to:

Code:
sub build_sorthit {
# --------------------------------------------------------
# This function sorts a list of links. It has been modified to sort
# new links first, then cool links, then the rest alphabetically. By modifying
# the sort function below, you can sort the links however you like (by date,
# or random, etc.).

my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, %isnew, %iscool, $hit, $i, @sorted, $column, $type);

foreach $column (@db_cols) {
if ($db_sort_links == $db_def{$column}[0]) {
$type = $db_def{$column}[1];
last;
}
}
for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
($unsorted[$db_isnew + ($i * ($#db_cols+1))] eq "Yes") and ($isnew{$i} = 1);
($unsorted[$db_ispop + ($i * ($#db_cols+1))] eq "Yes") and ($iscool{$i} = 1);
}
if ($type eq "date") {
foreach $hit (sort {
&date_to_unix ($sortby{$b}) <=> &date_to_unix ($sortby{$a})
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
}
elsif ($type eq "numer") {
foreach $hit (sort {
$sortby{$b} <=> $sortby{$a}
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
}
else {
foreach $hit (sort {
($isnew{$b} and !$isnew{$a}) and return 1;
($isnew{$a} and !$isnew{$b}) and return -1;
($iscool{$b} and !$iscool{$a}) and return 1;
($iscool{$a} and !$iscool{$b}) and return -1;
($isnew{$a} and $isnew{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
($iscool{$a} and $iscool{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
return lc($sortby{$a}) cmp lc($sortby{$b});
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
}
return @sorted;
}

what it does.. it finds out if the field is NUMER ALPHA or DATE.. that way it will sort properly..

that way if someone says:

$db_sort_links = 3; it will sort the date correctly.. and if they changed the number to the number for hits.. it will sort hits correctly..

tell me what you think!
jerry