1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
|
# AltaVista/Intranet3.pm
# $Id: Intranet3.pm,v 1.5 2008/01/21 02:04:11 Daddy Exp $
#
# Complete copyright notice follows below.
=head1 NAME
WWW::Search::AltaVista::Intranet3 - class for searching via AltaVista Search Intranet 3.0
=head1 SYNOPSIS
use WWW::Search;
my $oSearch = new WWW::Search('AltaVista::Intranet3',
(_host => 'copper', _port => 9000),);
my $sQuery = WWW::Search::escape_query("+investment +club");
$oSearch->native_query($sQuery);
while (my $oResult = $oSearch->next_result())
{ print $oResult->url, "\n"; }
=head1 DESCRIPTION
This class implements a search on AltaVista's Intranet ("AVI") Search.
This class exports no public interface; all interaction should
be done through WWW::Search objects.
=head1 NOTES
If your query includes characters outside the 7-bit ascii,
you must tell AVI how to interpret 8-bit characters.
Add an option for 'enc' to the native_query() call:
=encoding ISO8859-1
$oSearch->native_query(WWW::Search::escape_query('Zrich'),
{ 'enc' => 'iso88591'},
);
Hopefully the correct values for various languages can be found in the
AVI documentation (sorry, I haven't looked).
=head1 TESTING
There is no standard built-in test mechanism for this module, because
very few users of WWW::Search will have AVI installed on their
intranet. (How's that for an excuse? ;-)
=head1 AUTHOR
=head1 COPYRIGHT
Copyright (c) 1996 University of Southern California.
All rights reserved.
Redistribution and use in source and binary forms are permitted
provided that the above copyright notice and this paragraph are
duplicated in all such forms and that any documentation, advertising
materials, and other materials related to such distribution and use
acknowledge that the software was developed by the University of
Southern California, Information Sciences Institute. The name of the
University may not be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
=head1 VERSION HISTORY
If it''s not listed here, then it wasn''t a meaningful nor released revision.
=head2 2.04, 2000-03-09
Added pod for selecting query language encoding
=head2 2.03, 2000-02-14
Added support for score/rank (thanks to Peter von Burg <pvonburg@aspes.ch>)
=head2 2.02, 1999-11-29
Fixed to work with latest version of AltaVista.pm
=head2 1.03, 1999-06-20
First publicly-released version.
=cut
#####################################################################
package WWW::Search::AltaVista::Intranet3;
use strict;
use warnings;
use base 'WWW::Search::AltaVista';
use Carp;
our
$VERSION = '2.04';
our $TEST_CASES = <<"ENDTESTCASES";
&no_test('AltaVista::Intranet3', '$MAINTAINER');
ENDTESTCASES
$self->{_debug} = 1; # PvB
# private
sub native_setup_search
{
my ($self, $sQuery, $rhOptions) = @_;
my $sMsg = '';
unless (defined($self->{_host}) && ($self->{_host} ne ''))
{ $sMsg .= " --- _host not specified in WWW::Search::AltaVista::Intranet object\n"; }
unless (defined($self->{_port}) && ($self->{_port} ne ''))
{ $sMsg .= " --- _port not specified in WWW::Search::AltaVista::Intranet object\n"; }
if ($sMsg ne '')
{
carp $sMsg;
return undef;
} # if
$self->{_options} = { # PvB
'search_url' => 'http://' . $self->{_host} . ':' . $self->{_port} . '/cgi-bin/query',
'mss' => 'search', # AV Intranet 3.0
# 'mss' => 'simple', # AV Intranet 2.3
'kl' => '',
'i' => '',
'text' => 'yes',
};
# $self->{_debug} = 1; # PvB
if ($self->{_debug})
{ # PvB
print " Query: ", $sQuery, "\n";
print " Options: ";
while (($k, $v) =each %$rhOptions) {print "$k => $v "};
print "\n";
}
# let AltaVista.pm finish up the hard work.
return $self->SUPER::native_setup_search($sQuery, $rhOptions);
} # native_setup_search
# private
sub native_retrieve_some
{
my ($self) = @_;
print STDERR " * AltaVista::Intranet::native_retrieve_some()\n" if $self->{_debug};
# fast exit if already done
return undef if (!defined($self->{_next_url}));
# If this is not the first page of results, sleep so as to not overload the server:
$self->user_agent_delay if 1 < $self->{'_next_to_retrieve'};
# get some
print STDERR " * sending request (",$self->{_next_url},")\n" if $self->{_debug};
my($response) = $self->http_request('GET', $self->{_next_url});
$self->{response} = $response;
if (!$response->is_success)
{
return undef;
}
$self->{'_next_url'} = undef;
print STDERR " * got response, start parsing\n" if $self->{_debug};
# parse the output
my ($HEADER, $HITS, $TITLE,$DESC,$DATE,$SIZE,$TRAILER) = qw(HE HI TI DE DA SI TR);
my $hits_found = 0;
my $state = ($HEADER);
my $cite = "";
my $hit = ();
foreach ($self->split_lines($response->content()))
{
next if m@^$@; # short circuit for blank lines
print STDERR " * $state ===$_=== \n" if 2 <= $self->{'_debug'};
if ($state eq $HEADER && m/<b>AltaVista found\s+(\d+)/i) # PvB
{
print "No of Pages Line --$_--\n" if 2 <= $self->{_debug}; # 1st parsing check: No of Pages
# Actual line of input is:
#
print STDERR "found web pages count line\n" if 2 <= $self->{_debug};
$self->approximate_result_count($1);
print "No of pages found: $1\n\n" if $self->{_debug}; # PvB
$state = $HITS;
} # COUNT line
if ($state eq $HITS && m/Word count:/) # PvB
{
print "No of words Line --$_--\n" if 2 <= $self->{_debug}; # 2nd parsing check: No of Words
# Actual line of input is:
#
print STDERR "count line\n" if 2 <= $self->{_debug};
$self->approximate_result_count($1);
$state = $HITS;
} # COUNT line
elsif ($state eq $HITS && m/Begin results list/i) # PvB
{
$state = $TITLE; # PvB
}
elsif ($state eq $TITLE && m:\<a\shref=\"([^"]+)\">:i) # PvB *** begin found pages ***
{
print "title line: --$_--\n" if 2 <= $self->{_debug}; # 4nd parsing check: title
# Actual line of input is:
#
#
print STDERR "title line\n" if 2 <= $self->{_debug};
if (ref($hit))
{
push(@{$self->{cache}}, $hit);
}
$hit = new WWW::SearchResult;
$hit->add_url($1);
print "Hit found: $1\n" if $self->{_debug};
$hits_found++;
if (m:\<b>(.+?)\</b>:i)
{
my $sTitle = $1;
$sTitle =~ s/\s+$//;
$sTitle =~ s:</a>.*::;
$sTitle =~ s:.*<a.*">::;
print "Title of page found: ", $sTitle, "\n" if $self->{_debug};
$hit->title($sTitle);
} # if
if (m:\<strong>(.+?)\</strong>:i)
{
my $sTitle = $1;
$sTitle =~ s/\s+$//;
print "Title of page found: ", $sTitle, "\n" if $self->{_debug};
$hit->title($sTitle);
} # if
$state = $DESC;
} # TITLE line
elsif ($state eq $DESC)
{
# Actual line of input is:
#
$_ =~ s/<dd>//i;
$_ =~ s/<br>//i;
print STDERR "description line\n" if 2 <= $self->{_debug};
print STDERR "description: --$_-- \n" if 2 <= $self->{_debug};
$hit->description($_);
$state = $DATE;
print "Description of page found: ", $_, "\n" if $self->{_debug};
} # DESCRIPTION line
elsif ($state eq $DATE && m:Last modified (.+)$:i)
{
# Actual lines of input are:
#
#
print STDERR "relevance/date/size line\n" if 2 <= $self->{_debug};
$line = $_;
$_ =~ s/.*modified on //i;
$_ =~ s/ ·.*//i;
print STDERR "last modified date: $_ \n" if $self->{_debug};
$hit->change_date($_);
$_ = $line;
$_ =~ s/Relevance //i;
$_ =~ s/ ·.*//i;
print STDERR "relevance: $_ \n" if $self->{_debug};
$hit->score($_);
$_ = $line;
$_ =~ s/.* · Last//i;
$_ =~ s/.*? · //i;
$_ =~ s/ bytes.*//i;
my $iSize = $_;
$iSize *= 1024 if ($iSize =~ s@k$@@i);
$iSize *= 1024*1024 if ($iSize =~ s@M$@@i);
print STDERR "size: $iSize \n\n" if $self->{_debug};
$hit->size($iSize);
$state = $TITLE;
} # REL/DATE/SIZE line
elsif ($state eq $TRAILER && m:next\s*>>:i)
{
# Actual line of input is:
#
print STDERR "next link line\n" if 2 <= $self->{_debug};
$_ =~ s/\[<a href="//i;
$_ =~ s/"><b>next.*//i;
$_ = 'http://' . $self->{_host} .':'. $self->{_port} . $_ ;
$self->{_next_url} = $_;
print STDERR "next link url is: $_ \n" if $self->{_debug};
$state = $TRAILER;
} # next AV result page
elsif ($_ eq "<!-- End results list. -->")
{
print " * end of parsing reached\n" if $self->{_debug};
$state = $TRAILER;
} # NEXT line
else
{
print STDERR "didn't match\n" if 2 <= $self->{_debug};
}
} # foreach
if (defined($hit))
{
push(@{$self->{cache}}, $hit);
} # if
print " * hits found: \n" if $self->{_debug};
return $hits_found;
} # native_retrieve_some
1;
__END__
|