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

Max Cat Hits

Quote Reply
Max Cat Hits
Im not very good with perl. Basically I want to limit the number of category hits I get when doing a search.

Is this the right code to edit and where would I add the max="" so that only a certain number of category matches are found. I find it really annoying when I have 30 category hits staring me in the face.

--
# Only display the category output on the first page.
if ($nh == 1) {
if ($cat_hits) {
foreach my $hit (@$cat_hits) {
$hit = $catdb->array_to_hash($hit);
$category_results .= "<li>" . &search_build_linked_title ($hit->{Name}) . "\n";
}
}
}

Quote Reply
Re: Max Cat Hits In reply to
Hi,

yes it is the right code to modify. Try to insert a counter variabel to the foreach-loop.

# Only display the category output on the first page.
#
my $counter=0;
#
if ($nh == 1) {
if ($cat_hits) {
foreach my $hit (@$cat_hits) {
$counter ++;
$hit = $catdb->array_to_hash($hit);
$category_results .= "<li>" . &search_build_linked_title ($hit->{Name}) . "\n";
if ($counter >= 10) {last}
}
}
}
# you can use a variable instead of the "10"
# like $LINKS{max_cat_result} = 10;
# and define it in Links.pm
# change: if($counter >= $LINKS{max_cat_result}){last}

regards, alexander





Quote Reply
Re: Max Cat Hits In reply to
Thanks Alex works great. I have another question to ask. Lets say

If Max hits > 10 then display [MORE]

and when they click on more they get the full listing of catgories found on a seperate page. Would I just have another search.cgi but only have it build the category hits?

Thats the only way I can see it being done. I have no perl knowledge whats so ever.

Thanks
Jason

Quote Reply
Re: Max Cat Hits In reply to
The easiest way would be to just have the [more] link to the unmodified search.cgi and pass it the original query.



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

Quote Reply
Re: Max Cat Hits In reply to
Thanx pugdog you help with every question I have. I just would like to know if possible. Can I make [more] appear only when MAX CAT HITS is > 10. Like using the <%if%> statements for including or data if presents.


Thanks once again
Jason

Quote Reply
Re: Max Cat Hits In reply to
What I mean is can I do something like this

<%if "cat_hits<10">
[MORE]
<%endif%>

or some other sorta or code that will work.

Thanks again.
Jason

Quote Reply
Re: Max Cat Hits In reply to
You'd have to do it where you count the hits.

You'd want to do something like:

if ($counter <=10> {
$rec->{more}= 0
} else {
$rec->{more}= 1
}

and in the templates, you can use:

<%if more%>
<a href=.....>[more]</A>
<%endif%>



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