#!/bin/perl5 # this is a customizable output filter for swish output. # also reads "hidden" config info from the form # use CGI::Carp; #$debug = 1; $_ = 1; #unbuffered out print STDERR "Content-type: text/html\n\n"; # Grab the cgi routines require "/usr/local/lib/perl/cgi/cgilib.pl"; # Get the template library too #use Text::Template; # Read form input into %in and @in &ReadParse; # Required Vars ($in{'index'}) || die 'No swish index passed. Set hidden var "index"'; ($in{'words'}) || die 'Please enter some search words'; ($in{'template'}) || die 'No template passed. Set hidden var "template"'; (-f $in{'index'}) || die "swish index $in{'index'} not found."; (-f $in{'template'}) || die "template $in{'template'} not found."; # Optional vars ($in{'max'}) && ($max = '-m ' . $in{'max'}); ($in{'tags'}) && ($tags = '-t ' . $in{'tags'}); $words = $in{'words'}; # Get the results! ($debug) && print("
/usr/local/bin/swish  -f $in{'index'} $max $tags -w $in{'words'}|");


open(TPL,"$in{'template'}");
while() {
	if (/\{FORMAT(.*)\}/) {
		my $xformat = $1;
		&format($xformat);
		next;
	}
	if (/\$/) {
		eval "print \"$_\"" ;
		next;
	}
	print;
}
close(TPL);

($debug) && (print "
"); sub format { my ($format) = @_; open(SWISH,"/usr/local/bin/swish -f $in{'index'} $max $tags -w $in{'words'}|"); while() { /^\#/ && next; /^search words/ && next; #($score,$url,$title,$size) = split(' ',$_); ($score,$url,$therest) = split(' ',$_,3); $score = $score / 10; $score = $score . "%"; $url =~ /(.*\/)*(.*)/; $page = $2; $therest =~ /\"(.*)\" (.*)/; # $title changed to $3 $title = $1; $size = $2; if ($score =~ /err:/) { print "Sorry, no records were found for your search.\n"; print "The search engine returned: $_\n"; last; } if ($score != "0%") { eval "print \"$format\"\n"; } } close(SWISH); }