#usr/bin/perl
use Plucene::Document;
use Plucene::Document::Field;
use Plucene::Index::Writer;
use Plucene::Analysis::SimpleAnalyzer;
use Plucene::Search::HitCollector;
use Plucene::Search::IndexSearcher;
use Plucene::QueryParser;
my $content = "I am the law";
my $doc = Plucene::Document->new;
$doc->add(Plucene::Document::Field->Text(content => $content));
$doc->add(Plucene::Document::Field->Text(author => "Philip Johnson"));
my $analyzer = Plucene::Analysis::SimpleAnalyzer->new();
my $writer = Plucene::Index::Writer->new("my_index", $analyzer, 1);
$writer->add_document($doc);
undef $writer; # close
my $searcher = Plucene::Search::IndexSearcher->new("my_index");
my @docs;
my $hc = Plucene::Search::HitCollector->new(collect => sub {
my ($self, $doc, $score) = @_;
push @docs, $searcher->doc($doc);
});
$searcher->search_hc($query => $hc);
尽我所能,我不明白这段代码的作用。我了解熟悉的 Perl 语法以及在这方面发生了什么……但什么是 Lucene 文档、Index::Writer 等?最重要的是,当我运行这段代码时,我希望会生成一些东西……但我什么也看不到。
我知道分析器是什么...感谢在 CPAN 中链接的此文档:http: //onjava.com/pub/a/onjava/2003/01/15/lucene.html ?page=2 。但我只是不明白为什么我运行这段代码而且它似乎没有做任何事情......