NAME
Net::LuceneWS - Interface to the Lucene Web Service
SYNOPSIS
use Net::LuceneWS;
my $ws = new Net::LuceneWS(
host => 'localhost',
port => 8080,
index => 'musicindex',
context => 'context',
);
my $ret = $ws->Search('R.E.M.', max_hits=>5, default_field=>'artist')
or die "Error: " . $ws->GetError() . "\n";
foreach my $hit ( $ret->GetHits() ) {
printf "%3d %s\n", $hit->GetScore(), $hit->GetField('artist');
}
DESCRIPTION
Interface to the Lucene indexing and searching package via lucene-ws, the Lucene Web Service.
METHODS
- new()
-
new Net::LuceneWS( host => 'localhost', port => 8080, context => 'lucene', index => 'musicindex', max_hits => 25, default_field => 'artist', debug => 1, );
Create a new Net::LuceneWS object. This constructor expects a hash of configuration settings. Alternatively, you can pass the same arguments to each of the methods described above. In this case they take precedence over arguments passed to the constructor.
host
,port
,context
andindex
are always required, either when calling the constructor or for each method call.If you set up lucene-ws as suggested,
context
has to be set to "lucene".index
is the name of the index directory.max_hits
set the maximum number of hits returned by theSearch()
method.default_field
is the default field that is used for the query. Ifdebug
is set to 1 the network dialog is printed to stderr. - Search()
-
my $results = $ws->Search('Tori Amos', %args);
Search the web service. The first parameter is the query string, the other parameters are the same as those for the constructor. The arguments
max_hits
anddefault_field
are required, additional to those listed innew()
.This method returns a Net::LuceneWS::SearchResults object or undef on error. In this case an error message is available via
GetError()
. - AddDocuments()
-
my @docs = ( { id => '1', artist => 'Tori Amos', track => 'Northern Lad' }, { id => '2', artist => 'R.E.M.', track => 'Falls to Climb' }, ); $ws->AddDocuments(\@docs, %args);
Add one or more documents to the index. Each document is a hashref
If the index doesn't exist yet it is created. In this case you have to pass an
analyzer
argument. Valid values are "SimpleAnalyzer", "StopAnalyzer", "StandardAnalyzer" and "WithStopAnalyzer". After the analyzer argument is no longer required. - UpdateDocuments()
-
my %update = ( default_field => 'id', query => '1', document => { id => 1, artist => 'Heather Nova', track => 'Storm' }, ); $ws->UpdateDocuments([\%update], %args);
Update the matching documents. This is basically a combination of the delete and add methods.
- DeleteDocuments()
-
my @delete = ( { default_field => 'artist', query => 'R.E.M.' }, ); $ws->DeleteDocuments(\@delete, %args);
Delete all documents matching the queries.
- Optimize()
-
$ws->Optimize();
Optimize the index which results in a speedup of queries. This method should be called after making larger changes to the index.
- GetError()
-
Get the error message returned by lucene-ws.
BUGS
Diagnostics could be better but that is partly due to lucene-ws.
SEE ALSO
http://lucene-ws.sourceforge.net http://lucene.apache.org
AUTHOR
Matthias Friedrich, <matt@mafr.de>
COPYRIGHT AND LICENSE
Copyright (C) 2005 by Matthias Friedrich
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 460:
You forgot a '=back' before '=head1'