X-Git-Url: https://git.deb.at/?a=blobdiff_plain;f=lib%2FPackages%2FDoSearchContents.pm;h=93a20265adc4d84925451ef8da86c258defdd618;hb=f4bd5d6e5488854bc9633fb5629cc70d1045e9fa;hp=f512ec4618334a3a007cd0492b8350e4ba7f8892;hpb=2ec757bb58907b15c43548be5601d4f2b8c7caac;p=deb%2Fpackages.git diff --git a/lib/Packages/DoSearchContents.pm b/lib/Packages/DoSearchContents.pm index f512ec4..93a2026 100644 --- a/lib/Packages/DoSearchContents.pm +++ b/lib/Packages/DoSearchContents.pm @@ -5,8 +5,6 @@ use warnings; use Benchmark ':hireswallclock'; use DB_File; -use URI::Escape; -use HTML::Entities; use Exporter; our @ISA = qw( Exporter ); our @EXPORT = qw( do_search_contents ); @@ -14,12 +12,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 +32,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 +73,7 @@ sub do_search_contents { &searchfile(\@results, reverse($_)."/", \$nres, $reverses); last if $Packages::Search::too_many_hits; } + while () {}; close FILENAMES or warn "fgrep error: $!\n"; } else { @@ -82,7 +81,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 +91,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 +110,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 +164,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; }