Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Sort question in category, new and cool

Quote Reply
Sort question in category, new and cool
Hello all,

I wanna sort the links to add_date with the newest first in new,cool,category and in search mode.

So i looked in this forum and i modify code in links.pm to this:

$LINKS{build_sort_order_category} = "Add_Date DESC";
$LINKS{build_sort_order_new} = "Add_Date DESC";
$LINKS{build_sort_order_cool} = "Add_Date DESC";
$LINKS{build_sort_order_search} = "Add_Date DESC";


Now start my problems :), it don't work good.

Category pages:
In static mode it sort the links but the highest is below instead of up in the list.
In dynamic mode it sort very strange, low date, high date, low date no logic in it.

When i have a span page (i set it to 50 links on a page) it's different then i told before, how strange :).

New and cool page looks ok but i have tested it enough.

In Search mode:
Sorts very strange, low date, high date, low date no logic in it.

Does any know what is wrong?

Allready thanks.

Regard Startpoint.

Quote Reply
Re: Sort question in category, new and cool In reply to
In Reply To:
Category pages:
In static mode it sort the links but the highest is below instead of up in the list.
In dynamic mode it sort very strange, low date, high date, low date no logic in it.
Well it seem like the alternatecategory links (which i really need!) is messing up the sort thing on the category pages. I haven't figured it out why this happen but when i don't use altercategory links it sort ok in static and dynamic mode. Maybe someone know why it's messed up when using alternatecategory links and how to fix it?

I have found a forum at:
http://gossamer-threads.com/perl/forum/showflat.pl?ubb=000590:Forum9 but there was no valid answer on it. I read about the new version it all will be better, but i have to finish my project in the current version 1.11.


In Reply To:
In Search mode:
Sorts very strange, low add_date, high add_date, low add_date no logic in it.
Maybe it sorts ok, but within category's. So when there are 4 links (2 links in 2 category) it sorts within the 2 category's. It will display the search like this:

cat1:
26-08-2000 link 2
30-01-2000 link 1

cat2:
21-10-2000 link 4
26-01-1999 link 3

But i want it sort this way (so highest add_date up and not sort within category's!):

21-10-2000 link 4
26-08-2000 link 2
30-01-2000 link 1
26-01-1999 link 3

Hope any can help me with it, allready thanks.

Regards Startpoint.
Quote Reply
Re: Sort question in category, new and cool In reply to
In Reply To:
alternatecategory links
I am still stuck on this sort thing. I can't figure it. :(

I search the forum over and over again and found many document but never a good solution. I really need it to work, how to handle this problem? Hope someone has fixed this bug allready?

Regards Startpoint.

Quote Reply
Re: Sort question in category, new and cool In reply to
Hello all,

I asked GS:Alex about the sort problem on the add_date in the category pages desc with alternative category links in the table links, but he didn't know it how to fix it. Well also a master can't know it all Smile.

So i though let's figure this out (got plenty of time, not!) and found this solution working somehow:

In nph_build.cgi sub build_sort_links replace this code:

my @c = sort { lc join ("", @{$a}[@fields]) cmp lc join ("", @{$b}[@fields]) } @{$arr_b}, @{$arr_a};

with this code:

my @c = sort { lc join ("", @{$b}[@fields]) cmp lc join ("", @{$a}[@fields]) } @{$arr_b}, @{$arr_a};

What it does is sort numerically descending so i quess it will not work on strings but i didn't test it out. Man i am so happy to solve my problem :)..

Case close....

Regards startpoint.

Quote Reply
Re: Sort question in category, new and cool In reply to
Oh no !!!!!!!!!! :(

I try to enter a other alternatieve category links and now it's doesn't have a good order..........

I am doomed.... sorry about prev. post i really did think it was solved.
Well maybe i did solve the desc order, but not the combine alternatieve links with links and then sort it on add_date.

Grrrrr..

Well i go give it a next shoot...

Regards startpoint.

Quote Reply
Re: Sort question in category, new and cool In reply to
I posted two theoretical solutions to this awhile back, when I first figured out what was going on.

Both solutions impose a speed/performance penalty.

You can copy all the found links to a temporary table, then re-extract them in order. If you are only building once a day, and not using a dynamic build for the site, this might be acceptable.

I actually forget what the other solution was, but two had occured to me at the time.

Since neither was elegant, or a long term solution, I didn't implement them.

I don't know anyone who has.

The problem seems to nest in the routine to sort two hashes, so that is the routine you'd want to rebuild. I forget which exactly,and I can't open my files from here (I just slit my finger on a kitchen slicer so I can't type too well either.)

When the two hashes are merged, the merge for some reason took on a pseudo-random order.

As I said, the best way is probably to SELECT the links and the ALT-LINKS into a temporary table, then select them out in theorder you want, then EMPTY the temporary table.

Problem: In a multi-user,multitasking environment you'd want to make sure only one process was writing to that table ie:ONE copy of the admin program was running the build at any given time. You really wouldn't want to use this for dynamic builds, since the number of tables could get quite large during busy times.

Any of this make sense?

There is no easy answer. I dare say 9 out of 10 users chose to give up the alt-links feature for now.

I don't know how it works in the next release, as not enough code was released last friday to know for sure.

But if you are looking for a solution to make this work, I don't know anyone who has implemented it (at least posted here).

It's a complex problem, in search of a complex answer. The best "solution" is to change the logic completely, and hopefully that has been done.

It doesn't prevent links from being listed in the multiple categories. It just prevents a strict-ordered listing from being done on them.

http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: Sort question in category, new and cool In reply to
Thanks for your reply pugdog!

I am stuck on this one for days....... But i really need this feature work in v1.11 and also in dynamic mode so your theoretical solutions isn't a option for me.

Ok listen this code is what i believe making the problem, it's in
page.cgi and nph-build.cgi

Quote:
sub build_sort_links {
# --------------------------------------------------------
# Merges two array refs into one link list.
#
my ($arr_a, $arr_b) = @_;
my @names = split /,/, $LINKS{build_sort_order_category};
my @fields = map { $LINKDB->position($_) - 1 } @names;
# was --> my @c = sort { lc join ("", @{$a}[@fields]) cmp lc join ("", @{$b}[@fields]) } @{$arr_b}, @{$arr_a};
my @c = sort { lc join ("", @{$b}[@fields]) <=> lc join ("", @{$a}[@fields]) } @{$arr_b}, @{$arr_a};
return \@c;
}
Quote:

This routine build_sort_links in page.cgi and nph-build.cgi is merging the links and alternative category links and will try to sort it.

The red code is what i have changed, because i change to order in the code (red) it will sort descending.
I found some usefull information about sort at:
http://www.perl.com/...d/perlfunc/sort.html.

I want to sort on add_date (so build_sort_order_category= "add_date") descending
and that's the problem i quess. Because the red code will not sort on dates ??

I don't know it for sure, but i quess that's the problem.

So maybe you can help me now ?

Allready thanks.

Regards startpoint.