1 |
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
2 |
|
|
3 |
use strict; |
use strict; |
4 |
use Search::Estraier; |
use Search::Estraier 0.06; |
5 |
use DBI; |
use DBI; |
6 |
use Data::Dumper; |
use Data::Dumper; |
7 |
use Encode qw/from_to/; |
use Encode qw/from_to/; |
12 |
|
|
13 |
=cut |
=cut |
14 |
|
|
15 |
my $node_url = 'http://localhost:1978/node/dbi'; |
my $c = { |
16 |
my $dbi = 'Pg:dbname=azop'; |
node_url => 'http://localhost:1978/node/dbi', |
17 |
my $sql = qq{ |
dbi => 'Pg:dbname=azop', |
18 |
select * from history_collection_view_cache |
sql => qq{ |
19 |
|
select * from history_collection_view_cache |
20 |
|
}, |
21 |
|
debug => 0, |
22 |
}; |
}; |
|
my $debug = 0; |
|
23 |
|
|
24 |
# create and configure node |
# create and configure node |
25 |
my $node = new Search::Estraier::Node( |
my $node = new Search::Estraier::Node( |
26 |
url => $node_url, |
url => $c->{node_url}, |
27 |
user => 'admin', |
user => 'admin', |
28 |
passwd => 'admin', |
passwd => 'admin', |
29 |
croak_on_error => 1, |
croak_on_error => 1, |
30 |
debug => $debug, |
create => 1, |
31 |
|
debug => $c->{debug}, |
32 |
); |
); |
33 |
|
|
34 |
# create DBI connection |
# create DBI connection |
35 |
my $dbh = DBI->connect("DBI:$dbi","","") || die $DBI::errstr; |
my $dbh = DBI->connect("DBI:$c->{dbi}","","") || die $DBI::errstr; |
36 |
|
|
37 |
my $sth = $dbh->prepare($sql) || die $dbh->errstr(); |
my $sth = $dbh->prepare($c->{sql}) || die $dbh->errstr(); |
38 |
$sth->execute() || die $sth->errstr(); |
$sth->execute() || die $sth->errstr(); |
39 |
|
|
40 |
warn "# columns: ",join(",",@{ $sth->{NAME} }),"\n" if ($debug); |
warn "# columns: ",join(",",@{ $sth->{NAME} }),"\n" if ($c->{debug}); |
41 |
|
|
42 |
my $total = $sth->rows; |
my $total = $sth->rows; |
43 |
my $i = 1; |
my $i = 1; |
44 |
|
|
45 |
while (my $row = $sth->fetchrow_hashref() ) { |
while (my $row = $sth->fetchrow_hashref() ) { |
46 |
|
|
47 |
warn "# row: ",Dumper($row) if ($debug); |
warn "# row: ",Dumper($row) if ($c->{debug}); |
48 |
|
|
49 |
# create document |
# create document |
50 |
my $doc = new Search::Estraier::Document; |
my $doc = new Search::Estraier::Document; |
74 |
|
|
75 |
print " ", int(( $i++ / $total) * 100), "%\n"; |
print " ", int(( $i++ / $total) * 100), "%\n"; |
76 |
|
|
77 |
warn "# doc draft: ",$doc->dump_draft, "\n" if ($debug); |
warn "# doc draft: ",$doc->dump_draft, "\n" if ($c->{debug}); |
78 |
|
|
79 |
die "error: ", $node->status,"\n" unless (eval { $node->put_doc($doc) }); |
die "error: ", $node->status,"\n" unless (eval { $node->put_doc($doc) }); |
80 |
} |
} |