From: Frank Lichtenheld Date: Thu, 2 Feb 2006 00:39:13 +0000 (+0000) Subject: Add full text search X-Git-Tag: switch-to-templates~207 X-Git-Url: https://git.deb.at/w?a=commitdiff_plain;h=7837241d743061df9f58680a9b786e48d3365a48;p=deb%2Fpackages.git Add full text search --- diff --git a/cgi-bin/search_packages.pl b/cgi-bin/search_packages.pl index 7aa7ffd..f6df10c 100755 --- a/cgi-bin/search_packages.pl +++ b/cgi-bin/search_packages.pl @@ -280,6 +280,49 @@ if ($searchon eq 'names') { } } } +} else { + + my @lines; + my $regex; + if ($case_bool) { + if ($exact) { + $regex = qr/\b\Q$keyword\E\b/o; + } else { + $regex = qr/\Q$keyword\E/o; + } + } else { + if ($exact) { + $regex = qr/\b\Q$keyword\E\b/io; + } else { + $regex = qr/\Q$keyword\E/io; + } + } + + open DESC, '<', "$DBDIR/descriptions.txt" or die "couldn't open $DBDIR/descriptions.txt: $!"; + while () { + $_ =~ $regex or next; + print "DEBUG: Matched line $.
" if $debug > 2; + push @lines, $.; + } + close DESC; + + my $obj = tie my %packages, 'DB_File', "$DBDIR/packages_small.db", O_RDONLY, 0666, $DB_BTREE + or die "couldn't tie DB $DBDIR/packages_small.db: $!"; + my $obj = tie my %did2pkg, 'DB_File', "$DBDIR/descriptions_packages.db", O_RDONLY, 0666, $DB_BTREE + or die "couldn't tie DB $DBDIR/descriptions_packages.db: $!"; + + my %tmp_results; + foreach my $l (@lines) { + my $result = $did2pkg{$l}; + foreach (split /\000/o, $result) { + my @data = split /\s/, $_, 3; + next unless $archs{$data[2]}; + $tmp_results{$data[0]}++; + } + } + foreach my $pkg (keys %tmp_results) { + read_entry( \%packages, $pkg, \@results ); + } } my $st1 = new Benchmark;