Skip to main content.
home | support | download

Back to List Archive

Getting older .cgi scripts to work with swish-2.1-dev25 ?

From: Andrew Lord <andrewlord(at)>
Date: Sun Jun 02 2002 - 13:37:28 GMT
Hello swish-e developers,

I have been using swish-e 2.0.5 for some time and love it.  However I would 
like to move to swish-e-2.1-dev-25 in order to use its prog function and its 
capacity to index .php pages.  I'm having trouble getting swish-e-2.1-dev-25 
to work in conjunction with some cgi scripts.

One of these is dictionary.cgi, written by Bas Meijer, found in the lookup 
package (  It works perfectly with 1.3.3 & 2.0.5  but 
not with swish-dev.  The only result I get combining dictionary.cgi and 
swishdev is to be found when I click on the letter 'e' (in dictionary.cgi) 
and the sum total of that result is a hyperlinked 'err'.  The hyperlinking is 
correct so the script is not failing completely, but  that's about as good as 
it gets at the moment; not too exciting really.  No other letters display any 
result whatsoever.

I am guessing that the way in which dictionary.cgi accesses swish dev is not
appropriate for the current swish-e-2.1-dev25 and am hoping that somebody on 
the swish list or in the development team, familiar enough with the way that 
swish-e has evolved, might have the clarity of vision to be able to point out 
what change(s) need to be made to dictionary.cgi so that it can function in 
the modern swish-e environment.

So that's my question.  What changes should be made to the script to 
enable it to "do its thing" using swish-e-2.1-dev-25 ?

Dictionary.cgi is shown below.


Andrew Lord


# Copyright (c) 2000 Bas Meijer
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#- Configurable Variables --------------------------------------------#
$searchscript = 'lookup.cgi';
# Absolute path and command to execute the SWISH searcher   
$swish = '/usr/local/bin/swish-e';

#- Standard Stuff you won't need to edit -----------------------------#
# configure the sections from the configuration files.
my $swishdir = "$ENV{'DOCUMENT_ROOT'}/SWISH-E/swish";
# find the configfile that belongs to the index
@sections = glob("$swishdir/*.conf");
foreach $section (@sections){
	open CONF,$section;
		if (/^IndexFile\s(.*)$/){
			$indexfile = $1;
			$parts{$indexfile} = $1;
		if (/^IndexName\s(.*)$/){
			$indexname = $1;
			$indexname =~ s/"//g;
	 		$parts{$indexfile} = $indexname;
		# ReplaceRules should no longer be quoted for this to work
		s|["']||g; # if they still are they're trimmed
		if( m|ReplaceRules\sreplace\s(\S*)\s(\S*)|i){
					$replace{$2} = $1;
	close CONF;

print "Content-type: text/html\n\n";

# Parse web input   
# When the pattern is used act accordingly
my $swishtags = "index=$input{index}&abstracts=CHECKED&search=";
my $pattern = $input{'l'};
my $index = $input{'index'};
# data filled in so do da thang!
# generate the select with the sections
$select = &makeselect;
        $wordlist = (&tableize(6,@words));

# S U B R O U T I N E S

sub printform{
	my $letter;
	print '<HTML><HEAD><TITLE>Dictionary</TITLE></HEAD>';
	<FORM ACTION="/cgi-bin/dictionary.cgi" METHOD=POST NAME=catalog>
	<INPUT TYPE=hidden NAME="index" VALUE="$input{index}">
	# Convenience function for large databases
    print '<A NAME="letters">Dictionary: show words starting with:<BR><FONT 
    for $letter ('a'..'m'){
        print qq|<INPUT TYPE=SUBMIT NAME=l VALUE="$letter">|;
	#print '<BR>';
    for $letter ('n'..'z'){
        print qq|<INPUT TYPE=SUBMIT NAME=l VALUE="$letter">|;
    print '</FONT></TD></TR>';
	print "<TR><TD>in: $select";
	print " </TD></TR>";
    print "</TABLE></FORM><BR CLEAR=ALL>$wordlist";
	print '</BODY></HTML>'; 
# generate the pulldown menu with the sections of the archive
sub makeselect{
	$html = '<SELECT NAME="index">';
	foreach $key (sort keys %parts){
		if($key eq $FORM{'index'}){
			$html .= qq|<OPTION SELECTED VALUE="$key">$parts{$key}|;
			$section = $parts{$key};
			$html .= qq|<OPTION VALUE="$key">$parts{$key}|;
	$html .= '</SELECT>';
	return $html;
# get data from httpd and put it in global hash input
sub getinput{
	my ($qstring,$i,$value);
	my @querylist;
		read(STDIN, $qstring, $ENV{'CONTENT_LENGTH'});
		$qstring = $ENV{'QUERY_STRING'};
	# decode input into hash table
	@querylist = split(m'&', $qstring);
	for $i (@querylist)
		($key,$value) = split(/=/, $i);
		$value =~ tr/+/ /;
		$value =~ s/%(..)/pack('c',hex($1))/eg;
		$input{$key} = $value;
	return %input;

sub makewordlist{
	$swish = '/usr/local/bin/swish-e';

	open SWISH, '-|' or exec $swish, '-D',"$swishdir/$index" 
		or exec 'echo',"$!";
	while(<SWISH>) {
		next if /^\d/;
		next unless /^$pattern/;
		($word,$numbers) = split(/:/,$_);
		if(length $numbers > 0) {
			push @words,$word;

# make a html-table from a list
sub tableize {
    my($columns,@elements) = @_;
    $rows = int(0.99 + @elements/$columns);
    # rearrange into a pretty table
    $result = "<TABLE CELLPADDING=2>";
    for ($row=0;$row<$rows;$row++) {
        $result .= "<TR>";
        for ($column=0;$column<$columns;$column++) {
            $result .= qq|<TD><A HREF="$searchscript?$swishtags| . 
			$elements[$column*$rows + $row] . '">' .
			$elements[$column*$rows + $row] . '</A></TD>';
        $result .= "</TR>";
    $result .= "</TABLE>";
    return $result;
# end of file                   
Received on Sun Jun 2 13:40:58 2002