Gossamer Forum
Home : Products : Links 2.0 : Customization :

altavista search - new mod

(Page 1 of 3)
> >
Quote Reply
altavista search - new mod
This mod allows you to search theweb, categories, or both... Keep in mind I have posted the code here as if you are using templates. It shouldn't be too hard to figure out how to change it...

You can see this in action here:
www.magicdirectory.com/cgi-bin/search.cgi?query=david+blaine&search=both

or just the web search:
www.magicdirectory.com/cgi-bin/search.cgi?query=david+blaine&search=theweb

or just the category search:

www.magicdirectory.com/cgi-bin/search.cgi?query=david+blaine

In order for the option to search both the web and categories follow these instructions...

In search.cgi under:

Code:
# Display the form if called with no input.
(keys %in <= 0) and &site_html_search_form() and return;

put this:

Code:
($in{'search'} eq "theweb") and &altavista;
($in{'search'} eq "both") and &altavista;

also at the bottom of search.cgi add these routines...

Code:
sub altavista {
# --------------------------------------------------------
# Search Altavista
my %in = &parse_form;
use LWP::Simple;
my $query = $in{'query'};
my $query_q = &urlencode($query);
my $page = ($in{'nh'} * 10) | | 0;
my $pageXX = $page - 10;
my $url = "http://www.altavista.com/cgi-bin/query?q=$query_q&text=yes&stq=$pageXX";
my $results = get ($url);
$results or &site_html_search_failure ({ error => "No Results Available.", %in }) and return;
# If we see this, then we couldn't get a match.
my $none = quotemeta ("AltaVista found no document matching your query.");
if ($results =~ m/$none/) {
&site_html_search_failure ({ error => "No Matching Links", %in }) and return;
}
else {
if ($results =~ /([^>\s]+) pages found./) { $link_hits = $1; }
else { &site_html_search_failure ({ error => "Can't Parse Results", %in }) and return;
}
my $FONT = 'font face="verdana, arial" size="2"';
my $FONT_SMALL = 'font face="verdana, arial" size="1"';
if ($link_hits) {
while ($results =~ m#<dl><dt>\n<b>(\d+)\.\s*</b>\n<a href="([^"]+)">\n<b>([^<]+)</b></a></dt>\n<dd>([^<]*)</dd>\n<br><b>URL:</b> <font color="\#808080">([^<]+)</font>\n<br><font color="\#808080">\n([^<]+\n[^<]+)</font>#sog) {
($count, $url, $title, $description, $url2, $last) = ($1, $2, $3, $4, $5, $6);$url2 =~ s,/$,,;
$last =~ s,\n,,;$last =~ s,\s\s+, ,;
$link_results .= qq~<p>\n<$FONT_SMALL><b>$count.</b></font> <$FONT><a href="$url">$title</a><br>\n$description</font><br>\n<$FONT_SMALL><b>URL:</b> <font color="#808080">http://$url2</font></font>\n~;
}
}
}
$next = &next_hits($page, $link_hits, 10)

if ($in{'search'} eq "both") {
$link_results2 = $link_results;
$link_hits2 = $link_hits;
$next2 = $next;
return;
}
&site_html_search_results;
exit;
}
The routine above this has changed...
Code:
sub next_hits {
# ----------------------------------------------
# Creates a next hits toolbar.
#
my ($page, $numhits, $maxhits) = @_;
my ($left, $right, $upper, $lower, $next_hit, $prev_hit, $i);
my $nh = int ($page / $maxhits) | | 1;
my $output = '';
$numhits =~ s/,//g;
$numhits = int ($numhits);

my $next_url = $ENV{'QUERY_STRING'};
$next_url =~ s/\&nh=\d+//;
$next_hit = $nh + 1; $prev_hit = $nh - 1;

# First, set how many pages we have on the left and the right.
$left = $nh; $right = int($numhits/$maxhits) - $nh;
# Then work out what page number we can go above and below.
($left > 7) ? ($lower = $left - 7) : ($lower = 1);
($right > 7) ? ($upper = $nh + 7) : ($upper = int($numhits/$maxhits) + 1);
# Finally, adjust those page numbers if we are near an endpoint.
(7 - $nh >= 0) and ($upper = $upper + (8 - $nh));
($nh > ($numhits/$maxhits - 7)) and ($lower = $lower - ($nh - int($numhits/$maxhits - 7) - 1));

# Then let's go through the pages and build the HTML.
($nh > 1) and ($output .= qq~<a href="$ENV{'SCRIPT_NAME'}?$next_url&nh=$prev_hit">[<<]</a> ~);
for ($i = 1; $i <= int($numhits/$maxhits) + 1; $i++) {
last if ($i > 19);
if ($i < $lower) { $output .= " ... "; $i = ($lower-1); next; }
if ($i > $upper) { $output .= " ... "; last; }
($i == $nh) ?
($output .= qq~$i ~) :
($output .= qq~<a href="$ENV{'SCRIPT_NAME'}?$next_url&nh=$i">$i</a> ~);
(($i * $maxhits) >= $numhits) and print "Exiting3" and last; # Special case if we hit exact.
}
$output .= qq~<a href="$ENV{'SCRIPT_NAME'}?$next_url&nh=$next_hit">[>>]</a> ~ unless (($nh == $i) or ($nh == 19));
return $output;
}

In site_html_templates.pl add these under sub site_html_search_results:

Code:
link_hits2 => $link_hits2,
next2 => $next2,
link_results2 => $link_results2,

Now in your actual template add:

Code:
<%if link_hits2%>
<%link_hits2%>
<%endif%>

<%if next2%>
<%next2%>
<%endif%>

<%if link_results2%>
<%link_results2%>
<%endif%>

Thats it! Keep in mind that you can edit the failure page to display one result if the other isn't working etc...!

Don't forget about deleting the space between | |.

------------------
- Jonathan Gamble

www.magicdirectory.com

[This message has been edited by jdgamble (edited April 09, 2000).]
Quote Reply
Re: altavista search - new mod In reply to
Oh yeah, you can add a drop down list that will select what search you want on your home page and on your search page:
http://www.magicdirectory.com/cgi-bin/search.cgi

Code:
<select size="1" name="search">
<option value="theweb">The Web</option>
<option value="categories">Categories</option>
<option selected value="both">Both</option>
</select>

------------------
- Jonathan Gamble

http://www.magicdirectory.com/

[This message has been edited by jdgamble (edited March 15, 2000).]
Quote Reply
Re: altavista search - new mod In reply to
Nice Mod. Keep up the good work. HOWEVER, you should probably delete the extraneous codes like:

Code:
($in{'query'} eq "david blaine") and &david_blaine;

so that novice users won't freak when they try to use your Mod and experience error messages.

Also...nice use of the Category Number code hack...

Wink

Regards,

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


[This message has been edited by AnthroRules (edited March 13, 2000).]
Quote Reply
Re: altavista search - new mod In reply to
Thanks. I had made this mod before experimenting, but I couldn't find any use for it.

I removed the extra code. That was for a different mod I made.

------------------
- Jonathan Gamble

http://www.magicdirectory.com/




Quote Reply
Re: altavista search - new mod In reply to
For anyone interested, I've updated this mod again to make it easier to install and less complicated. Also it is one less sub routine to worry about.

------------------
- Jonathan Gamble

http://www.magicdirectory.com/




Quote Reply
Re: altavista search - new mod In reply to
Nice job...I was going to suggest that...Step ahead of the game!

Wink

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: altavista search - new mod In reply to
I am looking for help for this mod,
I have copied and pasted it from here and did exactly what was mentioned in this thread.

I have the LWP module so that is not the problem.

You can view my search.cgi as a text file at
http://www.on-linecanada.com/search.txt

I did notice that when I cut and paste using IE 5.0 it paste it as one long line,
In Netscape it paste it like is seen in the txt file I do not know if this is why I am getting an Internal Server Error.

Any help would be appreciated, also if someone could email me the code as a text file if the way it was pasted is the problem.

Eliot if you see this post could you maybe recommend some good perl books Title or Author I would like to pick some up.

Thanks People

------------------
On-line Canada.com
http://www.on-linecanada.com
Internet Directory & Website Resource Centre
Quote Reply
Re: altavista search - new mod In reply to
Exactly what problems are you having? What errors are you getting?

------------------
- Jonathan Gamble

http://www.magicdirectory.com/




Quote Reply
Re: altavista search - new mod In reply to
* "Perl for Dummies"
* "Perl Cookbook"
* "Learning Perl, 2nd Edition"
* "Programming Perl, 2nd Edition"
* "Advanced Perl Programming"

All can be found at Amazon.com or ora.com.

Please provide the exact error messages you receive if any.

Regards,


------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: altavista search - new mod In reply to
I search for "whatever" in all area's
web, categories and both and I get an Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.

I am positive that it was done exactly like you mention above. In fact I leave the other pages alone ie. site_html_templates.pl (leave the changes to that page there)and re-install my back up search.cgi and my search works fine for my catagories then try it again and same problem.

I think it has to do with the cut and paste, for some reason it distorts I used both browsers IE and netscape yet when I have done other mods it doesn't and it works fine.

Hmmmmm...

Thanks Redneck

------------------
On-line Canada.com
http://www.on-linecanada.com
Internet Directory & Website Resource Centre
Quote Reply
Re: altavista search - new mod In reply to
hi,

this mod look so great i must have it.. but i can get it to work (interal server error)

there was some talk about a new and more simple code !! could I see it ?

Allan
Quote Reply
Re: altavista search - new mod In reply to
crudetower,

Uh...the edited codes are in the FIRST Post. See the edited message at the bottom of the Post...jdgamble has edited the codes in his first Post. Copy the codes as written and paste them into your search.cgi file.

RedNeck,

What Editor program are you using to edit your search.cgi file? I would recommend editing your cgi scripts in WordPad, EditPlus (www.editplus.com). If you are editing "on-line" via pico or other on-line editors in your telnet shell account, that is not very wise idea.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: altavista search - new mod In reply to
I've had several emails about how people can't get this to work.

If you have the origional altavista mod installed and working, here is all you have to do...

under this in search.cgi:
Code:
($in{'search'} eq "theweb") and &altavista;

add this:

Code:
($in{'search'} eq "both") and &altavista;

In sub altavista, under this:

Code:
$next = &next_hits($page, $link_hits, 10)

add this:

Code:
if ($in{'search'} eq "both") {
$link_results2 = $link_results;
$link_hits2 = $link_hits;
$next2 = $next;
return;
}

In site_html_templates.pl add these under sub site_html_search_results:

Code:
link_hits2 => $link_hits2,
next2 => $next2,
link_results2 => $link_results2,

Now in your actual template add:
Code:
<%if link_hits2%>
<%link_hits2%>
<%endif%>
<%if next2%>
<%next2%>
<%endif%>
<%if link_results2%>
<%link_results2%>
<%endif%>

To add a drop down list etc, add this in your search.html template:

Code:
<select size="1" name="search">
<option value="theweb">The Web</option>
<option value="categories">Categories</option>
<option selected value="both">Both</option>
</select>


------------------
- Jonathan Gamble

http://www.magicdirectory.com/

[This message has been edited by jdgamble (edited March 19, 2000).]
Quote Reply
Re: altavista search - new mod In reply to
I use notetab but I went and got edit plus 2.01a and try it again same problem,
Internal Server Error.

I'm going to find the other altavista mod and
try jdgamble's update.

I don't know that much about writting perl
but I am able to play with it and get things
to go right, But like I said before even in
edit plus 2.01a when you paste the code it paste about 3 inches in from the left.

when I leave it like that internal server
error, so I backspace it to where it should
be but still internal server error.

Eliot when you write perl does it matter
about spaces and line breaks etc. or does this effect the code.

well of to the drawing board
Regards,
Redneck

------------------
On-line Canada.com
http://www.on-linecanada.com
Internet Directory & Website Resource Centre
Quote Reply
Re: altavista search - new mod In reply to
Okay here is what I have found out so far, when I telnet into
the server and run the script from there I get two errors

(1) syntax error near line 420 which is $link_hits2 = $link_hits;

(2) syntax error near line 426 which is } the last line of the first sub routine.

It executes the search.cgi great up until it hits this point. This is what's causing the Internal server error.

Any suggestions?

Regards,
Redneck

------------------
On-line Canada.com
http://www.on-linecanada.com
Internet Directory & Website Resource Centre
Quote Reply
Re: altavista search - new mod In reply to
 
Quote:
Eliot when you write perl does it matter
about spaces and line breaks etc. or does this effect the code.

Yes...line breaks and spaces do matter.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: altavista search - new mod In reply to
Well I don't know what you did jdgamble but the new codes worked like
a charm, and beleive it or not I didn't even have the other altavista
search mod working I got the same errors as before, but I figured
I had nothing else to loose so I tried it and
it Worked.

Thanks for your time and help and also for the great mod.

Thanks to you to Eliot for wisdom.

Regards,
Redneck

Now if I can only figure out how my case of beer got on the roof??? Hmmmm...

------------------
On-line Canada.com
http://www.on-linecanada.com
Internet Directory & Website Resource Centre
Quote Reply
Re: altavista search - new mod In reply to
You're welcome.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: altavista search - new mod In reply to
May I suggest when you have the time, to format the Mod into one section and post-it into the Resources section?

I would think many people look there first for modifications rather than search this forum.!

Best regards,

The Marshal
--------------


[This message has been edited by The Marshal (edited March 19, 2000).]
Quote Reply
Re: altavista search - new mod In reply to
jdgamble:

I ran into a snag with your mod again, when
you search for different
sites it does what ever it wants. It is really hard to explain,
but I'll try.

If you search for say "free" using both it
comes up that it found
55 sites on the sites directory, but it doesn't show anything only
web matches, but if you searched for "canada" using both it does.

Further if you searched for "free" using the web selection it again
comes up it found 55 sites on the sites directory and doesn't
show anything for web matches.

If you want to see for yourself go to http://www.on-linecanada.com
This has really got me thinking, Hmmmm...

Regards,
Redneck

------------------
On-line Canada.com
http://www.on-linecanada.com
Internet Directory & Website Resource Centre
Quote Reply
Re: altavista search - new mod In reply to
One problem I see with jdgamble codes is the following:

Code:
<option value="categories">Categories</option>

This should be:

Code:
<option value="">Categories</option>

With regards to your search results problem, RedNeck, I think that you may be confusing the placement of your tags. Could you please upload your search_results.html file in a publicly accessibly directory in your server? So, that we can see what codes and tags you are using.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: altavista search - new mod In reply to
Eliot:

The search_results.html page is up, you can find it at:

http://www.on-linecanada.com/test/site_html.html

Thanks for looking into this.

Regards,
Redneck

------------------
On-line Canada.com
http://www.on-linecanada.com
Internet Directory & Website Resource Centre
Quote Reply
Re: altavista search - new mod In reply to
One thing that I see missing from your codes is a conditonal tag for the main link_results and link_hits. These tags should look like the following:

Code:
<%if link_results%>
<%link_results%>
<%endif%>

Code:
<%if link_hits%>
<%link_hits%>
<%endif%>


And again, that option field I believe is wrong. Refer to my previous Reply.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: altavista search - new mod In reply to
Eliot:

Thanks for pointing that out I do have those
tags but did not have
the <%endif%> part. (must have gotten deleted some how)

Also I think I found the problem, in search.cgi under
sub main {

I had: ($in{'search'} eq "altavista") and &altavista;
($in{'search'} eq "both") and &altavista;

which I copied from the altavista search mod
in another thread

I believe it should be ($in{'search'} eq "the web") and &altavista;

as jdgamble mentions above to be able to use his mod, I don't have
time to verify this but will look more into it later tonight.

Regards,
Redneck


------------------
On-line Canada.com
http://www.on-linecanada.com
Internet Directory & Website Resource Centre
Quote Reply
Re: altavista search - new mod In reply to
I forgot about the extra tags in site_html_templates, thanks. Frontpage added the "category" think automaticaly and I ignored it since extra tags are ignored.

I could be wrong, but I think Redneck's thing about canada and free is because your database doesn't have any results on it and it will try and go to site_html_failure page. You might concider adding the web code to site_html_failure.


------------------
- Jonathan Gamble

http://www.magicdirectory.com/




> >