3 # search_contents.pl -- CGI interface to the Contents files on packages.debian.org
5 # Copyright (C) 2006 Jeroen van Wolffelaar
7 # use is allowed under the terms of the GNU Public License (GPL)
8 # see http://www.fsf.org/copyleft/gpl.html for a copy of the license
15 print "Extremely blunt ends-with search results:<br><pre>";
16 # only thing implemented yet: ends-with search
17 my $kw = lc $cgi->param("keywords");
18 # full filename search is tricky
19 my $ffn = $cgi->param("fullfilename");
23 my $suite = 'stable'; #fixme
25 my $reverses = tie my %reverses, 'DB_File', "$DBDIR/contents/reverse_$suite.db",
26 O_RDONLY, 0666, $DB_BTREE
27 or die "Failed opening reverse DB: $!";
30 open FILENAMES, "$DBDIR/contents/filenames_$suite.txt"
31 or die "Failed opening filename table";
33 next if index($_, $kw)<0;
35 last unless &dosearch(reverse($_)."/", \$nres, $reverses);
42 # exact filename searching follows trivially:
43 my $exact = $cgi->param("exact");
44 $kw = "$kw/" if $exact;
46 print "ERROR: Exact and fullfilenamesearch don't go along" if $ffn and $exact;
48 &dosearch($kw, \$nres, $reverses);
50 print "</pre>$nres results displayed";
58 my ($kw, $nres, $reverses) = @_;
60 my ($key, $rest) = ($kw, "");
61 for (my $status = $reverses->seq($key, $value, R_CURSOR);
63 $status = $reverses->seq( $key, $value, R_NEXT)) {
65 # FIXME: what's the most efficient "is prefix of" thingy? We only want to know
66 # whether $kw is or is not a prefix of $key
67 last unless index($key, $kw) == 0;
69 @hits = split /\0/o, $value;
70 print reverse($key)." is found in @hits\n";
71 last if ($$nres)++ > 100;