#! /usr/bin/perl # Search interface for SWISH++ # Based on the script downloaded from use strict; use lib qw( /usr/lib/swish++ ); use CGI qw(:standard); # Put the path to where the WWW library is above. require WWW; require Encode; use Encode 'from_to'; #use encoding 'latin1'; #use utf8; #use locale; my $SWISH_BIN = '/usr/bin'; # The full path to the bin directory where you installed the # SWISH++ executables. my $DOC_ROOT = '/'; # The top-level directory for your document tree presumeably # where the index was generated from. my $INDEX_FILE = '/path/to/swish++.index'; # The full path to the index file to be searched through. # Main: # Redirect to search page if no parameters if ( !(param()) ) { my $redirect = "http://www.yoursite.here/search/"; print "Location: $redirect\n\n"; print "URI: $redirect\n\n"; } # Get search parameters. else { my $q = new CGI; my $search = ""; if ($q->param( 'query' )) { $search = $q->param("query"); # Add in specified options. my @options; push( @options, '-s' ) if $q->param( 'stem' ); from_to($search, "iso-8859-15", "iso-8859-1"); # Zap dangerous characters before exposing to shell; escape rest. #$search =~ s/[^\s&'()*\-=\w]/ /g; $search =~ s/[<>\/&\;:|()'\[\]=+%#]/ /g; #$search =~ s/([&'()*])/\\$1/g; #$search =~ s/[<>]//g; # Open a pipe from the 'search' command. #my $cantopen = 0; open( SEARCH, "$SWISH_BIN/search++ -i $INDEX_FILE @options $search |" ); $search =~ s/\\//g; print header(); print "Search Results for \"$search\"\n"; print "\n\t
\n\t
\n\t
\n\t
\n\n\t"; print "
\n\t
Menu
\n\t
\n\t\n\t"; print "\n\t
\n\t"; print "\n\t
\n\t"; print "
\n\t
Search
\n\t
\n\t"; print "
\n\t
\n\t\n\t\n\t
\n\t
\n\t
\n\t\n\t
\n\t"; print "
\n\n\t
\n\t"; print "
Search Results
\n\t
\n\n\t"; print "

Search Results for \"$search\"

\n\n"; my $ignored = ""; my @results = ; if (!close( SEARCH )) { # don't die, we'll handle this later #print "\n\n\nClose failed\n\n\n;" if (! -r $INDEX_FILE) { print "\t
\n\t\"Magnifying\n\t

magnifying glass ©\; by Jamez Picard

\n\t
"; print "

There seems to be a problem reading the search database. Please report this problem to the webmaster. Thank you!

"; print "
\n\t
\n\n\t"; print "
\n\t
\n\t
\n\n\t
"; print "
\n\t
\n\t
[XHTML 1.1]
This document is made with valid XHTML 1.1 markup. Check your site for (X)HTML validity with the W3C Markup Validation Service.
\n\t"; print "
[CSS3]
The style sheet markup on this page is made with valid CSS, albeit with its unfinished and as of yet experimental third version (Level 3, CSS3). Check your site for CSS validity with the W3C CSS Validation Service.
\n\t"; print "
[Creative Commons]
Some rights reserved. This site and parts thereof — unless otherwise indicated — are licensed under the Creative Commons license Attribution-NonCommercial-ShareAlike 1.0 Finland.
\n\t
\n\n\t"; print "
This site is optimized for any reasonably standards-compliant browser (both XHTML and CSS).
\n\tQuestions and comments to webmaster\@susannawinter.net.\n\t
\n\t
\n\t"; print "
\n\t
\n"; print "\n"; exit; } } elsif ($results[$#results] =~ /# results: 0/) { print "
\n\t\"Magnifying\n\t

magnifying glass ©\; by Jamez Picard

\n\t
"; print "\t

Sorry. Nothing found. Try stemming the word, using wildcards, or correcting the spelling.

\n\t"; print "
\n\t
\n\t\n\t
\n\t Stem words?\n\t
\n\t
\n\n\t"; } else { # Print the results print "\t\n\t\n\t"; # Read the search results back. my $counter = 2; #while ( ) foreach ( @results ) { if ( /^# ignored: / ) { # Get the ignored words so we can report them to the user. $ignored = $'; next; } # Future releases of SWISH++ may emit other comments: ignore ones we # don't know about. next if /^#/; my( $rank, $file, $size, $title ) = split( / /, $_, 4 ); my $desc = WWW::extract_description( "$DOC_ROOT/$file" ); WWW::hyperlink( $desc ); #$file =~ s/^\.//; $file =~ s/^\/home\/winter\/.www//; $file =~ s/index\.html$//; $size = int( $size / 1024 ); if ( $size ) { $size .= 'K'; } else { $size = '<1K'; } if ($counter % 2 == 0) { print ""; } else { print ""; } chomp($title); print "\n\t"; $counter++; } print "
RelevancePage Description
$rank%$title [$size]
$desc
\n\n\t"; } if ( $? ) { print "\t
\n\t\"Magnifying\n\t

magnifying glass ©\; by Jamez Picard

\n\t
"; print "

Malformed query. Your search contained inappropriate special characters. Try again using only alphanumeric characters.

\n\t"; print "
\n\t
\n\t\n\t
\n\t Stem words?\n\t
\n\t
\n\n\t"; } else { print "

The following search terms were omitted: $ignored\n" if $ignored; } print " \n\t \n\n\t"; print "

\n\t \n\t \n\n\t
"; print "
\n\t
\n\t
[XHTML 1.1]
This document is made with valid XHTML 1.1 markup. Check your site for (X)HTML validity with the W3C Markup Validation Service.
\n\t"; print "
[CSS3]
The style sheet markup on this page is made with valid CSS, albeit with its unfinished and as of yet experimental third version (Level 3, CSS3). Check your site for CSS validity with the W3C CSS Validation Service.
\n\t"; print "
[Creative Commons]
Some rights reserved. This site and parts thereof — unless otherwise indicated — are licensed under the Creative Commons license Attribution-NonCommercial-ShareAlike 1.0 Finland.
\n\t
\n\n\t"; print "
This site is optimized for any reasonably standards-compliant browser (both XHTML and CSS).
\n\tQuestions and comments to webmaster\@susannawinter.net.\n\t
\n\t
\n\t"; print "
\n\t \n"; print "\n"; } else { my $redirect = "http://www.yoursite.here/search/"; print "Location: $redirect\n\n"; print "URI: $redirect\n\n"; } }