#!/usr/local/bin/perl # *********************************************************************** # # * * # # * Copyright (c) 1996-1999 Scott Crevier * # # * All Rights Reserved Worldwide * # # * * # # * This program product material is the property of Scott Crevier. * # # * This program may be used and modified by anyone free of charge, * # # * as long as this copyright notice remains in tact. By using this * # # * code, you agree to indemnify Scott Crevier from any liability * # # * that might arise from its use. * # # * * # # * scott@crevier.org - Scott M. Crevier - www.crevier.org * # # *********************************************************************** # # * smcSwish.sh v 2.0 22-Dec-1998 * # # * * # # * This script provides a CGI interface to the SWISH search utility. * # # * SWISH can be found at: * # # * http://www.rpi.edu/dept/library/swish.11/docs/swish.html * # # * * # # * To use this, just create a form with one input field and set the * # # * action to the path of this script. Then define the variables * # # * below and you should be all set. * # # * * # # *********************************************************************** # # *********************************************************************** # # * Set some variables. * # # * $swish The path to the swish program * # # * $swishdir The path to the directory where all the needed * # # * files can be found. This is convenient if you * # # * put all the files in the same directory. But * # # * if you don't want to do that, just make sure * # # * the $index, $head and $tail variables are * # # * properly set. * # # * $index The path to your SWISH index file. * # # * $head The partial HTML file to display above the * # # * search results. * # # * $tail The partial HTML file to display below the * # # * search results. * # # * $cmdline The swish command line. The actual line you use * # # * will be soley based on your preferences. See * # # * the SWISH documentation for more info. The * # # * command line that I provide as a default is *# # *********************************************************************** # $swish = '/usr/local/bin/swish'; $swishdir = '/usr/www/users/crevier/scott/search/'; $index = $swishdir . 'index.swish'; $head = $swishdir . '_head.ht'; $tail = $swishdir . '_tail.ht'; $cmdline = "$swish -f $index -w $words"; # *********************************************************************** # # * Get the search words. * # # *********************************************************************** # $query_string = $ENV{'QUERY_STRING'}; ($j,$words) = split(/=/,$query_string); $words =~ tr/+/ /; $words =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg; # *********************************************************************** # # * Get the search results and count the number of pages returned. The * # # * SWISH command line that I use produces results that contain 10 * # # * header lines (that are not actual files found); therefore I * # # * subtract 10 from the count. This number may be different for you. * # # *********************************************************************** # @results = `$cmdline`; $count = @results; $count -= 10; # *********************************************************************** # # * Print the head file. * # # *********************************************************************** # print "Content-type: text/html\n\n"; open(F,$head) or die "$! \'$head\'"; while () { print; } close(F); # *********************************************************************** # # * Print the body of the search results. * # # *********************************************************************** # print < Matches $count Search words $words

htmlCodeA foreach (@results) { if (/^#/) { next; } if (/^search/) { next; } if (/^\.$/) { last; } /^(\d*) (.*) "(.*)" (\d*)$/; $score = $1; $url = $2; $title = $3; $bytes = $4; $kbytes = (int($bytes / 1024) + 1); print ""; print ""; print ""; print ""; print "\n"; } print "
Score Page
$score  $title (${kbytes}Kb)
\n"; print "\n\n\n"; # *********************************************************************** # # * Print the tail page. * # # *********************************************************************** # open(F,$tail) or die "$! \'$tail\'"; while () { print; } close(F); exit(0);