#!/usr/bin/perl -wT use strict; use Fcntl; use DBI; use CGI; use File::Basename; use Text::English; #input Words my ($q, $query, $type); my (@words); $q = new CGI; $query = $q->param("query"); $type = $q->param("type"); @words = split(/\s*(?:,|\s+)/, $query); my %paths = search(\@words, $type); for my $val (keys %paths) { print $q->a( { -href => "$val" }, "$val" ), $q->br; } sub search { my($words, $type) = @_; my($dbh, $match, $sth1, $sth2, $rule_append, $word, $file_index,); my %matches; my(@poss, @lists); #Database Connection: $dbh = DBI->connect( "DBI:mysql:host=localhost;database=testdb", "testuser", "testpass", {PrintError=>0,RaiseError=>1}); #Establish Rules for file type: CASE: { if($type eq "email") { $rule_append = "filetype = \"email\" "; last CASE; } if($type eq "article") { $rule_append = "filetype = \"article\" "; last CASE; } $rule_append = "filetype = \"article\" OR \"email\" "; }#End of Rule foreach $word(@$words) { my $match; ( $word ) = Text::English::stem( $word ); my @poss; #round 1: Find all file pertaining to word. my $statement1 = "SELECT files FROM catalog WHERE word LIKE \"%$word%\" "; $sth1 = $dbh -> prepare($statement1); $sth1 -> execute(); while(my @val = $sth1 -> fetchrow_array()) { $match = $val[0]; #Get List of files. push(@lists, $match); } #created list }#End of word search loop #Parse Files and Check for matches within. foreach $match(@lists) { @poss = split(/:/, $match); foreach $file_index(@poss) { $sth2 = $dbh ->prepare("select filename, filetype from library where filename = '\$file_index\' and ".$rule_append); $sth2 -> execute(); my @val2 = $sth2->fetchrow_arrayref(); #print"$@val2 $\n"; $matches{$file_index} = $type; } # All Relevant Files found. }# Cycle through all possible matches. $dbh -> disconnect(); return(%matches); }#End of search Function #### [Sun Oct 30 11:15:33 2005] [error] [client 69.119.177.200] Premature end of script headers: /www/cgi-bin/searchfunc.pl