[Xapian-discuss] Perl Search::Xapian

Jon Bradley weatchu at gmail.com
Mon Jan 27 23:05:54 GMT 2014


Hi,

Trying to learn Search::Xapian and be better at perl at the same time,
I'm stuck, at the DB_CREATE_OR_OPEN error.  Perl says this:

~/dev/sandbox/Xapian-perl$ ./Index1-Xap.pl 100-objects-v1.csv db
"db" is not exported by the Search::Xapian module
Can't continue after import errors at ./Index1-Xap.pl line 7.
BEGIN failed--compilation aborted at ./Index1-Xap.pl line 7.

What I did was try to convert the python example code in to Perl.
There's probably other errors, but my question is how to I deal with
the :db DB_CREATE_OR_OPEN in perl?  Been reading a lot and
my understanding of perl I guess is not the best it seems, any
help would be great, Thanks.

----------------snip---------------
#!/usr/bin/perl

use strict;
use warnings;
unless ($#ARGV eq 1) { die "Usage: <cvsfile> <dbpath>\n" };

use Search::Xapian;
use Tie::Handle::CSV;

my $csvfile = $ARGV[0];
my $dbpath = $ARGV[1];
my $db = Search::Xapian::WritableDatabase->new(
        path => $dbpath,
        mode => "DB_CREATE_OR_OPEN",
    );

# setup TermGenerator that'll be used in indexing.
my $tg = Search::Xapian::TermGenerator->new();
$tg->set_stemmer(Search::Xapian::Stem->new('en'));

# here is a for to loop thru all the csv? file.
my $fh = Tie::Handle::CSV->new($csvfile, header => 1);
while (my $csvline = <$fh>) {
    my $description = $csvline->{DESCRIPTION};
    my $title = $csvline->{TITLE};
    my $identifier = $csvline->{id_NUMBER};

    # We make a doc and tell the term generator to use this.
    my $doc = Search::Xapian::Document->new();
    $tg->set_document($doc);

    $tg->index_text($title, 1, 'S');
    $tg->index_text($description, 1, 'XD');

    # index fields without prefixes for general search.
    $tg->index_text($title);
    $tg->increase_termpos();
    $tg->index_text($description);

    # Store all the feilds for display purposes.
    # this is a TODO

    my $idterm = "Q".$identifier;
    $doc->add_boolean_term($idterm);
    $db->replace_document($idterm, $doc);
}

close $fh;
----------------snip---------------

(\ /)
( . .)   Jon's website is here:
c(")(")   http://www.securityrabbit.com



More information about the Xapian-discuss mailing list