#!/usr/bin/perl5 #CHANGE THE ABOVE SETTING TO WHERE PERL5 IS ON YOUR COMPUTER #usually /usr/local/bin/perl. #CHANGE THIS TO THE DIRECTORY WHERE YOUR WEB SPACE IS $filepath = "/home/boutell/html"; #CHANGE THIS TO THE FILE CONTAINING YOUR SEARCH INDEX, #created with search-index, WHICH MUST BE RUN **OFTEN** $indexFile = "searchindex.txt"; use CGI; $query = new CGI; chdir($filepath); $target = $query->param('target'); if ($target eq "") { &header; &form; &footer; exit 0; } $rule = $query->param('rule'); # Simple HTML flusher $target =~ s/\<.*?\>//g; # Case insensitive $target =~ tr/A-Z/a-z/; # If it's not a letter, it's whitespace $target =~ s/[^a-z]/ /g; @words = split(/ /, $target); if (open(IN, $indexFile)) { while ($line = ) { my($wordCount, $score); if ($line =~ /^(\S+) /) { $filename = $1; } else { next; } for $w (@words) { if ($line =~ /(\d+):$w/) { $score += $1; $wordCount ++; } } if ($rule eq "and") { if ($wordCount == int(@words)) { push @files, "$score:$filename"; } } elsif ($wordCount > 0) { push @files, "$score:$filename"; } } } &header; if (!int(@files)) { print "

Sorry, no pages were found.\n

\n"; } else { print "

The following pages were found:

\n"; } print "