1 |
douglas |
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 |
douglas |
34 |
my $root = "/usr/local/dtse"; |
14 |
douglas |
1 |
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 |
|
|
print "Content-type: text/html |
26 |
|
|
|
27 |
|
|
"; |
28 |
|
|
|
29 |
|
|
if ($page == 0) |
30 |
|
|
{ |
31 |
|
|
$page = 1; |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
my ($temphandle, $temp) = tempfile(); |
35 |
|
|
|
36 |
|
|
open($temphandle, "> $temp") || die "$0: cannot open $temp"; |
37 |
|
|
print $temphandle "$query\n"; |
38 |
|
|
close $temphandle; |
39 |
|
|
|
40 |
|
|
open(SEARCH, "$search $index -P $page -h $header -b $body -f $footer -n " . |
41 |
|
|
"$notfound -p $pages <$temp |" ) || die "$0: cannot fork $!"; |
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; |