Lucene
view release on metacpan or search on metacpan
lib/Lucene.pm view on Meta::CPAN
my $filter = new Lucene::Search::QueryFilter($query);
# query index and get results
my $hits = $searcher->search($query);
my $sorted_hits = $searcher->search($query, $sort);
my $filtered_hits = $searcher->search($query, $filter);
my $filtered_sorted_hits = $searcher->search($query, $filter, $sort);
# get number of results
my $num_hits = $hits->length();
# get fields and ranking score for each hit
for (my $i = 0; $i < $num_hits; $i++) {
my $doc = $hits->doc($i);
my $score = $hits->score($i);
my $title = $doc->get("title");
my $isbn = $doc->get("isbn");
}
# free memory and close searcher
undef $hits;
undef $query;
undef $parser;
undef $analyzer;
$searcher->close();
undef $fsdir;
undef $searcher;
}
=head2 Access index by Document number
# create index reader
my $reader = Lucene::Index::IndexReader->open($store);
# get number of docs in index
my $num_docs = $reader->numDocs();
# get the nth document
my $document = $reader->document($n);
=head2 Get/Set field boost factor
my $boost = $field->getBoost();
$field->setBoost($boost);
=head2 Query multiple fields simultaneously
my $parser = new Lucene::MultiFieldQueryParser(\@field_names, $analyzer);
my $query = $parser->parse($query_string);
# ... using different boosts per field
my %rh_boosts = { "title" => 3, "subject" => 2 };
my $parser = new Lucene::MultiFieldQueryParser(\@field_names, $analyzer, \%rh_boosts);
my $query = $parser->parse($query_string);
=head2 Close your Store
$store->close;
undef $store;
=head2 Customize Lucene's scoring formula (for Lucene experts)
It is possible to customize Lucene's scoring formula by defining your own
Similarity object using perl XS and passing it on to both the IndexWriter
and the IndexSearcher
$searcher->setSimilarity($similarity);
$writer->setSimilarity($similarity);
=head2 Merge indexes
To merge several indexes into a single one, use the following method of
IndexWriter
$writer->addIndexes(@stores);
This will add @stores to the writer's current store, and then optimize
the resulting index.
=head1 DESCRIPTION
Like it or not Lucene has become the de-facto standard for open-source
high-performance search. It has a large user-base, is well documented and has
plenty of committers. Unfortunately until recently Lucene was entirely written
in Java and therefore of relatively little use for perl programmers. Fortunately
in the recent years a group of C++ programmers led by Ben van Klinken decided
to port Java Lucene to C++.
The purpose of the module is to export the C++ Lucene API to perl and at
the same time be as close as possible to the original Java API. This has the
combined advantage of providing perl programmers with a well-documented API
and giving them access to a C++ search engine library that is supposedly faster
than the original.
=head1 CHARACTER SUPPORT
This module support both types of perl strings that are available since perl 5.8.0
that is ISO 8859-1 (Latin-1) and UTF-8 encoded strings. For UTF-8 you need to make
sure that the UTF-8 flag is on. You can achieve this by applying
utf8::upgrade($string)
to your UTF-8 string. This will garantee the internal UTF-8 flag is on.
=head1 INDEX PORTABILITY
You can copy a Lucene index directory from one platform to another and it will
work just as well.
=head1 DEVELOPMENT AND DIAGNOSTIC TOOL
Lucene comes with a handy development and diagnostic tool which allows
to access already existing Lucene indices and to display and modify
their content. This tool is currently written in Java but doesn't
require any Java programming knowledge.
You can download the tool (lukeall.jar) from the following webpage:
http://www.getopt.org/luke/
and run it with the following command:
java -jar lukeall.jar
( run in 1.392 second using v1.01-cache-2.11-cpan-f56aa216473 )