]> git.deb.at Git - deb/packages.git/blobdiff - cgi-bin/search_packages.pl
Print total page evaluation time if debug allowed (also nice hint that you
[deb/packages.git] / cgi-bin / search_packages.pl
index 6b4a4676daa4ab3835961a04ddc83de072c70178..e5bcae588de9ea1205dda557e7831aeae86aeea9 100755 (executable)
@@ -26,7 +26,7 @@ use Deb::Versions;
 use Packages::Search qw( :all );
 use Packages::HTML ();
 
-my $thisscript = "search_packages.pl";
+my $thisscript = $Packages::HTML::SEARCH_CGI;
 my $HOME = "http://www.debian.org";
 my $ROOT = "";
 my $SEARCHPAGE = "http://packages.debian.org/";
@@ -183,7 +183,7 @@ my $search_on_sources = 0;
 
 my $st0 = new Benchmark;
 my @results;
-my $too_much_hits;
+my $too_many_hits;
 if ($searchon eq 'sourcenames') {
     $search_on_sources = 1;
 }
@@ -236,25 +236,23 @@ sub do_names_search {
        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 );
-       do {
+       while (index($key, $keyword) >= 0) {
             if ($prefixes =~ /^\001(\d+)/o) {
-                $too_much_hits += $1;
+                $too_many_hits += $1;
             } else {
-               print "DEBUG: add word $key<br>" if $debug > 2;
-               $pkgs{$key}++;
                foreach (split /\000/o, $prefixes) {
+                   $_ = '' if $_ eq '^';
                    print "DEBUG: add word $_$key<br>" if $debug > 2;
                    $pkgs{$_.$key}++;
                }
            }
-       } while (($p_obj->seq( $key, $prefixes, R_NEXT ) == 0)
-                && (index($key, $keyword) >= 0)
-                && !$too_much_hits
-                && (keys %pkgs < 100));
+           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_much_hits || ($no_results >= 100)) {
-           $too_much_hits += $no_results;
+        if ($too_many_hits || ($no_results >= 100)) {
+           $too_many_hits += $no_results;
            %pkgs = ( $keyword => 1 );
        }
        foreach my $pkg (sort keys %pkgs) {
@@ -335,8 +333,8 @@ if ($format eq 'html') {
     }
 }
 
-if ($too_much_hits) {
-print "<p><strong>Your search was too wide so we will only display exact matches. At least <em>$too_much_hits</em> results have been omitted and will not be displayed. Please consider using a longer keyword or more keywords.</strong></p>";
+if ($too_many_hits) {
+print "<p><strong>Your search was too wide so we will only display exact matches. At least <em>$too_many_hits</em> results have been omitted and will not be displayed. Please consider using a longer keyword or more keywords.</strong></p>";
 }
 
 if (!@results) {
@@ -599,5 +597,11 @@ print <<END;
 </div>
 END
 
+my $pete = new Benchmark;
+my $petd = timediff($pete, $pet0);
+print "Total page evaluation took ".timestr($petd)."<br>"
+    if $debug_allowed;
 print $input->end_html;
 }
+
+# vim: ts=8 sw=4