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
On Mon, Jan 27, 2014 at 02:05:54PM -0900, Jon Bradley wrote:> ~/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.This error doesn't seem to correspond to the script you sent.> 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", > );The Perl bindings don't use this named parameter style - just pass parameters like this: my $db = Search::Xapian::WritableDatabase->new($dbpath, DB_CREATE_OR_OPEN); But you'll also need to specify you want these constants at "use" time: use Search::Xapian (':db'); Or ':all' for all the constants. There's an example indexer here: http://trac.xapian.org/browser/svn/trunk/xapian-bindings/perl/docs/examples/simpleindex.pl Cheers, Olly
Thanks, that works fine now.
The script is almost at the end of the loop now
40 # my $idterm = "Q".$identifier;
41 my $idterm = join('',"Q",$identifier);
42 $doc->add_boolean_term($idterm);
43 $db->replace_document($idterm, $doc);
With this error:
~/dev/sandbox/Xapian-perl$ ./Index1-Xap.pl 100-objects-v1.csv db
Argument "Q1974-100" isn't numeric in subroutine entry at
./Index1-Xap.pl line 43, <$csv_fh> line 2.
I took out the dot concatinate, thinking a join would make the
variable a string but both the join and dot method give the same error
in this case.
Sorry about the other error, you are right. This error I checked does
match the code.
(\ /)
( . .) Jon's website is here:
c(")(") http://www.securityrabbit.com
On Mon, Jan 27, 2014 at 2:23 PM, Olly Betts <olly at survex.com>
wrote:> On Mon, Jan 27, 2014 at 02:05:54PM -0900, Jon Bradley wrote:
>> ~/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.
>
> This error doesn't seem to correspond to the script you sent.
>
>> 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",
>> );
>
> The Perl bindings don't use this named parameter style - just pass
> parameters like this:
>
> my $db = Search::Xapian::WritableDatabase->new($dbpath,
DB_CREATE_OR_OPEN);
>
> But you'll also need to specify you want these constants at
"use" time:
>
> use Search::Xapian (':db');
>
> Or ':all' for all the constants.
>
> There's an example indexer here:
>
>
http://trac.xapian.org/browser/svn/trunk/xapian-bindings/perl/docs/examples/simpleindex.pl
>
> Cheers,
> Olly
On 1/27/14 5:05 PM, Jon Bradley wrote:> 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 Search::Xapian ':db'; will import the constants.> 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", > );DB_CREATE_OR_OPEN is a constant so it should not be quoted. -- Peter Karman . http://peknet.com/ . peter at peknet.com
(\ /)
( . .) Jon's website is here:
c(")(") http://www.securityrabbit.com
---------- Forwarded message ----------
From: Jon Bradley <weatchu at gmail.com>
Date: Tue, Jan 28, 2014 at 9:52 AM
Subject: Re: [Xapian-discuss] Perl Search::Xapian
To: peter at peknet.com
This script now seems to work, thanks all!
now soon have to write the search.......
#!/usr/bin/perl
use strict;
use warnings;
unless ($#ARGV eq 1) { die "Usage: <cvsfile> <dbpath>\n"
};
use Search::Xapian (':db');
use Tie::Handle::CSV;
my $csvfile = $ARGV[0];
my $dbpath = $ARGV[1];
my $db = Search::Xapian::WritableDatabase->new($dbpath,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;
my $idterm = join('',"Q",$identifier);
$doc->add_boolean_term($idterm);
$db->replace_document_by_term($idterm, $doc);
}
close $fh;
(\ /)
( . .) Jon's website is here:
c(")(") http://www.securityrabbit.com
On Mon, Jan 27, 2014 at 6:19 PM, Peter Karman <peter at peknet.com>
wrote:> On 1/27/14 5:05 PM, Jon Bradley wrote:
>>
>> 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 Search::Xapian ':db';
>
> will import the constants.
>
>
>
>> 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",
>> );
>
>
>
> DB_CREATE_OR_OPEN is a constant so it should not be quoted.
>
>
> --
> Peter Karman . http://peknet.com/ . peter at peknet.com
>
>
> _______________________________________________
> Xapian-discuss mailing list
> Xapian-discuss at lists.xapian.org
> http://lists.xapian.org/mailman/listinfo/xapian-discuss