-sub read_entry {
- my ($hash, $key, $results, $opts) = @_;
- my $result = $hash->{$key} || '';
- foreach (split /\000/, $result) {
- my @data = split ( /\s/, $_, 7 );
- debug( "Considering entry ".join( ':', @data), 2);
- if ($opts->{h_suites}{$data[0]}
- && ($opts->{h_archs}{$data[1]} || $data[1] eq 'all')
- && $opts->{h_sections}{$data[2]}) {
- debug( "Using entry ".join( ':', @data), 2);
- push @$results, [ $key, @data ];
- }
- }
-}
-sub read_src_entry {
- my ($hash, $key, $results, $opts) = @_;
- my $result = $hash->{$key} || '';
- foreach (split /\000/, $result) {
- my @data = split ( /\s/, $_, 5 );
- debug( "Considering entry ".join( ':', @data), 2);
- if ($opts->{h_suites}{$data[0]} && $opts->{h_sections}{$data[1]}) {
- debug( "Using entry ".join( ':', @data), 2);
- push @$results, [ $key, @data ];
- }
- }
-}
-sub do_names_search {
- my ($keyword, $file, $postfix_file, $read_entry, $opts) = @_;
- my @results;
-
- $keyword = lc $keyword unless $opts->{case_bool};
-
- 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}++;
- }
- }
- last if $p_obj->seq( $key, $prefixes, R_NEXT ) != 0;
- last if $too_many_hits or keys %pkgs >= 100;
- }
-
- my $no_results = keys %pkgs;
- if ($too_many_hits || ($no_results >= 100)) {
- $too_many_hits += $no_results;
- %pkgs = ( $keyword => 1 );
- }
- foreach my $pkg (sort keys %pkgs) {
- &$read_entry( \%packages, $pkg, \@results, $opts );
- }
- }
- return \@results;
-}
-sub do_fulltext_search {
- my ($keword, $file, $mapping, $lookup, $read_entry, $opts) = @_;
- my @results;
-
- my @lines;
- my $regex;
- if ($opts->{case_bool}) {
- if ($opts->{exact}) {
- $regex = qr/\b\Q$keyword\E\b/o;
- } else {
- $regex = qr/\Q$keyword\E/o;
- }
+unless (@Packages::CGI::fatal_errors) {
+
+ if ($searchon eq 'names') {
+ push @results, @{ do_names_search( $keyword, \%packages,
+ $p_obj,
+ \&read_entry, \%opts ) };
+ } elsif ($searchon eq 'sourcenames') {
+ push @results, @{ do_names_search( $keyword, \%sources,
+ $sp_obj,
+ \&read_src_entry, \%opts ) };
+ } elsif ($searchon eq 'contents') {
+ require "./search_contents.pl";
+ &contents($input);