if ($params->{errors}{keywords}) {
fatal_error( _g( "keyword not valid or missing" ) );
- } elsif (length($opts->{keywords}) < 2) {
+ $opts->{keywords} = [];
+ } elsif (grep { length($_) < 2 } @{$opts->{keywords}}) {
fatal_error( _g( "keyword too short (keywords need to have at least two characters)" ) );
}
$$menu = "";
- my $keyword = $opts->{keywords};
+ my @keywords = @{$opts->{keywords}};
my $searchon = $opts->{searchon};
# for URL construction
- my $keyword_esc = uri_escape( $keyword );
- my $suites_param = join ',', @{$params->{values}{suite}{no_replace}};
- my $sections_param = join ',', @{$params->{values}{section}{no_replace}};
- my $archs_param = join ',', @{$params->{values}{arch}{no_replace}};
- $opts->{common_params} = "suite=$suites_param§ion=$sections_param&keywords=$keyword_esc&searchon=$searchon&arch=$archs_param";
+ my $keyword_esc = uri_escape( "@keywords" );
+ $opts->{keywords_esc} = $keyword_esc;
# for output
- my $keyword_enc = encode_entities $keyword || '';
+ my $keyword_enc = encode_entities "@keywords" || '';
my $searchon_enc = encode_entities $searchon;
my $suites_enc = encode_entities( join( ', ', @{$params->{values}{suite}{no_replace}} ) );
my $sections_enc = encode_entities( join( ', ', @{$params->{values}{section}{no_replace}} ) );
if ($searchon eq 'names') {
if ($opts->{source}) {
- do_names_search( $keyword, \%sources, $sp_obj,
+ do_names_search( \@keywords, \%sources, $sp_obj,
\&read_src_entry_all, $opts,
\@results, \@non_results );
} else {
- do_names_search( $keyword, \%packages, $p_obj,
+ do_names_search( \@keywords, \%packages, $p_obj,
\&read_entry_all, $opts,
\@results, \@non_results );
}
-# } elsif ($searchon eq 'contents') {
-# require "./search_contents.pl";
-# &contents($input);
} else {
- do_names_search( $keyword, \%packages, $p_obj,
+ do_names_search( \@keywords, \%packages, $p_obj,
\&read_entry_all, $opts,
\@results, \@non_results );
- do_fulltext_search( $keyword, "$DBDIR/descriptions.txt",
+ do_fulltext_search( \@keywords, "$DBDIR/descriptions.txt",
\%did2pkg, \%packages,
\&read_entry_all, $opts,
\@results, \@non_results );
my $std = timediff($st1, $st0);
debug( "Search took ".timestr($std) ) if DEBUG;
- my $suite_wording = $suites_enc eq "all" ? _g("all suites")
+ my $suite_wording = $suites_enc =~ /^(default|all)$/ ? _g("all suites")
: sprintf(_g("suite(s) <em>%s</em>", $suites_enc) );
my $section_wording = $sections_enc eq 'all' ? _g("all sections")
: sprintf(_g("section(s) <em>%s</em>", $sections_enc) );
if ($opts->{exact}) {
hint( sprintf( _g( 'You have searched only for words exactly matching your keywords. You can try to search <a href="%s">allowing subword matching</a>.' ),
- encode_entities("$SEARCH_URL?exact=0&$opts->{common_params}") ) );
+ encode_entities(make_search_url('',"keywords=$keyword_esc",{exact => 0})) ) );
}
}
hint( sprintf( _g( 'You can try a different search on the <a href="%s">Packages search page</a>.' ), "$SEARCH_PAGE#search_packages" ) );
$subsect{$pkg}{$suite}{$version} = $subsection;
$sect{$pkg}{$suite}{$version} = $section
unless $section eq 'main';
- $archives{$pkg}{$suite}{$version} = $archive;
+ $archives{$pkg}{$suite}{$version} ||= $archive;
$desc{$pkg}{$suite}{$version} = $desc;
} else {
}
}
- my @pkgs = sort(keys %pkgs, keys %provided_by);
- $$page_content .= print_packages( \%pkgs, \@pkgs, $opts, $keyword,
+ my %uniq_pkgs = map { $_ => 1 } (keys %pkgs, keys %provided_by);
+ my @pkgs = sort keys %uniq_pkgs;
+ $$page_content .= print_packages( \%pkgs, \@pkgs, $opts, \@keywords,
\&print_package, \%provided_by,
\%archives, \%sect, \%subsect,
\%desc );
}
my @pkgs = sort keys %pkgs;
- $$page_content .= print_packages( \%pkgs, \@pkgs, $opts, $keyword,
+ $$page_content .= print_packages( \%pkgs, \@pkgs, $opts, \@keywords,
\&print_src_package, \%archives,
\%sect, \%subsect, \%binaries );
} # else unless $opts->{source}
} # sub do_search
sub print_packages {
- my ($pkgs, $pkgs_list, $opts, $keyword, $print_func, @func_args) = @_;
+ my ($pkgs, $pkgs_list, $opts, $keywords, $print_func, @func_args) = @_;
#my ($start, $end) = multipageheader( $input, scalar @pkgs, \%opts );
my $str = '<div id="psearchres">';
$str .= "<p>".sprintf( _g( "Found <em>%s</em> matching packages." ),
scalar @$pkgs_list )."</p>";
#my $count = 0;
+ my $keyword;
+ $keyword = $keywords->[0] if @$keywords == 1;
my $have_exact;
- if (grep { $_ eq $keyword } @$pkgs_list) {
+ if ($keyword && grep { $_ eq $keyword } @$pkgs_list) {
$have_exact = 1;
$str .= '<h2>'._g( "Exact hits" ).'</h2>';
$str .= &$print_func( $keyword, $pkgs->{$keyword}||{},
}
} elsif (@$pkgs_list) {
$str .= "<p>".sprintf( _g( '<a href="%s">%s</a> results have not been displayed because you requested only exact matches.' ),
- encode_entities("$SEARCH_URL?exact=0&$opts->{common_params}"),
+ encode_entities(make_search_url('',"keywords=$opts->{keyword_esc}",{exact => 0})),
scalar @$pkgs_list )."</p>";
}
$str .= '</div>';
my $str = '<h3>'.sprintf( _g( 'Package %s' ), $pkg ).'</h3>';
$str .= '<ul>';
foreach my $suite (@SUITES) {
- my $path = $suite;
+ my $override = { suite => $suite };
if (exists $pkgs->{$suite}) {
my %archs_printed;
my @versions = version_sort keys %{$pkgs->{$suite}};
if ($sect->{$suite}{$versions[0]}) {
$origin_str .= " ".marker($sect->{$suite}{$versions[0]});
}
- $str .= sprintf( "<li><a href=\"$ROOT/%s/%s\">%s</a> (%s): %s %s\n",
- $path, $pkg, $path, $subsect->{$suite}{$versions[0]},
+ $str .= sprintf( "<li><a href=\"%s\">%s</a> (%s): %s %s\n",
+ make_url($pkg,'',$override), $suite, $subsect->{$suite}{$versions[0]},
$desc->{$suite}{$versions[0]}, $origin_str );
foreach my $v (@versions) {
}
if (my $p = $provided_by->{$suite}) {
$str .= '<br>'._g( 'also provided by: ' ).
- join( ', ', map { "<a href=\"$ROOT/$path/$_\">$_</a>" } @$p);
+ join( ', ', map { "<a href=\"".
+ make_url($_,'',$override)."\">$_</a>" } @$p);
}
$str .= "</li>\n";
} elsif (my $p = $provided_by->{$suite}) {
- $str .= sprintf( "<li><a href=\"$ROOT/%s/%s\">%s</a>: Virtual package<br>",
- $path, $pkg, $path );
+ $str .= sprintf( "<li><a href=\"%s\">%s</a>: "._g('Virtual package').'<br>',
+ make_url($pkg,'',$override), $suite );
$str .= _g( 'provided by: ' ).
- join( ', ', map { "<a href=\"$ROOT/$path/$_\">$_</a>" } @$p);
+ join( ', ', map { "<a href=\"".
+ make_url($_,'',$override)."\">$_</a>" } @$p);
}
}
$str .= "</ul>\n";