5 |
use DBI; |
use DBI; |
6 |
use Data::Dumper; |
use Data::Dumper; |
7 |
use Encode qw/from_to/; |
use Encode qw/from_to/; |
8 |
|
use Time::HiRes qw/time/; |
9 |
|
|
10 |
=head1 NAME |
=head1 NAME |
11 |
|
|
19 |
sql => qq{ |
sql => qq{ |
20 |
select * from history_collection_view_cache |
select * from history_collection_view_cache |
21 |
}, |
}, |
22 |
|
pk_col => '_id', |
23 |
db_encoding => 'iso-8859-2', |
db_encoding => 'iso-8859-2', |
24 |
debug => 0, |
debug => 0, |
25 |
}; |
}; |
45 |
my $total = $sth->rows; |
my $total = $sth->rows; |
46 |
my $i = 1; |
my $i = 1; |
47 |
|
|
48 |
|
my $t = time(); |
49 |
|
my $pk_col = $c->{pk_col} || 'id'; |
50 |
|
|
51 |
while (my $row = $sth->fetchrow_hashref() ) { |
while (my $row = $sth->fetchrow_hashref() ) { |
52 |
|
|
53 |
warn "# row: ",Dumper($row) if ($c->{debug}); |
warn "# row: ",Dumper($row) if ($c->{debug}); |
55 |
# create document |
# create document |
56 |
my $doc = new Search::Estraier::Document; |
my $doc = new Search::Estraier::Document; |
57 |
|
|
58 |
$doc->add_attr('@uri', $row->{_id}); |
if (my $id = $row->{$pk_col}) { |
59 |
|
$doc->add_attr('@uri', $id); |
60 |
|
} else { |
61 |
|
die "can't find pk_col column '$pk_col' in results\n"; |
62 |
|
} |
63 |
|
|
64 |
printf "%4d ",$i; |
printf "%4d ",$i; |
65 |
|
|
82 |
|
|
83 |
} |
} |
84 |
|
|
|
print " ", int(( $i++ / $total) * 100), "%\n"; |
|
|
|
|
85 |
warn "# doc draft: ",$doc->dump_draft, "\n" if ($c->{debug}); |
warn "# doc draft: ",$doc->dump_draft, "\n" if ($c->{debug}); |
86 |
|
|
87 |
die "error: ", $node->status,"\n" unless (eval { $node->put_doc($doc) }); |
die "error: ", $node->status,"\n" unless (eval { $node->put_doc($doc) }); |
88 |
|
|
89 |
|
printf (" %d%% %.1f/s\n", int(( $i++ / $total) * 100), ( $i / (time() - $t) ) ); |
90 |
|
|
91 |
} |
} |