replace the sub next_hits with the following:
sub next_hits {
# ----------------------------------------------
# Creates a next hits toolbar.
#
my ($page, $numhits, $maxhits) = @_;
my ($left, $right, $upper, $lower, $next_hit, $prev_hit, $i, $page_no);
my $nh = int ($page / $maxhits) | | 0;
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 = 0);
($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 > 0) and ($output .= qq~<a href="$ENV{'SCRIPT_NAME'}?$next_url&nh=$prev_hit">[<< Prev]</a> ~);
for ($i = 0; $i <= int($numhits/$maxhits) + 1; $i++) {
last if ($i > 19);
if ($i < $lower) { $output .= " ... "; $i = ($lower-1); next; }
if ($i > $upper) { $output .= " ... "; last; }
$page_no = $i + 1;
($i == $nh) ?
($output .= qq~$page_no ~) :
($output .= qq~<a href="$ENV{'SCRIPT_NAME'}?$next_url&nh=$i">$page_no</a> ~);
(($page_no * $maxhits) >= $numhits) and last; # Special case if we hit exact.
}
$output .= qq~<a href="$ENV{'SCRIPT_NAME'}?$next_url&nh=$next_hit">[Next >>]</a> ~ unless (($nh == $i) or ($nh == 19));
return $output;
}