-# FIXME
-# check if the Packages files are there
-#my @files = glob ("$fdir/$file");
-#if ($#files == -1) {
-# XXX has to be updated for new architectures
-# if ($format eq 'html') {
-# if (($version eq "stable" and $arch =~ /^(hurd|sh)$/)
-# || ($version eq "oldstable" and $arch =~ /^amd64$/)) {
-# print "Error: the $arch architecture didn't exist in $version.<br>\n"
-# ."Please go back and choose a different distribution.\n";
-# } else {
-# print "Error: Packages/Sources file not found.<br>\n"
-# ."If the problem persists, please inform $ENV{SERVER_ADMIN}.\n";
-# printf "<p>$file</p>";
-# }
-# &printfooter;
-# }
-# exit;
-#}
-
- my @files;
- foreach my $s (@suites) {
- foreach my $sec (@sections) {
- foreach my $a (@archs) {
- foreach my $archive (@ARCHIVES) {
- if (($searchon eq 'names' or $searchon eq 'sourcenames')
- and $exact) {
- my ( %packages, $file );
- if ($search_on_sources) {
- $file = "$FLATDIR/$s/$sec/Sources.$archive.db";
- } else {
- $file = "$FLATDIR/$s/$sec/Packages-$a.$archive.db";
- }
- if (-f $file) {
- print "DEBUG: Use file $file<br>"
- if $debug > 1;
-
- tie %packages, 'DB_File', $file, O_RDONLY
- or die "Couldn't open packages file $file: $!";
-
- if (my $data = $packages{$searchkeyword}) {
- print "DEBUG: Found result $data<br>"
- if $debug > 1;
- push @results, "$file:$data";
- }
- }
- } else {
- my $file;
- if ($search_on_sources) {
- $file = "$FLATDIR/$s/$sec/Sources.$archive";
- } else {
- $file = "$FLATDIR/$s/$sec/Packages-$a.$archive";
- }
- if (-f $file) {
- print "DEBUG: Use file $file<br>"
- if $debug > 1;
-
- # use_grep is currently way faster, though
- # I can't pinpoint exactly why, yet
- # most probably the perl regexes are
- # slow compared to the simpler grep
- # regexes
- unless ($use_grep) {
- open my $pkg_fh, '<', $file
- or die "Couldn't open packages file $file: $!";
-
- foreach (<$pkg_fh>) {
- if (/$searchkeyword/o) {
- print "DEBUG: Found result $_<br>"
- if $debug > 1;
-
- push @results, "$file:$_";
- }
- }
- } else {
- push @files, $file;
- }
- }
- }
+ my $obj = tie my %packages, 'DB_File', "$DBDIR/$file", O_RDONLY, 0666, $DB_BTREE
+ or die "couldn't tie DB $DBDIR/$file: $!";
+
+ if ($opts->{exact}) {
+ &$read_entry( \%packages, $keyword, \@results, $opts );
+ } else {
+ my ($key, $prefixes) = ($keyword, '');
+ my %pkgs;
+ my $p_obj = tie my %pref, 'DB_File', "$DBDIR/$postfix_file", O_RDONLY, 0666, $DB_BTREE
+ or die "couldn't tie postfix db $DBDIR/$postfix_file: $!";
+ $p_obj->seq( $key, $prefixes, R_CURSOR );
+ while (index($key, $keyword) >= 0) {
+ if ($prefixes =~ /^\001(\d+)/o) {
+ $too_many_hits += $1;
+ } else {
+ foreach (split /\000/o, $prefixes) {
+ $_ = '' if $_ eq '^';
+ debug( "add word $_$key", 2);
+ $pkgs{$_.$key}++;