#!/usr/bin/perl # # search.pl # Copyright (c) 1996 SurfUtah.Com # written by Rus Berrett # # simple interface to SWISH # require 'util.pl'; $| = 1; # unbuffer the data # whereis swish $swishexec = "/usr/bin/swish/swish"; unless (-e $swishexec) { &print_header_info("Cannot open $swishexec"); print <Cannot open $swishexec Cannot open \"$swishexec\". File not found or permission denied.

ENDERROR &print_footer_info(); exit(0); } # get the form data &parse_form_data(*array); # required variable in the html form: # --swishindex, keywords # optional fields: # --maxresults if ($array{'swishindex'} eq "") { # not happy crappy &print_header_info("Swishindex Variable Not Specified"); print <Form Incomplete The form is incomplete.... no \"swishindex\" variable is available. The \"swishindex\" variable specifies the pathname to the swish index.

ENDERROR &print_footer_info(); exit(0); } if ($array{'keywords'} eq "") { # not happy crappy &print_header_info("Data Incomplete"); print <Data Incomplete Your request to search has been rejected due to insufficient information. To properly send your search request, please provide one or more keywords.

search example 1: john and doe or jane
search example 2: john and (doe or jane)
search example 3: not (john or jane) and doe
search example 4: j* and doe

ENDERROR &print_footer_info(); exit(0); } # everything is happy, open up a pipe to the swish executable $command = "$swishexec -f $array{'swishindex'} -w \"$array{'keywords'}\""; if ($array{'maxresults'} ne "") { $command .= " -m $array{'maxresults'}"; } &print_header_info("Search Results"); print "

Search Results

\n"; print "Keywords: $array{'keywords'}\n

\n"; open(SWISH, "$command|"); while () { # results of swish can be- # line beginning with "#" # line beginning with "." # line beginning with "err" # line beginning with "search words:" # line beginning with relevance rank [0-9] if (/^\./) { last; } elsif (/^err:/) { print "$_"; last; } elsif (/^[0-9]/) { chop; # can't simply split because spaces can exit in title $firstspace = index("$_", "\ ", 0); if ($firstspace == -1) { next; } $secondspace = index("$_", "\ ", ($firstspace+1)); if ($secondspace == -1) { next; } $lastspace = rindex("$_", "\ "); if ($lastspace == -1) { next; } $rank = substr($_, 0, $firstspace); $url = substr($_, ($firstspace+1), ($secondspace-$firstspace-1)); $title = substr($_, ($secondspace+1), ($lastspace-$secondspace-1)); $numbytes = substr($_, ($lastspace+1)); print "$rank $title ($numbytes bytes)
\n"; } } close(SWISH); if ($ENV{'PATH_INFO'} ne "") { print < Back to search form

RETURNURL } print "

\n"; &print_footer_info(); ############################################################################## # eof search.pl