home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet 1996 World Exposition
/
park.org.s3.amazonaws.com.7z
/
park.org.s3.amazonaws.com
/
cgi-bin
/
park-search.cgi
< prev
next >
Wrap
Text File
|
2017-09-21
|
4KB
|
162 lines
#!/usr/local/bin/perl -- -*-perl-*-
#
# file: swish-search.cgi
# auth: brad burdick
# desc: process swish search using specified keywords and max hits
#
eval 'exec /usr/local/bin/perl -s $0 ${1+"$@"}'
if 0;
# who am i?
($prog = $0) =~ s#.*/##;
# where we find local libraries
push(@INC, '/web/fair/cgi-bin');
# CGI processing
require 'cgi-lib.pl';
# generate HTML header
&html_header('Search Results');
# parse the form input
&parse_request(*query);
$status = 0;
if (defined(%query)) {
# perform the search
$status = &search(*query);
} else {
# error processing input
print "<h1>Error processing form input</h1>\n";
print "<hr>\n";
print "<p>\n";
print "We were unable to process the input from the search form.\n";
$status = 1;
}
# generate HTML trailer
&html_trailer;
exit $status;
#
# perform the search
#
sub search {
local(*query) = shift;
local($keywords, $maxhits, $command);
# Where is the swish program.
local($swishprog) = '/usr/local/bin/swish';
# What is the name of the swish index file
local($swishindex) = '/usr/local/swish/sources/index-park.swish';
$keywords = $query{'_keywords'};
$maxhits = $query{'_maxhits'};
$command = "$swishprog -f $swishindex -w $keywords";
if ($maxhits ne "ALL") {
$command .= " -m $maxhits";
}
open(SEARCH, "$command |") ||
die "$prog: unable to execute search engine: $!\n";
$cnt = 0;
while (<SEARCH>) {
chop;
if (/^#/) {
next; # comment
} elsif (/^\./) {
next; # END OF DATA
} elsif (/^err:/) {
&search_problem($_); # an error occurred
return 1;
} elsif (/^search words:/) {
($stuff, $search_words) = split(/:/);
# push(@matches, "<font size=+1>T</font>he results of your search using");
# push(@matches, " the keyword(s): <b>$search_words</b><p>");
} else {
($score, $url) = split(/ /);
($other, $title, $size) = split(/"/);
$cnt++;
# push(@matches, "<b>$cnt:</b> <a href=\"$url\">$title</a><br>");
push(@matches, "<li><a href=\"$url\">$title</a><br>");
push(@matches, " Score: <b>$score</b>, Size: <b>$size</b> bytes<p>");
}
}
close(SEARCH);
print "<h2>Results for the search of:</h2>";
print "<center>\n";
print "Keyword(s): <b>$keywords</b>\n";
print "Hits: <b>$cnt</b>\n";
print "<\/center>\n";
print "<hr width=\"75%\" align=\"center\">\n";
print "<p>\n";
print "<ol>\n";
print join("\n", @matches), "\n";
print "<p>\n";
print "</ol>\n";
print "<hr>\n";
return 0;
}
#
# A problem occurred in the search
#
sub search_problem {
local($error) = shift;
# Swish diagnostic constants
local($ERR_NO_RESULTS) = "err: no results";
local($ERR_NO_FILE_OPEN) = "err: could not open index file";
local($ERR_NO_DATA) = "err: no search words specified";
local($ERR_TOO_COMMON) = "err: a word is too common";
local($ERR_EMPTY_INDEX) = "err: the index file is empty";
local($ERR_UNKNOWN_INDEX) = "err: the index file format is unknown";
print "<BLOCKQUOTE>\n";
if ($error eq $ERR_NO_RESULTS) {
print "<font size=+1>N</font>o results were found.";
} elsif ($error eq $ERR_NO_FILE_OPEN) {
print "<font size=+1>T</font>he index file could not be";
print " found or opened. Contact the system administrator";
print " at <i>fairmaster\@park.org</i>";
} elsif ($error eq $ERR_NO_DATA) {
print "<font size=+1>N</font>o search words were specified.";
print " Please return to search form and enter some criteria";
print " to search for.";
} elsif ($error eq $ERR_TOO_COMMON) {
print "<font size=+1>T</font>he search words specified are";
print " too common. Please return to search form and try again.";
} elsif ($error eq $ERR_EMPTY_INDEX) {
print "<font size=+1>T</font>he index file contains";
print " no data. Contact the system administrator";
print " at <i>fairmaster\@park.org</i>";
} elsif ($error eq $ERR_UNKNOWN_INDEX) {
print "<font size=+1>T</font>he index file is unknown.";
print " Contact the system administrator";
print " at <i>fairmaster\@park.org</i>";
} else {
print "<font size=+1>A</font>n unknown error occurred. ";
print " Contact the system administrator";
print " at <i>fairmaster\@park.org</i>";
}
print "</BLOCKQUOTE>\n";
}