[Xapian-discuss] Search::Xapian

Peter Karman peter at peknet.com
Mon Aug 15 02:43:59 BST 2005


Hello.

I'm new to Xapian and the Search::Xapian package. I am able to create a testing 
index with the Omega (omindex) package, and can search using the Search::Xapian 
package example. Now I am playing with a Perl indexer using Search::Xapian. 
However, I get an Abort error when trying to set_data() in a document object. 
Here's the script I am using. Any suggestions welcome.

#!/usr/bin/perl -w
#
# test indexer
#

use Search::Xapian ':all';
use File::Slurp;

my $d = 'foodb';
my $db = Search::Xapian::WritableDatabase->new( $d, DB_CREATE_OR_OPEN ) or
     die "can't create write-able db object: $!\n";

for my $file (@ARGV) {

     my $buf = read_file( $file );
     $buf =~ s,<.+?>,,sg;
     my @w = split(/\W+/,$buf);
     print scalar(@w), " words in $file\n";

     my $doc = Search::Xapian::Document->new
	or die "can't create doc object for $file: $!\n";

     $doc->set_data("filename: $file")
	or warn "can't set_data in doc object for $file: $!\n";

     my $i = 0;
     for my $word (@w) {
         $doc->add_posting( $word, ++$i ) or warn "can't add word: $!\n";
     }

     unless ( $db->add_document( $doc ) ) {
         warn "failed to add document: $file\n";
     }

}
-- 
Peter Karman  .  http://peknet.com/  .  peter at peknet.com



More information about the Xapian-discuss mailing list