--- trunk/scripts/dbi-indexer.pl 2006/05/08 21:05:32 131 +++ trunk/scripts/dbi-indexer.pl 2006/05/10 20:31:02 144 @@ -1,7 +1,7 @@ #!/usr/bin/perl -w use strict; -use Search::Estraier; +use Search::Estraier 0.06; use DBI; use Data::Dumper; use Encode qw/from_to/; @@ -12,36 +12,39 @@ =cut -my $node_url = 'http://localhost:1978/node/dbi'; -my $dbi = 'Pg:dbname=azop'; -my $sql = qq{ - select * from history_collection_view_cache +my $c = { + node_url => 'http://localhost:1978/node/dbi', + dbi => 'Pg:dbname=azop', + sql => qq{ + select * from history_collection_view_cache + }, + debug => 0, }; -my $debug = 0; # create and configure node my $node = new Search::Estraier::Node( - url => $node_url, + url => $c->{node_url}, user => 'admin', passwd => 'admin', croak_on_error => 1, - debug => $debug, + create => 1, + debug => $c->{debug}, ); # create DBI connection -my $dbh = DBI->connect("DBI:$dbi","","") || die $DBI::errstr; +my $dbh = DBI->connect("DBI:$c->{dbi}","","") || die $DBI::errstr; -my $sth = $dbh->prepare($sql) || die $dbh->errstr(); +my $sth = $dbh->prepare($c->{sql}) || die $dbh->errstr(); $sth->execute() || die $sth->errstr(); -warn "# columns: ",join(",",@{ $sth->{NAME} }),"\n" if ($debug); +warn "# columns: ",join(",",@{ $sth->{NAME} }),"\n" if ($c->{debug}); my $total = $sth->rows; my $i = 1; while (my $row = $sth->fetchrow_hashref() ) { - warn "# row: ",Dumper($row) if ($debug); + warn "# row: ",Dumper($row) if ($c->{debug}); # create document my $doc = new Search::Estraier::Document; @@ -71,7 +74,7 @@ print " ", int(( $i++ / $total) * 100), "%\n"; - warn "# doc draft: ",$doc->dump_draft, "\n" if ($debug); + warn "# doc draft: ",$doc->dump_draft, "\n" if ($c->{debug}); die "error: ", $node->status,"\n" unless (eval { $node->put_doc($doc) }); }