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

Alt category and Priority links don't like each other!

Quote Reply
Alt category and Priority links don't like each other!
Whoa, I just added a sample priority link to one of my categories yesterday, and placed the same link in a few other alternate categories for visibility. The database ran its nightly build, and I checked this morning to find quite a mess.

The categories with the alternate priority links were a combination of alphabetical order, reverse cool order, no order, and the priority link at the end... The main category for the priority link showed up fine.

I promptly removed the alternate categories and rebuilt, so I can't show you the bad output, but here's what the normal non-alt page looks like:

http://www.run-down.com/Training_Resources/

Here are my sort orders:

# The default sort orders for links.
# distribution - "isNew,isPopular,Title";
$LINKS{build_sort_order_category} = "Priority DESC,isNew,Title";
$LINKS{build_sort_order_new} = "Priority DESC,Title,Add_Date";
$LINKS{build_sort_order_cool} = "Priority DESC,Title";
$LINKS{build_sort_order_search} = "isNew,Title,isPopular";

And my Priority field table definition:
Type: INT
Form Length: 10
Max Length: 20
Not Null: Yes
Default Value: 0
Validation: ^\d*\.?\d*$
Weight: 3

Any ideas what may have caused that to go haywire?

Dan
Quote Reply
Re: Alt category and Priority links don't like each other! In reply to
This has been reported.... and is the infamous sort-order bug.

I've thought about making a real kludge to use a temporary table to hold the links, then re-sort and send them back. The reason is how the hash is combined.

If you don't use alt links, there is no problem. Depending on how many you do use, it can be a mess!

I have some categories that are purely alternates, and my "real" links show up at the END Of the list --- even though it looks like they should be first.

Anyway, the problem is in the build_category routine, where it makes the call to:

Code:
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;
my @c = sort { lc join ("", @{$a}[@fields]) cmp lc join ("", @{$b}[@fields]) } @{$arr_b}, @{$arr_a};
return \@c;
}

If this routine is re-written to put all the links into a temporary table, or insert them into an empty table, then extract them again with the build_sort_order, and return that hash, you'll probably get the right answer. I haven't done it.... since Alex is rewriting the sort and search routines at last report.

Actually, it's probably _better_ to change the build_category routine to extract the links into a temporary table, then extract them again, and just skip the call to this routine.

Leave this routine intact, since it might be useful in other situations.

Instead of the
$get_links = $LINKDB->prepare and
$get_alt = $LINKDB->prepare

Statements, that are then
$get_links->execute ($category_r->{'ID'});
$get_alt->execute ($category_r->{'ID'});

And fetched and turned into hashes of hashes,
the statement would be something like:

Code:
INSERT INTO Temp_Table
SELECT * FROM Links WHERE CategoryID = $category_r->{'ID'} LIMIT 1000
Code:

and then follow that with a:

Code:
INSERT INTO Temp_Table
SELECT l.* FROM Links as l, CategoryAlternates as c WHERE l.ID = c.LinkID AND c.CategoryID = $category_r->{'ID'} LIMIT 1000


The "ORDER" parameter doesn't work in the insert/select combination.


Happy hacking Smile

Quote Reply
Re: Alt category and Priority links don't like each other! In reply to
BTW --- I know I don't have to say it, but the above is in no way guaranteed to work, or even be accurate! It's only a good guess, and a place to start.

Quote Reply
Re: Alt category and Priority links don't like each other! In reply to
Oh, I must've mis-read the sort order bug... For some reason I thought that was just for searches, not categories. I guess this is nothing specific to the alt categories and Priority field, then.

Not much urgency on my part to incorporate alt categories, so I'll probably wait to see what Alex comes up with. Thanks for taking the time to explain it, though.

Thanks,
Dan