#!/usr/bin/perl
#
# Copyright 1995 (c) Tim Laren Instant Internet Corp.
# Hacker Development: Tim Laren timl@instanet.com
#
# WISE Search Program
#
# This Search functionality requires an already installed and running
# Swish binary.  Get swish here: http://www.eit.com/software/swish/
# 

require '/usr/local/etc/httpd/cgi-bin/www-lib.pl';
require '/usr/local/etc/httpd/conf/wise.conf';

# This is the swish command line for searching the index file.  Leave in
# the trailing -w.
$swish = '/usr/local/bin/swish -f /var/httpd/wise/data/wise.swish -w';

require 'shellwords.pl';

%data = &GetArgs();
$i = 0;

# get the words to search for
foreach $item (%data)
{
    if($data{$item} eq "on")
    {
	$words[$i] = $item;
	$i++;
	next;
    }
    if($data{$item} =~ /^\s*$/)
    {
	next;
    }
 
    $words[$i] = $data{$item};
    $i++;
}
while($j <= $#words)
{
    if($j == $#words)
    {
	$searchfor .= "$words[$j]";
	$j++;
	next;
    }
    $searchfor .= "$words[$j] and ";
    $j++;
}

open(RESULT, "$swish '$searchfor'|");

&PrintFooter;

dbmopen(%DBdata, "$Path/$Wise", $dbmMode);
while(<RESULT>)
{
    next if /^#.*/;
    next if /^search.*/;
    next if /^\..*/;
    if(/^err.*/)
    {
	$res = "<LI>No Matches Found\n";
	next;
    }
    @data = &shellwords($_);
    
    $data[1] =~ s/$Path\/(\w*)/\1/;
    ($url, $title, $desc, $kwords) = split($split, $DBdata{$data[1]});
         $title =~ s/^\s+//;

        $itemtime = (split('\.', $data[2]))[1];

	if ($title ne "") {
        if ($desc ne "") {            # if no short description, drop the -
	    $res .= "<LI><A HREF=\"\/$url\">$title</A> - $desc<br>\n";} else {
	    $res .= "<LI><A HREF=\"\/$url\">$title</A><br>\n";}}

}
dbmclose(%DBdata);
print &Header;
print STDOUT <<"EOM";
<HTML>
<HEAD>
<TITLE>WILMA Search Results</TITLE>
</HEAD>
<body>
<H1>Search Results</H1>
<HR>

<UL>
$res
</UL>

<HR SIZE=3>

<font size=2><small>
<a href="/search">Return to search page</a><br>
Search performed by <a href="$swishURL">$swishVER</a>.<br>
This database maintained by <a href="mailto:$maintainer">$maintainer</a>.<p></small></font>
</body>
</html>
EOM

exit 0;
