Indexation and searching with Lucy

75 Views Asked by At

I am trying to index a folder with text files, and search the files which contain a word using lucy::simple module. Here is my code so far:

#!/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",
    }

but i get the error:

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.

Does anybody know why I get this?

1

There are 1 best solutions below

0
On

You need to create the path directory first:

mkdir /home/akpinar/Desktop/lucyindex/text

I was confused too because Lucy::Simple and Lucy::Index::Indexer do not give the same api. path=> for ::Simple versus index=> for ::Indexex. And, this second may create the directory.

$indexer = Lucy::Index::Indexer->new(
schema => $schema,
index  => $outIndex,
create => 1,
truncate =>0,
);