our
$VERSION
=
do
{
my
@r
= (
q$Revision: 2.12 $
=~ /\d+/g );
sprintf
"%d."
.
"%03d"
x
$#r
,
@r
};
my
$MAINTAINER
=
'Jim Smyser <jsmyser@bigfoot.com>'
;
my
$TEST_CASES
=
<<"ENDTESTCASES";
&test('HotFiles', '$MAINTAINER', 'zero', \$bogus_query, \$TEST_EXACTLY);
&test('HotFiles', '$MAINTAINER', 'one', 'replication', \$TEST_RANGE, 2,24);
&test('HotFiles', '$MAINTAINER', 'two', 'Medicine', \$TEST_GREATER_THAN, 25);
ENDTESTCASES
sub
native_setup_search
{
my
(
$self
,
$native_query
,
$native_options_ref
) =
@_
;
$self
->{_debug} =
$native_options_ref
->{
'search_debug'
};
$self
->{_debug} = 2
if
(
$native_options_ref
->{
'search_parse_debug'
});
$self
->{_debug} ||= 0;
my
$DEFAULT_HITS_PER_PAGE
= 25;
$DEFAULT_HITS_PER_PAGE
= 25
if
$self
->{_debug};
$self
->{
'_hits_per_page'
} =
$DEFAULT_HITS_PER_PAGE
;
my
$iMaximum
= 1 +
$self
->maximum_to_retrieve;
my
$iNumPages
= 1 +
int
(
$iMaximum
/
$self
->{
'_hits_per_page'
});
if
(1 <
$iNumPages
)
{
$self
->{
'_hits_per_page'
} = 1 +
int
(
$iMaximum
/
$iNumPages
);
}
else
{
$self
->{
'_hits_per_page'
} =
$iMaximum
;
}
$self
->{agent_e_mail} =
'jsmyser@bigfoot.com'
;
$self
->user_agent(1);
$self
->{
'_next_to_retrieve'
} = 0;
$self
->{
'_num_hits'
} = 0;
if
(!
defined
(
$self
->{_options})) {
$self
->{_options} = {
'Usrt'
=>
'rel&Usrchtype=simple&search_max=26'
,
'Utext'
=>
$native_query
,
};
}
my
$options_ref
=
$self
->{_options};
if
(
defined
(
$native_options_ref
))
{
foreach
(
keys
%$native_options_ref
)
{
$options_ref
->{
$_
} =
$native_options_ref
->{
$_
};
}
}
my
$options
=
''
;
foreach
(
keys
%$options_ref
)
{
next
if
(generic_option(
$_
));
$options
.=
$_
.
'='
.
$options_ref
->{
$_
} .
'&'
;
}
$self
->{_next_url} =
$self
->{_options}{
'search_url'
} .
'?'
.
$options
;
}
sub
begin_new_hit
{
my
(
$self
) =
shift
;
my
(
$old_hit
) =
shift
;
my
(
$old_raw
) =
shift
;
if
(
defined
(
$old_hit
)) {
$old_hit
->raw(
$old_raw
)
if
(
defined
(
$old_raw
));
push
(@{
$self
->{cache}},
$old_hit
);
}
;
return
(new WWW::SearchResult,
''
);
}
sub
native_retrieve_some
{
my
(
$self
) =
@_
;
return
undef
unless
defined
(
$self
->{_next_url});
print
STDERR
"***Sending request ("
,
$self
->{_next_url},
")\n"
if
$self
->{
'_debug'
};
my
$response
=
$self
->http_request(
'GET'
,
$self
->{_next_url});
$self
->{response} =
$response
;
unless
(
$response
->is_success)
{
return
undef
;
}
print
STDERR
"***Picked up a response..\n"
if
$self
->{
'_debug'
};
$self
->{
'_next_url'
} =
undef
;
my
(
$HEADER
,
$HITS
,
$DESC
,
$TRAILER
) =
qw(HE HH DE TR)
;
my
(
$raw
) =
''
;
my
$hits_found
= 0;
my
$state
=
$HEADER
;
my
$hit
;
foreach
(
$self
->split_lines(
$response
->content()))
{
next
if
m/^$/;
print
STDERR
" *** $state ===$_==="
if
2 <=
$self
->{
'_debug'
};
if
(
$state
eq
$HEADER
&& m@\<TR BGCOLOR=
"#FFFFFF"
>
@i
)
{
$state
=
$HITS
;
}
elsif
(
$state
eq
$HITS
&& m@\<TD ALIGN=left>\<FONT SIZE=2>\<b>\<A HREF=
"([^"
]+)">(.*)\</FONT>\</A>\<BR>
@i
)
{
print
STDERR
"hit url line\n"
if
2 <=
$self
->{
'_debug'
};
(
$hit
,
$raw
) =
$self
->begin_new_hit(
$hit
,
$raw
);
$raw
.=
$_
;
$self
->{
'_num_hits'
}++;
$hits_found
++;
$hit
->add_url($1);
$hit
->title($2);
$state
=
$DESC
;
}
elsif
(
$state
eq
$DESC
&& m@^\<FONT SIZE=2>(.*)@)
{
print
STDERR
"hit description line\n"
if
2 <=
$self
->{
'_debug'
};
$raw
.=
$_
;
$hit
->description($1);
$state
=
$HITS
;
}
elsif
(
$state
eq
$HITS
&& m@\<TD>
 
;\</TD>@)
{
$raw
.=
$_
;
}
elsif
(
$state
eq
$HITS
&& m@\<TD NOWRAP ALIGN=left>(.*)\</TD>@)
{
$raw
.=
$_
;
$hit
->index_date($1);
}
elsif
(
$state
eq
$HITS
&& m@\<TD ALIGN=left>(\<IMG SRC=(.+)>)@)
{
$raw
.=
$_
;
$hit
->score($1);
}
elsif
(
$state
eq
$HITS
&& m@\<TD ALIGN=left>\<FONT SIZE=2>(.*)@)
{
$raw
.=
$_
;
}
elsif
(
$state
eq
$HITS
&& m@\<TD ALIGN=left>\<FONT SIZE=2>(.*)\</FONT>\</TD>@)
{
$raw
.=
$_
;
}
elsif
(
$state
eq
$HITS
&& m@\<p>
@i
)
{
}
elsif
(
$state
eq
$HITS
&& m/\<INPUT\s[^>]
*VALUE
=\"Hits\s(.+)\"/i)
{
print
STDERR
" found next button\n"
if
2 <=
$self
->{
'_debug'
};
$self
->{
'_next_to_retrieve'
} +=
$self
->{
'_hits_per_page'
};
$self
->{
'_options'
}{
'mainnext'
} =
$self
->{
'_next_to_retrieve'
};
my
(
$options
) =
''
;
foreach
(
keys
%{
$self
->{_options}})
{
next
if
(generic_option(
$_
));
$options
.=
$_
.
'='
.
$self
->{_options}{
$_
} .
'&'
;
}
$self
->{_next_url} =
$self
->{_options}{
'search_url'
} .
'?'
.
$options
;
$state
=
$TRAILER
;
}
else
{
print
STDERR
"didn't match\n"
if
2 <=
$self
->{'_debug'};
}
}
if
(
$state
ne
$TRAILER
)
{
$self
->{_next_url} =
undef
;
}
return
$hits_found
;
}
1;