Gossamer Forum
Home : Products : Links 2.0 : Customization :

altavista - new mod - PAGE2!!!

(Page 1 of 3)
> >
Quote Reply
altavista - new mod - PAGE2!!!
 
Quote:
Might I suggest that people create another Topic and link to this Topic...This Topic is getting hard to follow and it is 125KB large.

You read my mind.

Back to Page 1:
http://www.gossamer-threads.com/...um3/HTML/005417.html

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

www.magicdirectory.com

[This message has been edited by jdgamble (edited April 12, 2000).]
Quote Reply
Re: altavista - new mod - PAGE2!!! In reply to
Jonathan,
thanks for the reply, yeah I know the code is just too messy, I'm kind of lost in it too.

I have used just too many mod, so it would be difficult for you to reinstal them for me but instead, I have uploaded a copy of my working search.cgi at internetevim.virtualave.net/links/search2.txt this version was just before editing for your mod. so you can try to suggest what changes I should make based on this search.cgi.

also a back up copy of my site_html_templates2.pl is at internetevim.virtualave.net/links/site_html_templates2.txt again this copy was before changes made for your mod,
so they both are working copies.

thanks for your time

[This message has been edited by Ugur (edited April 12, 2000).]
Quote Reply
Re: altavista - new mod - PAGE2!!! In reply to
All I can suggest to you is to add these sub routines at the bottom of your script: (latest script)

Code:

sub altavista {
# --------------------------------------------------------
# Search Altavista
if (!$in{'query'}) { return ("Please enter one or more keywords."); }
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 exit;
# 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 exit;
}
else {
if ($results =~ /([^>\s]+) pages found./) { $link_hits = $1; }
else { &site_html_search_failure ({ error => "Can't Parse Results", %in }) and exit;
}
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;
}

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++) {
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);
return $output;
}

And of course these in the usual place...
Code:
($in{'search'} eq "theweb") and &altavista; ($in{'search'} eq "both") and &altavista;

Now I don't believe there is anything wrong with your site_html_templates file or with your templates...

Try it and see...



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

www.magicdirectory.com


Quote Reply
Re: altavista - new mod - PAGE2!!! In reply to
I have remembered to get rid of the spaces between &#0124; &#0124; before uploading my cgi file, so that shouldnt be the problem. I have rechecked my file permissions and they are ok too. This is just so annoying nothing happens all I get is the server error..

I have even tried it without my all other mods, just on a new copy of search.cgi, but the result was the same.. I know I'm missing something small somewhere but where I just cant find.
Quote Reply
Re: altavista - new mod - PAGE2!!! In reply to
Ugur,

have you only copy the posted code without any modifications?

You MUST eliminate the pace between "| |"

at
"my $page = ($in{'nh'} * 10) | | 0;"

and
"my $nh = int ($page / $maxhits) | | 1;"



P.s: Send the file as a text file and change permission to 755.

Quote Reply
Re: altavista - new mod - PAGE2!!! In reply to
I completely forgot about that. The space between &#0124; &#0124; are mentioned more than once.

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

www.magicdirectory.com


Quote Reply
Re: altavista - new mod - PAGE2!!! In reply to
Hi!

I managed to get everything working AOK just by following the thread - good stuff you guys! Is there not a way you can hack the UBB code though to stop it replacing &#0124; &#0124; with | |? Come on..Im sure you can!

ANYWAY

The only problem I have is a small one.

If I search:
'WEB' the results page tells me:
There are categories and 5,456 links

'CATEGORIES' the results page tells me:
There are categories and 5,456 links

'BOTH' the results page tells me:
There are 4 categories and links

Each of these times the correct results are shown (and yes, web results are shown even if I dont have the keyword in my database!) it is just this header. Why can't it count?

Cheers!

------------------
Ben

-------------------------
http:/www.t-e.co.uk

Quote Reply
Re: altavista - new mod - PAGE2!!! In reply to
BTW Ladies and Gents....You can simply replace the two | with or. The codes mean the same.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.
Quote Reply
Re: altavista - new mod - PAGE2!!! In reply to
Okay, got everything running pretty well. Did what somebody suggested and started over from scratch. Thanks for all the help!

One more question, though:

Could somebody please elaborate a little more on how to fix the issue with altavista results not being returned if the search term isn't found in the local database (when searching both)? I tried Eliot's suggestion and I'm getting some weirdness. I'd like to give Jonathan's idea a shot, but didn't quite understand what I'm supposed to do.

Thanks again everybody!

blane
Quote Reply
Re: altavista - new mod - PAGE2!!! In reply to
This is just so odd, I have done exactly like what you said, and I still got this 500 server stuff...and to make it worse, I have tried with a fresh copy of search.cgi, you know the one without all my mods on it but still have the same error, so this is really puzzling me..

anyway, I have to be gone for like a month or so, I will look in to this when I get back, thanks for your help.. hope to see you around when I'm back Smile
Quote Reply
Re: altavista - new mod - PAGE2!!! In reply to
Eliot, etc.
Any ideas as to why it cant find the count total, as stated in my previous post?
Quote Reply
Re: altavista - new mod - PAGE2!!! In reply to
Blane,
Quote:
Could somebody please elaborate a little more on how to fix the issue with altavista results not being returned if the search term isn't found in the local database (when searching both)?

It is in the latest code at the top of this forum message.

benseb,
Quote:
Each of these times the correct results are shown (and yes, web results are shown even if I dont have the keyword in my database!) it is just this header. Why can't it count?

Sounds to me that in your actual templates, you have <%link_hits%>the second time. It should be <%link_hits2%>.

AnthroRules,

Thank you for that. Your right but the only problem is that it would be a hassle to change the code on this script and on any others. But I will keep that in mind for the future.

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

www.magicdirectory.com

[This message has been edited by jdgamble (edited April 13, 2000).]
Quote Reply
Re: altavista - new mod - PAGE2!!! In reply to
THanks, I worked out what I was doing wrong!

Now, is this possible:
I would like to be able to build this into Links not only when searching, but when browsing by category as well.

Is there a way that I would be able to get the altavista to show web links that correspond to the category name? Might sound confusing..

Basically if I click on 'Backpacking' category, it brings up my links (plus subcats etc) and also link from the web where altavista keyword = "Backpacking". It would simply have a hardcoded search, using the cat name?

Then if I clicked through to Backpacking/asia is would look for links in my db as well as " Backpacking Asia". You get the idea Smile

Any thoughts?

------------------
Ben

-------------------------
http:/www.t-e.co.uk

Quote Reply
Re: altavista - new mod - PAGE2!!! In reply to
That would be cool and yes it is possible, but it is way out of my league and if there is someone who can do it, I don't think it will be for free.

You might want to look into pod.cgi.
http://www.grohol.com/downloads/pod/

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

www.magicdirectory.com


Quote Reply
Re: altavista - new mod - PAGE2!!! In reply to
Jonathan,

Quote:
It is in the latest code at the top of this forum message.

I copied the code up above and pasted it in and it didn't make a diff. Maybe I didn't describe the problem clear enough.

When I have my search form set to "Both" and I conduct a search for something that's not in my own database I get a "No matching records" error -- even if the item IS in AltaVista. I notice the same problem occurs at your Magic Directory site.

You mentioned on page 1 of this topic:

Quote:
The only bug in it is that if you select search=both, and you don't have any links in your database, then you will get the site_html_search_failure page and you won't get any altavista results. But this can be fixed easily by editing your sub routine for the search failure page.

...And then you cited some code that I didn't really understand. I was just hoping somebody could clarify this all a bit.

Thanks to all for any input!

blane
Quote Reply
Re: altavista - new mod - PAGE2!!! In reply to
Sorry, I didn't understand you. Uhh... Change these lines...
Code:
# Do the actual search.
my $status = &search (\@search_terms, $bool);
if ($status ne "ok") { &site_html_search_failure ($status); return; }

# Return unless we have results.
((keys %link_results > 0) or ($#category_results >= 0)) or
&site_html_search_failure ("no matching records") and return;

to...

Code:
# Do the actual search.
my $status = &search (\@search_terms, $bool);
if ($status ne "ok") {
if ($in{'search'} eq "both") {
&site_html_search_failure2 ($status); return;
}
else {
&site_html_search_failure ($status); return;

}
# Return unless we have results.
if ($in{'search'} eq "both") {
((keys %link_results > 0) or ($#category_results >= 0)) or
&site_html_search_failure2 ("no matching records") and return;
}
else {
((keys %link_results > 0) or ($#category_results >= 0)) or
&site_html_search_failure ("no matching records") and return;
}

and add the following sub routine to site_html_templates.pl

Code:
sub site_html_search_failure2 {
# --------------------------------------------------------
# This routine displays the search results.
#

$ENV{'QUERY_STRING'} =~ s/\&nocats=$in{'nocats'}//g;
$ENV{'QUERY_STRING'} =~ s/\&noca//g;

my $term = &urlencode ($in{'query'});
&html_print_headers;
print &load_template ('search_failure2.html', {
term => $term,
sum => $sum,
control_results => $control_results,
link_results => $link_results,
link_results2 => $link_results2,
category_results => $category_results,
next => $next,
next2 => $next2,
cat_hits => $cat_hits,
link_hits => $link_hits,
link_hits2 => $link_hits2,
%in,
%globals
});
}

and last copy your search_results template and save it as search_failure2...

It's not the cleanest way to do it, but it should work.


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

www.magicdirectory.com


Quote Reply
Re: altavista - new mod - PAGE2!!! In reply to
Wait, for get about the sub routine and the templates, its simpler to just use this and only this, you don't need the other templates...

Code:
# Do the actual search.
my $status = &search (\@search_terms, $bool);
if ($status ne "ok") {
if ($in{'search'} eq "both") {
&site_html_search_results;
}
else {
&site_html_search_failure ($status); return;
}
}
# Return unless we have results.
if ($in{'search'} eq "both") {
((keys %link_results > 0) or ($#category_results >= 0)) or
&site_html_search_results;
}
else {
((keys %link_results > 0) or ($#category_results >= 0)) or
&site_html_search_failure ("no matching records") and return;
}

I keep forgeting about something!
Haven't tested it yet, but it should work.

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

www.magicdirectory.com

[This message has been edited by jdgamble (edited April 14, 2000).]
Quote Reply
Re: altavista - new mod - PAGE2!!! In reply to
Yeah, I don't know how I missed it. Let me know if it works ok.

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

www.magicdirectory.com


Quote Reply
Re: altavista - new mod - PAGE2!!! In reply to
Jonathan,

Excellent code addition! I haven't tested it yet, but shouldn't there be another right curly bracket at the end of the "Do the actual search" portion?

Again, great job!

Troy
Quote Reply
Re: altavista - new mod - PAGE2!!! In reply to
jdgamble, I think this script sounds really interesting, however after spending almost an hour reading all posts, not only have I developed a headache, I also suffer from severe eyestrain ;-)

Wouldn't it be possible to just post the updated and *working* script again.

preferebly a link to it, beacuse there are several bugs in this UBB forum that screws up code posts.

Thank's
Quote Reply
Re: altavista - new mod - PAGE2!!! In reply to
Thanks for a great script, jdgamble!
I works just fine exept for one rather strange problem : when I do a websearch for a particular word (krohnengen), a download screen pops up and asks me if I want to download the file search.cgi. This file is not the actual cgi file, but the source code for the results page from altavista. It shows the correct results. I have tried with a bunch of other words, just to see if there is any consistency between keywords in my directory,AltaVista and this consise issue, but I haven't found any. I can only dublicate the scenario with this word. Any thoughts on this.

Stian

Ps. Another thing : when I do a websearch, and AltaVista returns no hits the error screen is duplicated. First I have the "not found" screen for Altavista and below that comes an exact duplicate, only for the directory. The pagesource has two sets of pagesources.

[This message has been edited by stiantot (edited May 02, 2000).]
Quote Reply
Re: altavista - new mod - PAGE2!!! In reply to
I am having problems running, this Links 2.0 mod. When I run it I get a 500 error.
I have tryed to install this mod a few times.
You can see my search.cgi file by gooing to http://hiphopbot.com/search.txt. You
can see my site_html_templates.pl file by gooing to http://hiphopbot.com/site_html_templates.txt

Can anyone tell me what I am dooing wrong?

------------------
Thank You,
James Hardy
HipHopBot Co.
support@hiphopbot.com
http://hiphopbot.com

------------------
Thank You,
James Hardy
HipHopBot Co.
support@hiphopbot.com
http://hiphopbot.com
Quote Reply
Re: altavista - new mod - PAGE2!!! In reply to
Well, one problem I see is that you have the following codes:

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

You are calling the same sub-routine with the different values for the search option.

Why?

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
Anthro TECH, L.L.C
anthrotech.com
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.


Quote Reply
Re: altavista - new mod - PAGE2!!! In reply to
Actually that is right Eliot. You want it to call theweb search or both because both of them define the values for the altavista results.

The problem is in this line in sub altavista:
Code:
$next = &next_hits($page, $link_hits, 10)
It should be:
Code:
$next = &next_hits($page, $link_hits, 10);




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

www.magicdirectory.com


Quote Reply
Re: altavista - new mod - PAGE2!!! In reply to
Ok I have tried to make sence of all the post and was able to fix most of my problems.
However if I do a search for lets say music for (BOTH) it only return the links and catagories for my site and not any links from Altavista. Here is my search.cgi....

http://www.surf4dough.addr.com/search.txt

I figure thats where the problem lays. Great MOD other than that after I fixed all my other little bugs!

Also if I search for something and its not in my database and I used (BOTH) I does return results from Altavist and repronts the page again on the bottom saying no results found for my local data base.

[This message has been edited by jlee (edited May 11, 2000).]

[This message has been edited by jlee (edited May 11, 2000).]
> >