Gossamer Forum
Home : Products : Links 2.0 : Discussions :

Search results problem

Quote Reply
Search results problem
Hi all,
When I search and there are no matching results, the search page tells me this:
"Your search returned categories and links." Now I realize that this SHOULD read "Your search returned 0 categories and 0 links." How can I correct this problem?

Thanks!
Clark

------------------
Freshwebproduce - A web design & production co.
Walla Walla, Washington
http://www.freshwebproduce.com

Quote Reply
Re: Search results problem In reply to
Hi Clark,

In your search_results.html template, the appropriate line should read:

Your search returned <strong><%cat_hits%></strong> categories and <strong><%link_hits%></strong> Links.

Dan

p.s. Walla Walla, huh? You're not stranded with BMI are you...? Frown
Quote Reply
Re: Search results problem In reply to
Hi Dan,

I'm not using templates but in my site_html.pl file the applicable line is:

<p>Your search returned <strong>$cat_hits</strong> categories and <strong>$link_hits</strong> Links.</p>

The code is correct as far as I can tell. I guess I'm just looking for a way to make $cat_hits and $link_hits have a value of 0 if there actually are zero results.

Thanks!
Clark

PS. I USED to be one of the BMI faithful until server problems killed all my enthusiasm for them. E-mail servers being down for WEEKS at a time, etc. I'm with the only other local source: Highspeed.com (which used to be InternetNorthWest which used to be WWICS which used to be...)



[This message has been edited by ClarkP (edited March 09, 2000).]
Quote Reply
Re: Search results problem In reply to
There was a Mod written for templates that does this....

I will translate it to non-templates for site_html.pl:

Add the following codes in your sub site_html_search_results routine:

Code:
if (($cat_hits eq "0") && ($link_hits eq "0")) {
print qq~Your search returned 0 categories and 0 links.~ ;
}
else {
print qq~Your search returned $cat_hits categories and $link_hits links.~ ;
}

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Search results problem In reply to
Hi Eliot!

Thanks for your help on this. I cut and paste the new code into site_html.pl but get the following error when I try to "Build All":
Error including libraries: syntax error at /home/path/to/web/links/cgi-bin/admin/site_html.pl line 2145, near "print qq~Your search "
syntax error at /home/path/to/web/links/cgi-bin/admin/site_html.pl line 2147, near "else

I'm not a real Perl junkie unfortunately so I don't know enough about the sytax to pick up easy errors. Here is my code exactly as it is in the sub site_html_search_results routine of my site_html.pl file:

if (($cat_hits eq "0") && ($link_hits eq "0")) {
print qq~Your search returned 0 categories and 0 links.~ ;
}
else {
print qq~Your search returned $cat_hits categories and $link_hits links.~ ;
}

Did I do something easily fixable?

Thanks in advance,
Clark

Ps. Is there a time where there is a site found but no categories (and vice versa)? Would this code take care of it or would it then still leave one of the results blank instead of including a zero?

------------------
Freshwebproduce - A web design & production co.
Walla Walla, Washington
http://www.freshwebproduce.com



[This message has been edited by ClarkP (edited March 09, 2000).]
Quote Reply
Re: Search results problem In reply to
Uh...When you make changes to sub-routines in the site_html.pl file that are used for the CGI files, you DO NOT need to re-build your directory.

Okay...the reason that I put a space between the tilda ~ and semi-colon ; was my mistake since I always put spaces at the end of code lines in these forums to avoid smilies....

Just put the tilda and semi-colon together and you are set to go!

like the following:

Code:
if (($cat_hits eq "0") && ($link_hits eq "0")) {
print qq~Your search returned 0 categories and 0 links.~;
}
else {
print qq~Your search returned $cat_hits categories and $link_hits links.~;
}

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Search results problem In reply to
OK, so I showed off my newbie ignorance by "Building" after changing a sub routine. ;-) But it did show up my error and that's good!

Unfortunately, I'm still getting the exact same error when I try to build even after removing the space between the ~ and the ;

Any other ideas?

TIA,
Clark

------------------
Freshwebproduce - A web design & production co.
Walla Walla, Washington
http://www.freshwebproduce.com



[This message has been edited by ClarkP (edited March 09, 2000).]
Quote Reply
Re: Search results problem In reply to
Well, the synatx error relates to the space between the tilda and semi-colon. And the code SHOULD work.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Search results problem In reply to
OK...

I just uploaded site_html.pl again and then built it again (just to check for syntax error) and still get the same exact error message. Here is my code with a little extra from each side so you can see the placement of it in the sub routine:

<B><FONT FACE="Arial, Helvetica, sans-serif" SIZE="3">$site_title: Search Results</font></b>

if (($cat_hits eq "0") && ($link_hits eq "0")) {
print qq~Your search returned 0 categories and 0 links.~;
}
else {
print qq~Your search returned $cat_hits categories and $link_hits links.~;
}

~;
if ($next) {
print qq~<p>Pages: $next</p>
~;
}
if ($category_results) {
print qq~
<B>Categories:</b>
<ul>$category_results</ul>
~;
}
if ($link_results) {
print qq~
<B>Links</b>

$link_results

~;
}
if ($next) {
print qq~
<p>Pages: $next</p>
~;
}
print qq~

$site_search

Something else in the subroutine wouldn't be causing the problems on the new lines of code would it?

Thanks for your help!
Clark

------------------
Freshwebproduce - A web design & production co.
Walla Walla, Washington
http://www.freshwebproduce.com

Quote Reply
Re: Search results problem In reply to
UGH...You do not have to rebuild your directory when you make changes to the sub-routines that are used in the following .cgi files:

add.cgi (like sub site_html_add_form)
modify.cgi (like sub site_html_modify_form)
rate.cgi

etc........ (hope you get that now at least!)

Okay...

Try changing the following codes:

Code:
if (($cat_hits eq "0") && ($link_hits eq "0")) {

to the following:

Code:
if (($cat_hits eq 0) && ($link_hits eq 0)) {

Hope this works this time!

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Search results problem In reply to
BTW: If you are NOT a Perl guy, you should really consider using the template system in LINKS.

Wink

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Search results problem In reply to
Yes, yes... I understand that I don't have to "Build" when modifying those subroutines. I got it the first time you said it. I keep doing it because it tells Perl dummies like me that there are still errors in the code. Is there an easier way for dumb guys to check their code? I'd like to know if there is. :-)

In any case, I "Built" it again (!) and then tried a search and got the same error message both ways. Sorry I'm so dense on this one...

Clark



Quote Reply
Re: Search results problem In reply to
 
Code:
cd /cgi-bin/links/admin

2) Check the syntax of the file:

Code:
perl -c site_html.pl

Please do this and report back the EXACT syntax errors you receive!

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Search results problem In reply to
OK, here are my thoughts... in the code that says:
if (($cat_hits eq "0") && ($link_hits eq "0")) {
print qq~Your search returned 0 categories and 0 links.~;
}

Don't we need to be checking to see if the $cat_hits and $link_hits are empty variables instead of equal to zero? If they were equal to "0" I would never have had the original problem and it would have printed out the message: "Your search returned 0 categories and 0 links." exactly like I want it to. In this line of thought I tried:

if (($cat_hits eq "") && ($link_hits eq "")) {
print qq~Your search returned 0 categories and 0 links.~;
}

But I got the same error. How do I correctly check for an empty or null variable value? Isn't that what we want to do?

TIA,
Clark
Quote Reply
Re: Search results problem In reply to
Here is the error message from telnet:

Bareword found where operator expected at site_html.pl line 2141, near "print qq~Your"
(Might be a runaway multi-line ~~ string starting on line 2028)
(Do you need to predeclare print?)
syntax error at site_html.pl line 2141, near "print qq~Your search "
Number found where operator expected at site_html.pl line 2141, near "returned 0"
(Do you need to predeclare returned?)
Bareword found where operator expected at site_html.pl line 2141, near "0 categories"
(Missing operator before categories?)
Bareword found where operator expected at site_html.pl line 2141, near "0 links"
(Missing operator before links?)
syntax error at site_html.pl line 2143, near "else"
site_html.pl had compilation errors.

That's it from here...
Clark
Quote Reply
Re: Search results problem In reply to
 
Code:
~;
if (($cat_hits eq "0") && ($link_hits eq "0")) {
print qq~Your search returned 0 categories and 0 links.~;
}
else {
print qq~Your search returned $cat_hits categories and $link_hits links.~;
}
print qq~

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Search results problem In reply to
Hi all,

Thanks Eliot. That DID fix the syntax errors! Unfortunately it did not do anything to change my original problem. The output is still:

"Your search returned categories and links."

This leads me to believe that zero does NOT equal null.

If zero DID equal null, we would not have had the problem in the first place and the "stock" links code would have returned a value of 0 when it called $cat_hits and $link_hits. It's not returning ANYTHING when there are no search results so that leads me to believe again that those variable have values of null (or are empty) and do not have a value of zero.

So how do I check to see if $cat_hits and $link_hits have values of null? Then we can follow the if>then statements and output zero for them.

Thanks for all the help!
Clark


------------------
Freshwebproduce - A web design & production co.
Walla Walla, Washington
http://www.freshwebproduce.com

Quote Reply
Re: Search results problem In reply to
Welp, since you think you have a better handle on the logic behind the codes, I am sure you will figure out an answer.

Best of luck!

Wink

I have similar codes that were used for templates and it works fine for me.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Search results problem In reply to
I don't think I have a better handle on the logic... I obviously don't know the answer or I wouldn't have asked the question. I'm just asking questions that are going through my mind in an attempt to solve the problem.

So if an empty variable DOES equal zero, why do we need a mod anyway? The original code (
<p>Your search returned <strong>$cat_hits</strong> categories and <strong>$link_hits</strong> links.</p> ) would just work exactly as it's written and print out "Your search returned 0 categories and 0 Links." instead of what it is doing (printing out "Your search returned categories and links.")

Right? What am I missing? This new code prints out exactly the same thing as the original code.

Thanks a great deal for your help, Eliot. I really appreciate it. But please don't get your nose out of joint since I questioned the logic. I HAVE to question the logic because the code DOES NOT work. I'm only looking for a solution to the problem and I haven't found one yet so of course I am questioning everything.

Any additional help that would solve this problem would be greatly appreciated!
Clark



------------------
Freshwebproduce - A web design & production co.
Walla Walla, Washington
http://www.freshwebproduce.com



[This message has been edited by ClarkP (edited March 10, 2000).]
Quote Reply
Re: Search results problem In reply to
Well, the only other suggestion I have for you is to use the following codes:

Code:
~;
if ($cat_hits lt 1) {
print qq~Your search returned 0 categories and $link_hits links.~;
}
if ($link_hits lt 1) {
print qq~Your search returned $cat_hits categories and 0 links.~;
}
else {
print qq~Your search returned $cat_hits categories and $link_hits links.~;
}
print qq~

BTW: Since you don't know Perl...lt stands for less than.

Wink

BTW: A better approach in your comments would've been to ask questions in a nicer manner.

"Don't bite the hand that feeds you."

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Search results problem In reply to
Well folks, brains and Perl skills always win in the end. Thanks to Eliot's code, I have a fully functioning search results page. A heartfelt thanks!

I was apparently my own worst enemy on this one as I was placing Eliots code into the sub site_html_search_results subroutine in site_html.pl. This did not do a thing to solve the problem. Once I figured out that Links considers a search with 0 links and 0 categories a "failed" search instead of a search with no results, I put Eliots code into the sub site_html_search_failure subroutine and it works flawlessly. (This could very well be what Eliot thought I was doing all along...)

So to summarize Eliots fix:

Leave your code alone in sub site_html_search_results.

Place the following code into sub site_html_search_failure:

~;
if (($cat_hits lt 1) && ($link_hits lt 1)) {
print qq~<p>Your search returned <strong>0</strong> categories and <strong>0</strong> links.</p>
~;
}
else {
print qq~<p>Your search returned <strong>$cat_hits</strong> categories and <strong>$link_hits</strong> links.</p>
~;
}
print qq~

It works great. Thanks for all the help and for tolerating my stream-of-concsiousness ramblings.

Clark Pearson

------------------
Freshwebproduce - A web design & production co.
Walla Walla, Washington
http://www.freshwebproduce.com

Quote Reply
Re: Search results problem In reply to
Glad you figured it out.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums