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

Query Search in one Category only

Quote Reply
Query Search in one Category only
Hi there, I've tried searching the forum for this problem and can't find it, so my apologies if this question has already been asked.


Here's the problem:

I want to do a query search and allow the user to specify the CategoryID to be searched. For example: I want to search a category called Santa Fe(CategoryID=4) for my query on wood. What I get in return is 1 match. That's it. There are definitely more wood hits in that category. It has been working fine until I re-indexed the site and that's when this problem started. I though it may have been due to some mod that I made, but I've also found it to be the case in the demo version of Links SQL.

The query I used for testing on the demo site: http://gossamer-threads.com/perl/links-sql/search.cgi?query=foil&CategoryID=1261&substring=1

This category definitely has at least 2 links in it with the word foil in the description or in the title.

Anybody have any ideas?

Thanks,

Kyle Langan

Quote Reply
Re: Query Search in one Category only In reply to
This has been discussed before in this forum...search for category search. The only solution provided works for versions before Links v1.11. The MOD does not work in Links v.1.11. There are some Links SQL users who are attempting to do this in Links v.1.11, but I don't think any success stories have been posted.

Regards,

Eliot Lee

Quote Reply
Re: Query Search in one Category only In reply to
Thanks for your quick reply Eliot, but the thing I can't understand is why it's been working for the last 6 months until today when I re-indexed.

Anybody else?

Quote Reply
Re: Query Search in one Category only In reply to
Probably...because you made changes to your .def files and didn't re-weight your Links table via the Edit Table Definitions option in the editor.cgi script.

Regards,

Eliot Lee

Quote Reply
Re: Query Search in one Category only In reply to
Yeah Eliot, making sure my fields were indexed was the first thing I checked in both the Links table and the Category table, and I've verified by looking at the .def file to make sure that every column has a weight of 0 or greater so I'm sure that's not the problem, also a search without the CategoryID brings back the hits I would expect to get back, so that's another indicator that it is working.

So, why does it return 1 link. Why not 0? It's obviously doing the search, but it's stopping after 1 link hit, and I can't figure out why it appears to stop at that point.

Peace.

Kyle

Quote Reply
Source of Category Search problem? In reply to
Okay, I've had a chance to look over most of the other posts related to this topic. Thanks Eliot for turning me on to the search term - big help.

I have a lot riding on this feature because it's been working for so long and my users have come to rely on this feature so it's very important to this website.

I think I've discovered the source of the problem, but I need the help of gossamer-threads to fix it. After having spent 10 hours trying figure out why this is happening. I felt there must be something in the sub query in search.pm that's causing this problem so I divided and conquered and this is what I found.

In search.pm sub query there is this set of routines.

my $sth = $self->{dbh}->prepare ( $query );
$sth->execute ();
my $row;
my %needed = map { $$_[0] => 1 } @query_results;
foreach $row ( $sth->fetchrow_hashref () ) {
delete $needed { $$row { $id_col } };
}
foreach $row ( keys %needed ) {
delete $$id_results { $row };
}
#AS SOON AS THE FOLLOWING LINE IS COMPLETED THE DATA GETS LOST.
@query_results = sort { $$b[1] <=> $$a[1] } map ( [$_, $$id_results {$_} ], keys %$id_results );

So, The query results before this point are fine, but once this set of routines gets run, the query results get dropped from all the appropriate hits to just one (something to do with delete $$id_results { $row }; - I think).
I temporarily commented out that line and my results were as expected but then I got this error:

Can't use an undefined value as an ARRAY reference at admin/Links/Search.pm line 935.

And now I'm way in over my head.

Can anyone take this from here? I'll be happy to post whatever code I need to to get this up and working again.

I created some debugging output, which contained the contents of $query and these were the results that led me here :
Line 724 - SELECT count(*) FROM Artisans WHERE ID in (125,118,87) and (( CategoryID = "1"))
Line 733 - SELECT ID FROM Artisans WHERE ID in (125,118,87) and (( CategoryID = "1"))
Line 748 - SELECT ID FROM Artisans WHERE ID in (125,118,87) and (( CategoryID = "1"))
results before the @query_results = (posted above)
Line 754 - SELECT ID FROM Artisans WHERE ID in (118) and (( CategoryID = "1"))
results after the @query_results =
Line 796 - SELECT
ID,Title,URL,Add_Date,Mod_Date,CategoryID,Description,Contact_Name,Contact_Email,Hits,isNew,isChanged,isPopular,Rating,Votes,ReceiveMail,Status,Date_Checked,Street,Company,City,County,State,Zip,Phone,Fax,Performing_Arts,Visual_Arts_and_Crafts,Literary_Arts,Media_Arts,Applied_Arts,Services,Statement,Availability,Education,Languages,Awards,Owner,First_Name,Middle_Name,Last_Name,Public,Visible,Template,Detail_Template,Image,Thumbnail,Username,isActive,Gender
FROM Artisans WHERE ID in (118) and (( CategoryID = "1"))

Hope I explained this well enough.

Thanks and peace.

Kyle