更多地使用 Perl Plucene 模块,并且创建了我的索引,我现在正尝试搜索它并返回结果。
我创建索引的代码在这里......你可以跳过这个并继续阅读:
#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;
use Try::Tiny;
my $content = $ARGV[0];
my $doc = Plucene::Document->new;
my $i=0;
$doc->add(Plucene::Document::Field->Text(content => $content));
my $analyzer = Plucene::Analysis::SimpleAnalyzer->new();
if (!(-d "solutions" )) {
$i = 1;
}
if ($i)
{
my $writer = Plucene::Index::Writer->new("solutions", $analyzer, 1); #Third param is 1 if creating new index, 0 if adding to existing
$writer->add_document($doc);
my $doc_count = $writer->doc_count;
undef $writer; # close
}
else
{
my $writer = Plucene::Index::Writer->new("solutions", $analyzer, 0);
$writer->add_document($doc);
my $doc_count = $writer->doc_count;
undef $writer; # close
}
它创建了一个名为“解决方案”的文件夹和各种文件......我假设我创建的文档的索引文件。现在我想搜索我的索引......但我没有想出任何东西。这是我的尝试,由 Plucene::Simple examples of CPAN 指导。这是在我从命令行使用参数“lol”运行上述内容之后。
#usr/bin/perl
use Plucene::Simple;
my $plucy = Plucene::Simple->open("solutions");
my @ids = $plucy->search("content : lol");
foreach(@ids)
{
print $_;
}
遗憾的是,没有打印任何内容)-=。我觉得查询索引应该很简单,但也许我自己的愚蠢限制了我这样做的能力。