/[webpac2]/trunk/lib/WebPAC/Output/Riak.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/WebPAC/Output/Riak.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1358 - (show annotations)
Sat Nov 13 16:00:30 2010 UTC (13 years, 5 months ago) by dpavlin
File size: 2018 byte(s)
added Riak Search link
1 package WebPAC::Output::Riak;
2
3 use warnings;
4 use strict;
5
6 use base qw/WebPAC::Common WebPAC::Output Class::Accessor/;
7 __PACKAGE__->mk_accessors(qw(
8 input
9 url
10 database
11 bucket
12 ));
13
14 use Data::Dump qw/dump/;
15 use URI;
16 use Net::Riak;
17
18 =head1 NAME
19
20 WebPAC::Output::Riak - feed data into Riak Search
21
22 =head1 FUNCTIONS
23
24 =head2 init
25
26 $out->init;
27
28 =cut
29
30 sub init {
31 my $self = shift;
32 my $log = $self->_get_logger;
33
34 $log->debug('init');
35
36 my $bucket = $self->bucket || join('.', $self->database, $self->input || 'webpac2' );
37
38 $self->{_riak} = Net::Riak->new( host => $self->url );
39 $self->{_bucket} = $self->{_riak}->bucket( $bucket );
40 $self->{_bucket}->set_properties({
41 precommit => [ { mod => 'riak_search_kv_hook', fun => 'precommit' } ],
42 });
43
44 $log->info( $self->url,"/riak/$bucket" );
45 # warn dump($self->{_bucket}->get_properties);
46
47 $self->{_count} = 0;
48
49 return 1;
50 }
51
52
53 =head2 add
54
55 Adds one entry to database.
56
57 $out->add( 42, $ds );
58
59 =cut
60
61 sub add {
62 my ($self,$id,$ds) = @_;
63 my $log = $self->_get_logger;
64
65 # $log->debug( 'ds = ', $id, sub { dump($ds) } );
66
67 my $data;
68 $data->{$_} = join(' ', @{ $ds->{$_}->{search} }) foreach
69 map { m/^\d+$/ ? $_ = $_ . '_num' : $_ }
70 # add _num suffix for riak search https://wiki.basho.com/display/RIAK/Riak+Search+-+Schema
71 grep { exists $ds->{$_}->{search} }
72 keys %$ds;
73
74 my $obj = $self->{_bucket}->new_object( $id, $data );
75 $obj->store;
76
77 $log->debug( 'json = ', $id, sub { dump($data) } );
78
79 $self->{_count}++;
80
81 return 1;
82 }
83
84 =head2 finish
85
86 $out->finish;
87
88 =cut
89
90 sub finish {
91 my $self = shift;
92
93 my $log = $self->_get_logger();
94
95 $log->info('finish ', $self->{_count}, ' documents');
96
97 1;
98 }
99
100 =head1 SEE ALSO
101
102 L<https://wiki.basho.com/display/RIAK/Riak+Search>
103
104 =head1 AUTHOR
105
106 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
107
108 =head1 COPYRIGHT & LICENSE
109
110 Copyright 2010 Dobrica Pavlinusic, All Rights Reserved.
111
112 This program is free software; you can redistribute it and/or modify it
113 under the same terms as Perl itself.
114
115 =cut
116
117 1; # End of WebPAC::Output::Riak

  ViewVC Help
Powered by ViewVC 1.1.26