X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=koha%2Fkoha2riak-search.pl;h=d89853ff92014c88c72d52ff3e0ad15569116f46;hb=b2b73349daa6a86172f1f41ea15464cc225b9838;hp=8035135800487e4325f85812a384ddb26a590876;hpb=de8ff6541832c306ae5b028004afe08adf25d85f;p=NoSQL-toys.git diff --git a/koha/koha2riak-search.pl b/koha/koha2riak-search.pl index 8035135..d89853f 100755 --- a/koha/koha2riak-search.pl +++ b/koha/koha2riak-search.pl @@ -2,10 +2,10 @@ use strict; use DBI; -use Net::Riak; +use RiakSearch; use Data::Dump qw/dump/; -my $limit = "limit 3"; + my $riak_url = 'http://10.60.0.92:8098'; my $dbi = 'DBI:mysql:dbname=koha;host=10.60.0.10;port=3306'; my @tables = qw( @@ -13,10 +13,19 @@ biblioitems biblio ); +my $limit; +$limit = "LIMIT $ENV{LIMIT}" if $ENV{LIMIT}; + my $dbh = DBI->connect($dbi,"","") || die $DBI::errstr; -my $riak = Net::Riak->new(host => $riak_url ); +my $riak = RiakSearch->new( $riak_url ); + +warn $riak->request( 'GET' => '/koha.marcxml' ); -#my $marcxml_bucket = $riak->bucket( 'koha.marcxml' ); +sub riak_search_kv_hook { + $riak->request( 'PUT' => shift, { props => { precommit => [ { mod => 'riak_search_kv_hook', fun => 'precommit' } ] } }); +} + +riak_search_kv_hook '/koha.marcxml'; foreach my $table ( @tables ) { @@ -26,28 +35,25 @@ foreach my $table ( @tables ) { print "import ", $sth->rows, " rows from $table pk:",dump( @pk ),"...\n"; - my $bucket = $riak->bucket( 'koha.' . $table ); + riak_search_kv_hook "koha.$table"; while (my $row = $sth->fetchrow_hashref() ) { my $key = join('_', map { $row->{$_} } @pk); if ( my $marcxml = delete $row->{marcxml} ) { - my $request = $riak->client->new_request( - 'PUT', [ 'riak', "koha.marcxml/$key" ] - ); - $request->header('Content-Type' => 'text/xml'); - $request->content($marcxml); - my $response = $riak->client->send_request($request); - - warn "$riak_url/riak/koha.marcxml/$key ", length($marcxml), " bytes\n"; - - unless ($response->is_success) { - die "Error put marcxml:", dump( $response ); - } + $riak->request( 'PUT' => "/koha.marcxml/$key", $marcxml, { + 'Content-Type' => 'text/xml', + } ); } - warn "# $key ",dump($row); +# warn "## $key ",dump($row); + + my $headers; + if ( my $biblionumber = $row->{biblionumber} ) { + $headers->{Link} = qq|; riaktag="biblio"| unless $key =~ m/biblionumber/; + } + $riak->request( 'PUT' => "/koha.$table/$key", $row, $headers ); } }