1 |
#!/usr/bin/perl |
2 |
# |
3 |
# Douglas Thrift's Search Engine CGI Script |
4 |
# |
5 |
# Douglas Thrift |
6 |
# |
7 |
|
8 |
# Perl pragma |
9 |
use strict; |
10 |
use CGI qw/:standard :cgi/; |
11 |
use File::Temp qw/ tempfile tempdir /; |
12 |
|
13 |
my $root = "/usr/local/dtse"; |
14 |
my $data = "$root/data"; |
15 |
my $search = "$root/bin/Search"; |
16 |
my $index = "$data/*.xml"; |
17 |
my $page = param('p'); |
18 |
my $query = param('q'); |
19 |
my $header = "$data/header.html"; |
20 |
my $body = "$data/body.html"; |
21 |
my $footer = "$data/footer.html"; |
22 |
my $notfound = "$data/notfound.html"; |
23 |
my $pages = "$data/pages.html"; |
24 |
|
25 |
if ($page == 0) |
26 |
{ |
27 |
$page = 1; |
28 |
} |
29 |
|
30 |
my ($temphandle, $temp) = tempfile(); |
31 |
|
32 |
open($temphandle, "> $temp") || die "$0: cannot open $temp"; |
33 |
print $temphandle "$query\n"; |
34 |
close $temphandle; |
35 |
|
36 |
open(SEARCH, "$search $index -P $page -h $header -b $body -f $footer -n " . |
37 |
"$notfound -p $pages <$temp |" ) || die "$0: cannot fork $!"; |
38 |
|
39 |
print "Content-Type: text/html |
40 |
|
41 |
"; |
42 |
|
43 |
my $line; |
44 |
while($line = <SEARCH>) |
45 |
{ |
46 |
chomp($line); |
47 |
print "$line\n"; |
48 |
} |
49 |
|
50 |
close(SEARCH) || die "$0: cannot close $search: $!"; |
51 |
unlink $temp; |