]> git.deb.at Git - deb/packages.git/blob - cgi-bin/search_contents.pl
839ffc00f0ad830ab43125f6ff738cefaa942c0c
[deb/packages.git] / cgi-bin / search_contents.pl
1 #!/usr/bin/perl -wT
2 # $Id$
3 # search_packages.pl -- CGI interface to the Packages files on packages.debian.org
4 #
5 # Copyright (C) 1998 James Treacy
6 # Copyright (C) 2000, 2001 Josip Rodin
7 # Copyright (C) 2001 Adam Heath
8 # Copyright (C) 2004 Martin Schulze
9 # Copyright (C) 2004-2006 Frank Lichtenheld
10 #
11 # use is allowed under the terms of the GNU Public License (GPL)                              
12 # see http://www.fsf.org/copyleft/gpl.html for a copy of the license
13
14 sub contents() {
15
16     my ($cgi) = @_;
17
18     print "Extremely blunt ends-with search results:<br><pre>";
19 # only thing implemented yet: ends-with search
20     my $kw = lc $cgi->param("keywords");
21     $kw = reverse $kw;
22     
23     # exact filename searching follows trivially:
24     my $exact = $cgi->param("exact");
25     $kw = "/$kw" if $exact;
26
27 # FIXME: ensure $suite is sanitized
28     my $suite = 'stable';
29
30     my $reverses = tie my %reverses, 'DB_File', "$DBDIR/contents/reverse_$suite.db",
31         O_RDONLY, 0666, $DB_BTREE
32         or die "Failed opening reverse DB: $!";
33     
34     my ($key, $rest) = ($kw, "");
35     my $nres = 0;
36     for (my $status = $reverses->seq($key, $value, R_CURSOR);
37         $status == 0;
38         $status =  $reverses->seq( $key, $value, R_NEXT)) {
39
40         # FIXME: what's the most efficient "is prefix of" thingy? We only want to know
41         # whether $kw is or is not a prefix of $key
42         last unless index($key, $kw) == 0;
43
44         @hits = split /\0/o, $value;
45         print reverse($key)." is found in @hits\n";
46         last if $nres++ > 100;
47     }
48
49     $reverses = undef;
50     untie %reverses;
51     print "</pre>$nres results displayed";
52 }
53
54 1;
55 # vim: ts=8 sw=4