At 10:01 AM 08/02/00 -0700, jmruiz@boe.es wrote:
>Hi all,
>
>Although, it is a very alpha implmentation, I would like to hear from
>all of you about the API of the perl module.
Hi Jose,
A function interfaced to the xs module would be find, but how about an
object approach?
use SwishE;
my $swish = SwishE->new();
Or
my $swish = SwishE->new(
{
max_hits => 3000,
properties => [qw/name date/],
search => 'foo or "bah zaz"',
begin_date => time - 30 * 24 * 3600,
}
);
$swish->properties( qw/name date/ );
$swish->dates( $yesterday, $now );
my $results = $swish->search(' (foo or baa) and baz' );
return unless $results;
my $count = $results->count;
my $result_hash = $results->first; #or $results->next;
print $result_hash->{file};
my @properties = $result_hash->{properties};
Or to go all the way, make each record returned an object, but that might
be overkill.
my $record = $results->next;
my $file = $record->file;
Or grab the results all at the same time
my $all = $result->all;
foreach ( @$all ) {
my $file = $_->{file};
my @properties = @{$_->{file}};
}
One thing that might be nice is that with this you could have separate
modules for searching and for indexing. Normally you might say "use
SwishE::Search;", but saying use "SwishE::Index;" or maybe just "use
SwishE;" then you would get full function Swish in the same interface.
BTW -- would being able to use the index header as a place to store info be
any use? Could the index header be variable length? I'm not sure what
people would put there, but it might be cool to be able to make up
additional headers when creating the index. The index header format would
have to be tagged or indexed, of course.
>
>Here is an example (sorry for the broken lines):
>
>#!/usr/local/bin/perl
>
>use SWISHE;
>
>$properties=""; # No properties
>#$properties="prop1 prop2 prop3";
>
>$handle=SWISHE::SwishOpen("../src/index.swish");
>
>$structure=1; # Related to -t option of swish-e
>$words='test'; # search string
>
>$num_results=SWISHE::SwishSearch($handle,$words,$structure,$
>properties);
>
>print "Search Results: $num_results\n";
>
>while(($rank,$filename,$title,$size,$prop1,$prop2,$prop3)=SWISHE:
>:SwishNext($handle))
>{
> print "$rank $filename \"$title\" $size \"$prop1\" \"$prop2\"
>\"$prop3\"\n";
>}
>
>SWISHE::SwishClose($handle);
>
>At this moment, this sample is working fine. There are four perl
>functions (with their equivalents in C).:
>
>SWISHE::SwishOpen: Opens the index files and returns a handle.
>SWISHE::SwishSearch: Makes the search and returns the number
>of hits.
>SWISHE::SwishNet: Reads one result
>SWISHE:.SwishClose: Closes the handle
>
>You can open as many handlers as you like.
>At this moment, there are some other things to do. The
>implementation is not thread-safe because there are several static
>variables defined in some of the functions of swish-e. It is also
>neccesary to check all the errors in a search in a better way (swish-
>e issues an exit after an error too often).
>
>If anybody wants to try or help, let me know
>
>cu
>Jose
>
>
Bill Moseley
mailto:moseley@hank.org