| 1 | |||||||||||||||||||||||||||||
| 2 | package WWW::Search::Simple; | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | WWW::Search::Simple - class for searching any web site | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | require WWW::Search; | ||||||||||||||||||||||||||||
| 14 | $search = new WWW::Search('Simple'); | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | This class is a specialization of WWW::Search for simple web based | ||||||||||||||||||||||||||||
| 19 | search indices. It extracts all links from a given page. | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | This class exports no public interface; all interaction should be done | ||||||||||||||||||||||||||||
| 22 | through WWW::Search objects. | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | Note that this module will probably get a lot of false hits. | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | C<WWW::Search::Simple> is written by Paul Lindner, <lindner@itu.int> | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | Copyright (c) 1997,98 by the United Nations Administrative Committee | ||||||||||||||||||||||||||||
| 33 | on Coordination (ACC) | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | All rights reserved. | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =cut | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1 | ▶ | use base 'WWW::Search'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 1 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 43 | 1 | ▶ | use HTML::TreeBuilder; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 1 | ▶ | use WWW::SearchResult; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 1 | my $debug = 0; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | sub _native_setup_search | ||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my ($self, $native_query, $native_opt) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_native_setup_search: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 51 | 0 | my ($native_url); | |||||||||||||||||||||||||||
| 52 | 0 | my ($default_native_url) = "http://www.itu.int/cgi-bin/SFgate?application=itu&database=local//usr/local/wais/WWW/www-pages&listenv=table&httppath=/usr/local/www-data/&httpprefix=/&tie=and&maxhits=%n&text=%s"; | |||||||||||||||||||||||||||
| 53 | 0 | ▶ | if (defined($native_opt)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | { | ||||||||||||||||||||||||||||
| 55 | #print "Got " . join(' ', keys(%$native_opt)) . "\n"; | ||||||||||||||||||||||||||||
| 56 | # Process options.. | ||||||||||||||||||||||||||||
| 57 | # Substitute query terms for %s... | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if ($self->{'search_url'} && $native_opt->{'search_args'}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"search_url"} and $native_opt->{"search_args"}
MC/DC0%0/2
$self->{"search_url"} and $native_opt->{"search_args"}
$self->{"search_url"}
$native_opt->{"search_args"}
Truth table0%0/3
A and B
A= $self->{"search_url"}B= $native_opt->{"search_args"}
| |||||||||||||||||||||||||||||
| 60 | { | ||||||||||||||||||||||||||||
| 61 | 0 | $native_url = $native_opt->{'search_url'} . "?" . $native_opt->{'search_args'}; | |||||||||||||||||||||||||||
| 62 | } # if | ||||||||||||||||||||||||||||
| 63 | } # if | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | $native_url = $default_native_url if (!$native_url); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | $native_url =~ s/%s/$native_query/g; # Substitute search terms... | |||||||||||||||||||||||||||
| 66 | 0 | $self->user_agent(); | |||||||||||||||||||||||||||
| 67 | 0 | $self->{_next_to_retrieve} = 0; | |||||||||||||||||||||||||||
| 68 | 0 | $self->{_base_url} = $self->{_next_url} = $native_url; | |||||||||||||||||||||||||||
| 69 | } # _native_setup_search | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub _native_retrieve_some | ||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||
| 73 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_native_retrieve_some: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 74 | 0 | my ($hit) = (); | |||||||||||||||||||||||||||
| 75 | 0 | my ($hits_found) = 0; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # fast exit if already done | ||||||||||||||||||||||||||||
| 78 | 0 | ▶ | return undef if (!defined($self->{_next_url})); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | # get some | ||||||||||||||||||||||||||||
| 81 | 0 | ▶ | print "GET " . $self->{_next_url} . "\n" if ($debug); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | my($response) = $self->http_request($self->{search_method}, | ||||||||||||||||||||||||||||
| 83 | 0 | $self->{_next_url}); | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | $self->{response} = $response; | |||||||||||||||||||||||||||
| 86 | 0 | ▶ | if (!$response->is_success) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | { | ||||||||||||||||||||||||||||
| 88 | 0 | ▶ | print "Some problem\n" if ($debug); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | return undef; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | my $score = 800; | |||||||||||||||||||||||||||
| 93 | 0 | my $results = $response->content(); | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | my($h) = new HTML::TreeBuilder; | |||||||||||||||||||||||||||
| 96 | 0 | $h->parse($results); | |||||||||||||||||||||||||||
| 97 | 0 | for (@{ $h->extract_links(qw(a)) }) | |||||||||||||||||||||||||||
| 98 | { | ||||||||||||||||||||||||||||
| 99 | 0 | my($link, $linkelem) = @$_; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | my($linkobj) = new URI::URL $link, $self->{_next_url}; | |||||||||||||||||||||||||||
| 102 | 0 | ▶ | print "Fixing $link\n" if ($debug); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | my($hit) = new WWW::SearchResult; | |||||||||||||||||||||||||||
| 105 | 0 | $hit->add_url($linkobj->abs->as_string()); | |||||||||||||||||||||||||||
| 106 | 0 | $hit->title(join(' ',@{$linkelem->content})); | |||||||||||||||||||||||||||
| 107 | 0 | $hit->score($score); | |||||||||||||||||||||||||||
| 108 | 0 | $hit->normalized_score($score); | |||||||||||||||||||||||||||
| 109 | 0 | ▶ | if ($hit->title !~ /HASH\(0x/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||
| 111 | 0 | $hits_found++; | |||||||||||||||||||||||||||
| 112 | 0 | push(@{$self->{cache}}, $hit); | |||||||||||||||||||||||||||
| 113 | } # if | ||||||||||||||||||||||||||||
| 114 | 0 | $score = int ($score * .95); | |||||||||||||||||||||||||||
| 115 | } # for | ||||||||||||||||||||||||||||
| 116 | 0 | $self->approximate_result_count($hits_found); | |||||||||||||||||||||||||||
| 117 | 0 | $self->{_next_url} = undef; | |||||||||||||||||||||||||||
| 118 | 0 | return($hits_found); | |||||||||||||||||||||||||||
| 119 | } # _native_retrieve_some | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 1 | 1; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||