#!/usr/bin/perl # ------------------------------------------------------------------- # Program: swish-cgi.pl # Author : John Millard (millarj@muohio.edu) # # -------- User defined configuration variables ----------- # Optional parameters to pass to the SWISH searcher $params = " "; # The Full name of your organization -- Printed with Search Results # $organization = "Fornits Workshop"; # The full name of your department -- Printed with search Results # $department = "Swish-e Hack Shop"; # Path to your http root for proper URL translation $httpRoot = '/home/straights/thestraights'; # Absolute path and command to execute the SWISH searcher $swish = '/home/curiosity/swishfiles/swish-e'; # URL of where you put this cgi $swishcgi = $ENV{'SCRIPT_NAME'};# # paTH TO THE swISH iNDEX fILE $index_path ="/home/straights/swishfiles/straight-swish.idx"; $recipient = "support\@fornits.com"; # ------ End of Configuration Variables ------------ use CGI qw(:all); #sub read_form # Read in form data if it exists read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the Name value pairs @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); # Un-Webify plus signs and %-encoding $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; push(@search_tags, $value), next if ($name eq 'search_tags'); $FORM{$name} = $value } if ($FORM{'query'}){ $query = $FORM{'query'}; $results =$FORM{'results'}; $month_limit= $FORM{'months'}; }elsif (param('query')){ $query = param('query'); #$FORM{'query'}; $results=0 unless $results = param('results'); #$FORM{'results'}; $month_limit=0 unless $month_limit=param('months');# $FORM{'months'}; }else{ &html_header($head1,"No Query Was specified"); &print_form; &html_trailer; exit; } if (@search_tags) { $tags = join("",@search_tags); $search_tags = "\-t $tags"; } else { $search_tags = ""; } if ($query){ &html_header($head1,"Your Search Results"); &print_form; &search_parse; &html_trailer; }else{ &html_header($head1," "); &print_form; &html_trailer; } sub print_form { my $count=0; @dir=<$BasePath/articles/*>; # To change the form that get's generated on the fly, edit the HTML below. print <

Search Form

Enter word(s). You can connect terms with and or or

Maximum # of Items

Search In the following Tags: Leave Blank to search everything
Title Tags Heading Tags Comment Tags Emphasized Text


EOF } sub search_parse # Run SWISH and parse output { #Initialize counter variable for number of results $count=0; open(SWISH, "$swish -w $query -m $results $search_tags -f $index_path|")|| die "Cant open swish
$!"; while () { # First, check to see if search produced an error chop; if ($_ eq "err: no results") {&search_error("There were no items that matched your search request");} if ($_ eq "err: could not open index file") {&search_error("Could not open SWISH Index File $index");} if ($_ eq "err: no search words specified") {&search_error("Please Enter at least one Search Word");} if ($_ eq "err: a word is too common") {&search_error("One of your search terms is too common, please try again");} # Next Line ignores lines that begin with a non-digit next unless /^\d/; push(@results, $_); ++$count; } print "

Your Search for $query, returned $count Items

\n"; print "
    \n"; foreach (@results) { select(STDOUT); ($stringone, $title, $filesize) = split(/\"/, $_); ($rank, $url) = split(/ /, $stringone); open(IN,$url) || recover(); undef($content); $go=0;$line=0; while(){ if (/[source|Date]\:/gi){$go =1}; if ($go==1){ last if length($content)>250 or $line ==100; ++$line; $content .= $_; $content=~s/\<.*?\>//sgi; $content=~s/\<\/.*?\>//sgi; $content=~s/\n/ /sgi; $content=~s/\s\s/ /sgi; } } close(IN); $url =~ s/$httpRoot//i; print "
  1. $title
    \n"; print "".$content."\n" unless $content=~ /[<|>]/sgi; print "
    Relevancy Score:     $rank Size of Document: $filesize Bytes

    \n"; } print "

\n"; } sub recover{ $OpenFlag=0; } sub search_error { &html_header(head1,"Your Search Results"); $error_message = $_[0]; print "$error_message\n"; &html_trailer; } sub html_header # This subroutine takes the document title as a command # line parameter and adds header information to the top # of the HTML document to be returned. { print header(-type => 'text/html'), start_html(-title=>$_[1], -author=>'WebMistress@Fornits.com', -meta=>{'keywords'=>'keywords', 'copyright'=>'copyright 1998 Fornits\' Workshop'}, # -bgcolor=>$Conf{'bgcolor'}, # -LINK=>$Conf{'link'}, # -ALINK=>$Conf{'alink'}, # -VLINK=>$Conf{'vlink'}, # -TEXT=>$Conf{'text'}, # -background=>"$imgpath/$Conf{'background'}" ),$_[0]; print '

'; } sub html_trailer # This subroutine prints a suitable HTML trailer { print "

\n"; print "$organization
\n"; print "$department

\n"; print '

'; print "\n\n"; exit; }