Gossamer Forum
Home : Products : Gossamer Links : Discussions :

build_search_gb bug

Quote Reply
build_search_gb bug
I have spent a lot of time performing searching lately and I have this strange behavior to report.
My build_sort_order_search and build_sort_order_search_cat are set as score.

This is either a logic error when grouping links by category in Search.pm or is somehow mixed up via query or query_sth

Example 1
http://www.supportmusicians.com/...ubstring=0&mh=10

Page 1 lists
Bands & Musicians - Alternative
- Easy Chair
Bands & Musicians - Blues
- Jon Justice Band
Bands & Musicians - Country
- Bear Creek Band
- Twain Trax
- Boogie Junction
Bands & Musicians - Rock - Pop
- Big Noise in the Corner
- Tamara Pierce Band
- 3 Chords & The Truth
Lights & Sound
- MAEURA MUSIC WORKS
Music Venues
- The Rave

Page 2 lists...
Bands & Musicians - Blues
- Jon Justice Band

Bands & Musicians - World
- RGB World, Inc.

Item in red is duplicate from page 1 and doesn't belong here at all.
Also message says 12 matches. Should be 11 matches.

Example 2
http://www.supportmusicians.com/...and;substring=0;mh=5

Page 1 lists
Bands & Musicians - Alternative
- Easy Chair
Bands & Musicians - Blues
- Jon Justice Band
Bands & Musicians - Country
- Bear Creek Band
- Twain Trax
- Boogie Junction THIS LINK *DOESNT* SHOW HERE AND IT SHOULD
Bands & Musicians - Rock - Pop THIS CATEGORY DOESNT BELONG HERE
- Big Noise in the Corner THIS LINK DOESNT BELONG HERE EITHER

Page 2 lists...
Bands & Musicians - Country CATEGORY IS OUT OF ORDER. IT IS ON PREV PAGE ALREADY
- Boogie Junction OH HERE IS THE MISSING LINK FROM PREV PAGE
Bands & Musicians - Rap - Hip Hop
- mcnatural
Bands & Musicians - Rock - Pop
- Tamara Pierce Band
- 3 Chords & The Truth


Example 3
The only change from Example 2 is mh=5 changed to mh=3
http://www.supportmusicians.com/...substring=0&mh=3

Page 1 lists
Bands & Musicians - Alternative
- Easy Chair
Bands & Musicians - Blues
- Jon Justice Band
Bands & Musicians - Rock - Pop THIS CATEGORY AND LINK SHOULD BE ON LAST PAGE
- Big Noise in the Corner

Page 2 lists...
Bands & Musicians - Country
- Bear Creek Band
- Twain Trax
- Boogie Junction

Page 3 lists...
Bands & Musicians - Rap - Hip Hop
- mcnatural
Bands & Musicians - Rock - Pop CATEGORY IS IN CORRECT PLACE
- Tamara Pierce Band
- 3 Chords & The Truth

So you can see that the grouping or ordering of the Links and Categories is wrong.

I happen to have a fresh copy of the grouping code from Search.pm handy
Code:
# And format the link results.
my (@link_results_loop, $link_results, %link_output);
if ($link_count) {
my $results = $link_sth->fetchall_hashref;
$links->add_reviews($results);
@link_results_loop = map Links::SiteHTML::tags('link', $_) => @$results unless $CFG->{build_search_gb};
if ($CFG->{build_search_gb}) {
my @ids = map { $_->{ID} } @$results;
my $catlink = $DB->table('CatLinks','Category');
my %names = $catlink->select('LinkID', 'Full_Name', { LinkID => \@ids })->fetchall_list;
foreach my $link (@$results) {
push @{$link_output{$names{$link->{ID}}}}, Links::SiteHTML::tags('link', $link);
}
}
}

# Join the link results by category if we are grouping.
if ($CFG->{build_search_gb}) {
foreach my $cat (sort keys %link_output) {
$link_output{$cat}->[0]->{title_linked} = sub { Links::Build::build('title_linked', { name => $cat, complete => 1, home => 0 }) };
$link_output{$cat}->[0]->{title_loop} = Links::Build::build('title', $cat);
push @link_results_loop, @{$link_output{$cat}};
}
}
$link_results = sub {
my $links;
$CFG->{build_search_gb} or return join("", map { Links::SiteHTML::display('link', $_) } @link_results_loop);
foreach my $cat (sort keys %link_output) {
my $title = Links::Build::build('title_linked', { name => $cat, complete => 1, home => 0 });
$links .= "<p>$title" . join("", map { Links::SiteHTML::display('link', $_) } @{$link_output{$cat}});
}
return $links;
};

Please let me know if this is a bug or operator error.
This bug affects my search by zipcode plugin as well, but it is also apparent in Advanced search.

Thanks
Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] build_search_gb bug In reply to
Bump.

Sorry for the impatience, but this grouping problem affects my plugin and it would be nice to get it resolved so I can release my plugin :-)

Thanks,
Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] build_search_gb bug In reply to
There seems to be a bug in the code when there's any paging. I'll take a look at it tomorrow.

Adrian
Quote Reply
Re: [brewt] build_search_gb bug In reply to
Please let me know when you have had time to look at this and post the fix if you do not mind.

Thank you
Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [brewt] build_search_gb bug In reply to
I've been looking at the group by code and it looks like it's working the way it was written to work. The category grouping is done after the results have been fetched from the database (this includes sort ordering), so this means that links from the same category can be on separate pages.

The strange problem with the duplicate link is actually caused by the results not being sorted in the SQL query when doing paging. That's due to the build_sort_order_search option being set to an invalid column (well the default is only valid if you're using indexing). I'll have to get Bruce to add a note about this in the manual.

Adrian
Quote Reply
Re: [brewt] build_search_gb bug In reply to
What???? Please try explaining your answer better. I still say it is a bug and should be fixed.

Quote:
I've been looking at the group by code and it looks like it's working the way it was written to work.
Then please explain why it was written to work the way it is. It is broke IMHO.

Are you saying I can't have the Categories 'alphabetical' and the Links 'alphabetical' within the Categories?

I set my search option settings at:
build_sort_order_search = Title
build_sort_order_search_cat = Full_Name

This is suppossed to be ordered this way with those settings?
These results order makes absolutely no sense to me.
http://www.supportmusicians.com/...query=band&Go=Go

Page 1 lists
Bands & Musicians - Alternative
- Easy Chair
Bands & Musicians - Country
- Bear Creek Band
- Boogie Junction

Bands & Musicians - Rock - Pop
- 3 Chords & The Truth
- Big Noise in the Corner

Page 2 lists
Bands & Musicians - Blues
- Jon Justice Band
Bands & Musicians - Country
- Twain Trax
Bands & Musicians - Rap - Hip Hop
- mcnatural
Bands & Musicians - Rock - Pop
- Tamara Pierce Band


There is no way this can be right.
I change the search option for search_maxhits from 5 in prev url to 3 and now I get this.
These results are radically different than the ones above.

Page 1 lists
Bands & Musicians - Country
- Bear Creek Band
Bands & Musicians - Rock - Pop
- 3 Chords & The Truth
- Big Noise in the Corner

Page 2 lists
Bands & Musicians - Alternative
- Easy Chair
Bands & Musicians - Blues
- Jon Justice Band

Bands & Musicians - Country
- Boogie Junction

Page 3 lists
Bands & Musicians - Country
-
Twain Trax
Bands & Musicians - Rap - Hip Hop
- mcnatural
Bands & Musicians - Rock - Pop
- Tamara Pierce Band


FYI, this is what I want to be able to do. Categories are Alphabetical, then Links Alphabetical. Sounds simple :-)
Page 1 lists
Bands & Musicians - Alternative
- Easy Chair
Bands & Musicians - Blues
- Jon Justice Band

Bands & Musicians - Country
- Bear Creek Band

Page 2 lists
Bands & Musicians - Country (continued)
- Boogie Junction
- Twain Trax
Bands & Musicians - Rap - Hip Hop
- mcnatural


Page 3 lists
Bands & Musicians - Rock - Pop
- 3 Chords & The Truth
- Big Noise in the Corner
- Tamara Pierce Band

Quote:
The category grouping is done after the results have been fetched from the database (this includes sort ordering), so this means that links from the same category can be on separate pages.
I don't understand...
If the sorting is done first, and I have specified 'Title' for
build_sort_order_search, then the links should be in this order when "the results have been fetched from the database". If I turn off grouping, the links ARE in the following order!
Which again tells me that build_search_gb is incorrectly written. This is how it *should* work.

Sort the matching results into build_sort_order_search (Title)
- 3 Chords & The Truth (Rock)
- Bear Creek Band (Country)
- Big Noise in the Corner (Rock)
- Boogie Junction (Country)
- Easy Chair (Alternative)
- Jon Justice Band (Blues)
- mcnatural
(Rap)
- Tamara Pierce Band (Rock)
- Twain Trax (Country)

Now to group by category...
Sort the categories into
build_sort_order_search_cat (Full_Name)
Bands & Musicians - Alternative
Bands & Musicians - Blues
Bands & Musicians - Country
Bands & Musicians - Rap - Hip Hop
Bands & Musicians - Rock - Pop

Finally, Insert the results from the top-down, into the appropriate category.
This would give the results expected.

I do not have the knowlege to fix this.
If you are going to look into this further, that would be great. If not, I will have to disable the feature.

Thanks
Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] build_search_gb bug In reply to
Links are retrieved from the database sorted by whatever you tell it to sort by (eg. Title). However, if there are more than mh links, then only mh links are fetched (assume first page). Then from those links, they are grouped by category in the code. This, unfortunately, isn't the best way of doing it (and depending on how you think of how it should be done, incorrect), but it's how it's been done since it was written, and we can't really change it now.

Adrian
Quote Reply
Re: [brewt] build_search_gb bug In reply to
Thanks for the great explaination. It is working exactly the way you said, and I am able to use the mh=3 sample above to visually verify it.

Quote:
This, unfortunately, isn't the best way of doing it (and depending on how you think of how it should be done, incorrect), but it's how it's been done since it was written, and we can't really change it now.

Not the answer I was looking for. Frown
I think the majority of users would like to see this corrected. It would be interesting to take a poll.
As for depending on how I think it should be done,... The current method might as well be random. It certainly isn't "grouped" by even a loose interpetation of the word. Laugh

It may not be easy to correct, but "can't" usually means won't. I am voicing my opinion on the matter because I still think it should be fixed. It affects EVERY paging function throughout this software, including Cool Links, New Links, Searching etc... any where that grouping is done.

query and query_sth should to be rewritten so that they...
1) Perform the entire search
2) Sort the Link results on
build_sort_order_search
3) Sort the Categories on build_sort_order_search_cat
4) Insert the Links into the sorted categories
5) Then return mh number of Links from the final order.

I am just a rookie though and I am sure it is more complicated than that.

Thanks
Chris



RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] build_search_gb bug In reply to
Does anybody know if the GT Team is working to fix this bug....?

I used links 2.0 for years before coming to Links SQL and I donīt know why in links 2.0 the way or sort the links in a after a search query works as most of us expected (I mean, give the results sorted by full_name category and if in each category were more than one link they were sorted by title)

I didnt`t notice this bug till a few weeks ago, and I thought taht it was my fault for not configure properly de build_search_gb parameter. After making some changes and tries without success, I decide to check the MySQL sintax and I noticed that it doesn't work as it should be. So I think it should be re-rewriten to be fixed.

Do you know how can we assure that the GT team know the bug....? Should we post it in another forum or by e-mail..?

Toni
PD: Apologize for my 'very poor' english. It is not my mother language.
Quote Reply
Re: [tonisoto] build_search_gb bug In reply to
We know about this issue, but due to how the code is currently structured, it would require huge changes to GT::SQL to make it work. This is on our todo list, but is very low priority since there isn't that big of a demand for it.

Adrian