#! /usr/bin/perl
###############################################################################
#
# Allow other Ferrets to access the data stored on this site
#
# Written by Brian White <bcwhite@verisim.com>
# Copyright (c) 1996 by Verisim, Inc.  All rights reserved.
#
###############################################################################


# Load query stuff and user profile
require query;
readConfig("query.conf");


# Load the search engine
use Ferret;


# Before anything else, output the content type
print "Content-type: text/plain\n\n";


# Get access to the required index database
$search = new Ferret;
$search->Open($indexfile);


# Print out Ferret version and format code
print "$Ferret::VERSION-1\n";


# Get the desired query...
$query = $ENV{"QUERY_STRING"};
$query =~ tr/+/ /;
$query =~ s/^<(\d+)> //;
$flags = $1;
#print "Flags=$flags, Query='$query'\n\n";


# Run the query and output the results
my $result  = $this->QueryRun($query);
my @matches = $this->QueryMatches($result);
$this->FreeQueryResult($result);
foreach (@matches) {
	print $_,"\n";
	if ($flags & 1) {	# Include summaries?
		my($summary);
		$summary = $search->DBGetSummary("$name");
		print length($summary),"\n",$summary,"\n";
	} else {
		print "0\n\n";
	}
}


# Close the index
$search->Close();
