in reply to Indexing Files with Plucene::Simple

You create an empty hash called %documents, you loop over all keys in that hash (none, that is), and then you dump out the contents of that hash (again none). The Plucene::Simple module is not doing anything to fill that hash.

The following would work, but I think you must be expecting something different to happen, such as an automatic index of all files in the directory you give. It won't do that.

#! /usr/bin/perl -w use strict; use Plucene::Simple; use Data::Dumper; my %documents = (file1 => 'content1', file2 => 'content2'); my $index = Plucene::Simple->open( "~/MyPerl/QA/data/index" ); for my $id (keys %documents) { $index->add($id => $documents{$id}); } ...

Replies are listed 'Best First'.
Re^2: Indexing Files with Plucene::Simple
by monkfan (Curate) on Nov 04, 2004 at 02:25 UTC
    Thanks for the reply tall_man,

    Yes you are right, I am expecting an automoatic index to all files
    in ~/MyPerl/QA/data directory.

    Regards,
    Edward
    Update:
    Here are ways to populate hash from files with file name as hash key and its contents as values:
    . 1.Corion's
    map { $_ => do { local ($/,*F); open F, "<$_" or die "Error reading '$_': $!"; <F> }} glob('*') #or map{$_=>do{open my $fh,$_ or die"$_:$!";<$fh>}}glob('*')
    2.Aighearach's
    package MyPackage; sub make_hash { (local $/)=undef; my (@files,%hash); @files = @_; foreach my $file ( @files ) { open( my $fh, $file ) or next; $hash{$file} = <$file>; }; return \%hash; } __END__
    3.atcroft's
    foreach $filename (glob('*', '.*')) { open(DF, $filename) or die(); @{$hash{$filename}} = <DF>; close(DF); } #the snippet i mentioned would have had the contents in @{$hash{$fi +lename}}, #but you would have had to reassemble that back into a single strin +g, if that is what you needed)
      You might have better luck with SWISH-E. It's fast, easy to use, and has a good Perl interface.