0

我正在尝试用文本文件索引文件夹,并使用 lucy::simple 模块搜索包含单词的文件。到目前为止,这是我的代码:

#!/usr/bin/perl

use strict;
use warnings;
use Lucy::Simple;
use Lucy::Search::IndexSearcher;


#make_path($ch_Index);

    my $index = Lucy::Simple->new(
        path     => "/home/akpinar/Desktop/lucyindex/text",
        language => 'en',
    );

    while ( my ( $title, $content ) = each my %source_docs ) {
        my $index->add_doc({
            title    => $title,
            content  => $content,
        });
    }
    #print "Indexation finie\n"; 


###requete
    print "Veuillez taper votre requête : \n"; 
    my $requete = <STDIN>;
    chomp $requete ; 
    $requete=lc($requete); 


    my $nbTrouve = $index->search(
        query =>$requete, 
        offset=>0, 
        num_wanted=>100, 
    );

    print "Total hits: $nbTrouve\n";
    while ( my $hit = $index->next ) {
        print "$hit->{title}\n",
    }

但我得到了错误:

Failed to read seg_1
    S_try_open_elements at core/Lucy/Index/PolyReader.c line 290
    at lucyrequete.pl line 21, <STDIN> line 1.
    eval {...} called at lucyrequete.pl line 21
    lucy_PolyReader_do_open at core/Lucy/Index/PolyReader.c line 439
    at lucyrequete.pl line 21, <STDIN> line 1.

有人知道我为什么会得到这个吗?

4

1 回答 1

0

您需要先创建路径目录:

mkdir /home/akpinar/Desktop/lucyindex/text

我也很困惑,因为Lucy::SimpleLucy::Index::Indexer没有提供相同的 api。 path=>for::Simpleindex=>for ::Indexex。并且,这一秒可能会创建目录。

$indexer = Lucy::Index::Indexer->new(
schema => $schema,
index  => $outIndex,
create => 1,
truncate =>0,
);
于 2017-08-01T20:36:58.020 回答