]> git.deb.at Git - deb/packages.git/blobdiff - lib/Packages/DoSearchContents.pm
contents search: Give result in correct case
[deb/packages.git] / lib / Packages / DoSearchContents.pm
index f512ec4618334a3a007cd0492b8350e4ba7f8892..debbbb2a93e28539aef61f66556ae17871080c85 100644 (file)
@@ -14,12 +14,12 @@ our @EXPORT = qw( do_search_contents );
 use Deb::Versions;
 use Packages::I18N::Locale;
 use Packages::Search qw( :all );
-use Packages::CGI;
+use Packages::CGI qw( :DEFAULT error );
 use Packages::DB;
 use Packages::Config qw( $DBDIR @SUITES @ARCHIVES @ARCHITECTURES $ROOT );
 
 sub do_search_contents {
-    my ($params, $opts, $html_header, $page_content) = @_;
+    my ($params, $opts, $page_content) = @_;
 
     if ($params->{errors}{keywords}) {
        fatal_error( _g( "keyword not valid or missing" ) );
@@ -34,7 +34,7 @@ sub do_search_contents {
     #FIXME: that's extremely hacky atm
     if ($params->{values}{suite}{no_replace}[0] eq 'default') {
        $params->{values}{suite}{no_replace} =
-           $params->{values}{suite}{final} = $opts->{suite} = [ 'stable' ];
+           $params->{values}{suite}{final} = $opts->{suite} = [ 'etch' ];
     }
 
     if (@{$opts->{suite}} > 1) {
@@ -75,6 +75,7 @@ sub do_search_contents {
                &searchfile(\@results, reverse($_)."/", \$nres, $reverses);
                last if $Packages::Search::too_many_hits;
            }
+           while (<FILENAMES>) {};
            close FILENAMES or warn "fgrep error: $!\n";
        } else {
 
@@ -82,7 +83,8 @@ sub do_search_contents {
                if @keywords;
 
            my $kw = reverse $first_kw;
-           
+           $kw =~ s{/+$}{};
+
            # exact filename searching follows trivially:
            $kw = "$kw/" if $mode eq 'exactfilename';
 
@@ -91,11 +93,11 @@ sub do_search_contents {
        $reverses = undef;
        untie %reverses;
 
-    
+
        my $st1 = new Benchmark;
        my $std = timediff($st1, $st0);
        debug( "Search took ".timestr($std) ) if DEBUG;
-    }    
+    }
 
     my (%results,%archs);
     foreach my $result (sort { $a->[0] cmp $b->[0] } @results) {
@@ -110,8 +112,8 @@ sub do_search_contents {
        next unless keys %pkgs;
        $results{$file} = \%pkgs;
     }
-    my @all_archs = keys %archs;
-    @all_archs = @ARCHITECTURES unless @all_archs;
+    my @all_archs = sort keys %archs;
+    @all_archs = sort @ARCHITECTURES unless @all_archs;
     $page_content->{suite} = $suite;
     $page_content->{archive} = $archive;
     $page_content->{all_architectures} = \@all_archs;
@@ -164,15 +166,22 @@ sub searchfile
     debug( "searchfile: kw=$kw", 1 ) if DEBUG;
     for (my $status = $reverses->seq($key, $value, R_CURSOR);
        $status == 0;
-       $status =  $reverses->seq( $key, $value, R_NEXT)) {
+       $status =  $reverses->seq( $key, $value, R_NEXT)) {
 
        # FIXME: what's the most efficient "is prefix of" thingy? We only want to know
        # whether $kw is or is not a prefix of $key
        last unless index($key, $kw) == 0;
        debug( "found $key", 2 ) if DEBUG;
 
-       my @hits = split /\0/o, $value;
-       push @$results, [ scalar reverse($key), @hits ];
+       my @files = split /\001/o, $value;
+       foreach my $f (@files) {
+           my @hits = split /\0/o, $f;
+           my $file = shift @hits;
+           if ($file eq '-') {
+               $file = reverse($key);
+           }
+           push @$results, [ $file, @hits ];
+       }
        last if ($$nres)++ > 100;
     }