I've tried using the sample cgi script that's provided in the Quick Start
documentation and keep getting an error
Bad keyword: `'. Please don't use commas or non-alphanumeric characters.
This comes up before I'm able to enter any search criteria. I'm running the
latest swish dev on a Solaris 8 sparc machine. Where is the script picking
up the input that it says is bad? I'll attach the search.cgi script here.
Any help will be greatly appreciated!!!! as always
Rich
# cat search.cgi
#!/usr/bin/perl
#
# Kira's simple SWISH-E search CGI
#
#use CGI::Carp qw(fatalsToBrowser);
# You'll need to change this to the document root of your webspace.
# for personal accounts, change it to /home/yourusername/public_html.
# If you're running your own server, it should be the path to your
# document root for the server, e.g. /home/htdocs
$docroot = '/export/home/apache/htdocs';
# This also must be changed; if you've used your personal account path
# above, you should change this to /~youruserid so the webserver can
# properly translate the URL for your files. For non-personal pages,
# just set this to blank.
$prefix = '';
print "Content-type:text/html\n\n";
# customize this section as appropriate for your site
print <<EndHTML;
<html><head><title>Search Results</title></head>
<body>
<h2 align="CENTER">Search Results</h2>
EndHTML
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/~!/ ~!/g;
$FORM{$name} = $value;
}
$keystring = $FORM{'keywords'};
if ($keystring =~ /^([\w\-\. ]+)$/ ) {
$topic = $1;
} else {
&dienice("Bad keyword: `$topic'. Please don't use commas or
non-alphanumeric characters.");
}
@results = `/usr/local/bin/swish-e -w "$topic" -f
/export/home/thomasr/public_html/rich.index`;
$ct = 0;
foreach $i (@results) {
# results are returned in the form:
# relevance path title filesize
# separated by spaces.
# comments start with #, and the last line starts with a ., so we're
#ignoring those:
if ($i =~ /^#/ or $i =~ /^\./) {
# errors start with 'err', so we'll pass those on to dienice:
} elsif ($i =~ /^err/) {
$i =~ s/^err/Error/;
&dienice($i);
#
} else {
($start, $title, $size) = split(/\"/,$i);
($perc, $url) = split(/ /,$start);
$perc = $perc / 1000 * 100;
$percstr = sprintf("%3.1f\%",$perc);
# since the "url" returned is really the full unix path to the file,
# you need to translate this to a proper web url. Change the docroot
# and prefix variables as described above.
$url =~ s/^$docroot/$prefix/;
print "<a href=\"$url\">$title</a> - $percstr <br>\n";
$ct = $ct + 1;
}
}
if ($ct == 0) {
print "No results found.<p>\n";
}
&do_footer;
sub do_footer {
# customize this section as appropriate for your site
print <<EndFoot;
<p>
$ct results found.<p>
</body>
</html>
EndFoot
}
sub dienice {
my($msg) = @_;
print "<h2>Error</h2>\n";
print $msg;
&do_footer;
exit;
}
# the end.
Received on Tue Jan 22 13:38:17 2002