From: Jeroen van Wolffelaar Date: Tue, 14 Feb 2006 00:27:02 +0000 (+0000) Subject: Implement search_contents bluntly X-Git-Tag: switch-to-templates~134 X-Git-Url: https://git.deb.at/w?a=commitdiff_plain;h=3d5a2408c84b3197cfb003ef2c3204d9c280b481;p=deb%2Fpackages.git Implement search_contents bluntly --- diff --git a/cgi-bin/search_contents.pl b/cgi-bin/search_contents.pl new file mode 100755 index 0000000..21aaeab --- /dev/null +++ b/cgi-bin/search_contents.pl @@ -0,0 +1,50 @@ +#!/usr/bin/perl -wT +# $Id$ +# search_packages.pl -- CGI interface to the Packages files on packages.debian.org +# +# Copyright (C) 1998 James Treacy +# Copyright (C) 2000, 2001 Josip Rodin +# Copyright (C) 2001 Adam Heath +# Copyright (C) 2004 Martin Schulze +# Copyright (C) 2004-2006 Frank Lichtenheld +# +# use is allowed under the terms of the GNU Public License (GPL) +# see http://www.fsf.org/copyleft/gpl.html for a copy of the license + +sub contents() { + + my ($cgi) = @_; + + print "Extremely blunt ends-with search results:
";
+# only thing implemented yet: ends-with search
+    my $kw = lc $cgi->param("keywords");
+    $kw = reverse $kw;
+# FIXME: ensure $suite is sanitized
+    my $suite = 'stable';
+
+    my $reverses = tie my %reverses, 'DB_File', "$DBDIR/contents/reverse_$suite.db",
+	O_RDONLY, 0666, $DB_BTREE
+	or die "Failed opening reverse DB: $!";
+    
+    my ($key, $rest) = ($kw, "");
+    my $nres = 0;
+    for (my $status = $reverses->seq($key, $value, R_CURSOR);
+	$status == 0;
+    	$status =  $reverses->seq( $key, $value, R_NEXT)) {
+
+	# FIXME: what's the most efficient "is prefix of" thingy? We only want to know
+	# whether $kw is or is not a prefix of $key
+	last unless index($key, $kw) == 0;
+
+	@hits = split /\0/o, $value;
+	print reverse($key)." is found in @hits\n";
+	last if $nres++ > 100;
+    }
+
+    $reverses = undef;
+    untie %reverses;
+    print "
$nres results displayed"; +} + +1; +# vim: ts=8 sw=4 diff --git a/cgi-bin/search_packages.pl b/cgi-bin/search_packages.pl index 8e26b11..c74ffc2 100755 --- a/cgi-bin/search_packages.pl +++ b/cgi-bin/search_packages.pl @@ -159,8 +159,7 @@ unless (@Packages::CGI::fatal_errors) { \&read_src_entry, \%opts ) }; } elsif ($searchon eq 'contents') { require "./search_contents.pl"; - &contents(\$input); - exit; + &contents($input); } else { push @results, @{ do_names_search( $keyword, \%packages, $p_obj,