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 # fixme: I should open $reverses only once per search
26 my $reverses = tie my %reverses, 'DB_File', "$DBDIR/contents/reverse_$suite.db",
27 O_RDONLY, 0666, $DB_BTREE
28 or die "Failed opening reverse DB: $!";
31 open FILENAMES, "$DBDIR/contents/filenames_$suite.txt"
32 or die "Failed opening filename table";
34 next if index($_, $kw)<0;
36 last unless &dosearch(reverse($_)."/", \$nres, $reverses);
43 # exact filename searching follows trivially:
44 my $exact = $cgi->param("exact");
45 $kw = "$kw/" if $exact;
47 print "ERROR: Exact and fullfilenamesearch don't go along" if $ffn and $exact;
49 &dosearch($kw, \$nres, $reverses);
51 print "</pre>$nres results displayed";
59 my ($kw, $nres, $reverses) = @_;
61 my ($key, $rest) = ($kw, "");
62 for (my $status = $reverses->seq($key, $value, R_CURSOR);
64 $status = $reverses->seq( $key, $value, R_NEXT)) {
66 # FIXME: what's the most efficient "is prefix of" thingy? We only want to know
67 # whether $kw is or is not a prefix of $key
68 last unless index($key, $kw) == 0;
70 @hits = split /\0/o, $value;
71 print reverse($key)." is found in @hits\n";
72 last if ($$nres)++ > 100;