#!/usr/local/bin/perl ############################################################ # # # Virtual Visions :: "Fetch" Search Engine # # Script coded by Barracuda # # Email - baracuda@feartech.com # # # ############################################################ # this is the url of your site $base_url = 'http://209.25.247.19'; # this is the path equivalent of $base_url $base_dir = 'd:/http/ministryhealth_net/'; # this is the url of fetch.pl $search_url = 'http://209.25.247.19/cgibin/search/fetch.cgi'; # this is the path to header.shtml $header = 'd:/http/ministryhealth_net/cgibin/search/header.shtml'; # this is the path to footer.shtml $footer = 'd:/http/ministryhealth_net/cgibin/search/footer.shtml'; # the background color of fetch... behind the keyword field $bg = 'bgcolor=#FFFFFF'; # the directories you want to search in, note the trailing "/" # you cannot search only '' as a directory and expect it to # search all of your directories if you have $subdirs set to # yes... you must specify directories @dirs = ('mh_articles/','love_notes/'); # allow fetch to search in subdirectories of the above # directories? $subdirs = "yes"; # what types of files do you want to search in? note that # htm works for htm, html, phtml, shtml, etc... @searchtypes = ('htm','html'); ############################################################ use CGI qw(:standard); $search = new CGI; $result_num = $search->param('result_num'); $show_search = $search->param('show_search'); $show_summary = $search->param('show_summary'); $keyword = $search->param('keyword'); $page = $search->param('page'); $connector = $search->param('connector'); $case = $search->param('case'); &get_header_footer; &display_page unless $show_search eq "no"; ############################################################ @keywords = split(/\s+/,$keyword); foreach $type (@dirs) { chomp($type); $dir = "$base_dir/$type"; chdir($dir); opendir (DIR, $dir) || &cgiError ("Opening $dir Failed:", "$!"); @allfiles = readdir(DIR); $totalnum=@allfiles; closedir (DIR); for($i=1; $i<$totalnum; $i++) { if (-d $allfiles[$i]) { if ($allfiles[$i] ne "." && $allfiles[$i] ne ".." && $type ne "" && $subdirs eq "yes") { push(@dirs,"$type$allfiles[$i]/"); } } if (-f $allfiles[$i]) { ($file,$ext) = split(/\./, $allfiles[$i]); foreach $searchtype (@searchtypes) { if ($ext =~ /$searchtype/i) { open (SEARCH,"$allfiles[$i]") || &cgiError ("Open $allfiles[$i] Failed:", "$!"); @search = ; close(SEARCH); $temp_file = "$type$allfiles[$i]"; foreach $text (@search) { chomp($text); $text =~ s/<([^>]|\n)*>//g; $text =~ s/&([^;])*;//g; $text =~ s/])*-->//g; if ($connector eq "or" && $case eq "insensitive") { foreach $word (@keywords) { if (!($text =~ /$word/i)) { $match = 0; } else { $matches{$temp_file} = $text; last; } } } if ($connector eq "and" && $case eq "insensitive") { if (!($text =~ /$keyword/i)) { $match = 0; } else { $matches{$temp_file} = $text; last; } } if ($connector eq "or" && $case eq "sensitive") { foreach $word (@keywords) { if (!($text =~ /$word/)) { $match = 0; } else { $matches{$temp_file} = $text; last; } } } if ($connector eq "and" && $case eq "sensitive") { if (!($text =~ /$keyword/)) { $match = 0; } else { $matches{$temp_file} = $text; last; } } } } } } } } foreach $key (sort(keys %matches)) { push(@matches,$key); push(@summary,$matches{$key}); } &print_header; print "

Ministry Health Search Results


\n\n"; print "\n"; print "
Search Results

\n"; $total = @matches; $real_total = $total; $totalnum = int(($total + $result_num)/ $result_num); if ($page ) { ($liststart,$listend) = split(/ /,$page); } else { if ($total < $result_num) { $liststart = 0; $listend = $total; } else { $liststart = 0; $listend = $result_num; } } if ($total > $result_num) { print "

"; print ""; print ""; print ""; print ""; print "

\n"; } $first = ($liststart + 1); $last = $listend; if ($listend<=$result_num && $end<=$result_num) { $last = $total; } print "
\n"; print "Below are the results of your search for: $keyword
Documents $first - $last of $real_total Matches.

\n"; print "
\n"; if ($total eq "0") { print "Sorry, No Matches Found!
\nWe did not find anything that matched your search criteria.
Please try searching again with a different combination of keywords.\n"; } else { if ($liststart eq "$listend") { $liststart = ($liststart - 1); } for($liststart; $liststart<$listend; $liststart++) { if ($matches[$liststart]) { $match = $matches[$liststart]; $summary = $summary[$liststart]; if ($summary eq "") { $summary = "No summary available."; } print "$match
\n"; print "URL: $base_url/$match
\n"; if ($show_summary eq "yes") { print "Summary: $summary
"; } print "
\n\n"; } } } print "

Didn't find what you were looking for? Try searching again with a more specific keyword.

\n\n"; print "\n"; &print_footer; ################ # sub routines # ################ sub display_page { &print_header; print qq~

MinistryHealth Search Page


Enter a few words to search for and you will get a list of every file that contains a match.

Search For:
 Search
 As:
Keywords     Phrase
 Case:Insensitive     Sensitive
 Show
 Summaries:
Yes     No
 Results
 Per Page:
10     20     30     40     50
~; &print_footer; exit; } sub print_header { print "Content-type: text/html\n\n"; foreach $line (@dataa) { chomp($line); print "$line\n"; } } sub print_footer { foreach $line (@datab) { chomp($line); print "$line\n"; } } sub get_header_footer { open (FILEA,"$header") || &cgiError ("Reading Header Failed:", "$!"); @dataa = ; close(FILEA); open (FILEB,"$footer") || &cgiError ("Reading Footer Failed:", "$!"); @datab = ; close(FILEB); } sub cgiError { my ($error_cause,$error) = @_; if ($error_cause eq "") { $error_cause = "Error:"; } if ($error eq "") { $error = "The script encountered problems and terminated"; } &print_header; print "

$error_cause

$error

"; &print_footer; exit; }