From 3d5a2408c84b3197cfb003ef2c3204d9c280b481 Mon Sep 17 00:00:00 2001 From: Jeroen van Wolffelaar Date: Tue, 14 Feb 2006 00:27:02 +0000 Subject: [PATCH] Implement search_contents bluntly --- cgi-bin/search_contents.pl | 50 ++++++++++++++++++++++++++++++++++++++ cgi-bin/search_packages.pl | 3 +-- 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100755 cgi-bin/search_contents.pl 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, -- 2.39.2