#!/usr/local/bin/perl # # unixhelp_search # # CGI script interface to SWISH search engine # Written by Gavin Inglis June 1995 ######################################################################### # Edit the following configuration variables to customise for your site # # location of SWISH executable $SWISH = '/home/unixhelp/bin/swish'; # # location of index file $INDEX = '/home/unixhelp/index.swish'; # # URL of UNIXhelp directory $DIR_HREF = 'http://unixhelp.ed.ac.uk'; # # URL of search script $search_url = 'http://mathlab.cit.cornell.edu/CGI/unixhelp_search'; # ########################################################################## $input_line = $ENV{QUERY_STRING}; # read any arguments if ($input_line eq "") { # if none yet $search_string = ""; # use default values for form $max_hits = 20; &form; # return form exit 0; # and exit } else { &extract_args; # get $search_string and $max_hits &header; &search; &footer; exit 0; } sub extract_args { ($search_string,$max_hits) = split (/&/,$input_line); $search_string =~ s/search_term=(.*)/$1/; # strip off label $search_string =~ s/\+/ /g; # convert +s to spaces $search_string =~ s/%2B/ /g; # convert +s to spaces $max_hits =~ s/max_hits=(.*)/$1/; # strip off label } sub header { print < UNIXhelp search results: $search_string EOF } sub footer { print <
[Home] [Search] [Index]
EOF } sub try_again { print "

Try again

\n"; } sub search { if (length($search_string) == 0) { print "

\"\"No search term

\n"; print "

Please supply a word or phrase to search for.

\n"; &form2; } elsif (($max_hits < 1) || ($max_hits > 100)) { print "

\"\"Number of matches out of range

\n"; print "

$max_hits is not an appropriate value for the maximum number of matches.

\n"; print "

You can see up to 100 matches on $search_string.

\n"; print "

Please give a value between 1 and 100.

\n"; &form2; } else { print "

\"\"Search for $search_string

\n"; &interpret; } } sub interpret { print "

Your search produced the following results:

\n"; open(RESULTS,"$SWISH -f $INDEX -w \"$search_string\" |"); if (eof(RESULTS)) { &showerr("Unable to start search engine on host"); return; } $result = ; $listopen = 0; until ($result =~ /^\./) { if (($result =~ /^#/) || ($result=~ /^search/)) { 1; # search result comment } elsif ($result =~ /^err: /) { &showerr("$'"); # search error } else { $result =~ /^\d+ (\S+) \"(.*)\"/; if ($listopen == 0) { print "
    \n"; $listopen = 1; } if ($max_hits > 0) { print "
  1. $2
  2. \n"; $max_hits-- } } } continue { $result = ; } if ($listopen == 1) { print"
\n"; } } sub showerr { local($reason) = @_; print "

Error

\n"; print "

$reason

\n"; } sub form { print < UNIXhelp Searchable Index

UNIXhelp Searchable Index

Instructions

Type the key word or words that you want to search for in the box below and then select the Search button. If you specify more than one word the search will only return documents which contain every one.

You may also change the maximum number of results which will be returned in response.

EOF &form2; &footer; } sub form2 { print <

Search for:

Max number of matches:

EOF }