diff options
Diffstat (limited to 'lib/Net')
-rw-r--r-- | lib/Net/Riak.pm | 2 | ||||
-rw-r--r-- | lib/Net/Riak/Role/REST/Search.pm | 59 | ||||
-rw-r--r-- | lib/Net/Riak/Search.pm | 7 |
3 files changed, 56 insertions, 12 deletions
diff --git a/lib/Net/Riak.pm b/lib/Net/Riak.pm index 3210007..dbfc6a5 100644 --- a/lib/Net/Riak.pm +++ b/lib/Net/Riak.pm @@ -14,7 +14,7 @@ has client => ( is => 'rw', isa => Client_T, required => 1, - handles => [qw/is_alive all_buckets server_info stats search/] + handles => [qw/is_alive all_buckets server_info stats search setup_indexing/] ); sub BUILDARGS { diff --git a/lib/Net/Riak/Role/REST/Search.pm b/lib/Net/Riak/Role/REST/Search.pm index 161acf5..642964b 100644 --- a/lib/Net/Riak/Role/REST/Search.pm +++ b/lib/Net/Riak/Role/REST/Search.pm @@ -3,17 +3,18 @@ use Moose::Role; use JSON; sub search { - my ( $self, $params) = @_; - + my $self = shift; + my %params = @_; my $request; + $request = $self->new_request( 'GET', - [ $self->search_prefix, "select" ], $params ) unless $params->{index}; - if ( $params->{index} ){ - my $index = delete $params->{index}; + [ $self->search_prefix, "select" ], \%params ) unless $params{index}; + if ( $params{index} ){ + my $index = delete $params{index}; $request = $self->new_request( 'GET', - [ $self->search_prefix, $index, "select" ], $params ); + [ $self->search_prefix, $index, "select" ], \%params ); } my $http_response = $self->send_request($request); @@ -24,10 +25,50 @@ sub search { if ($status == 404) { return; } -use YAML::Syck; -warn Dump $http_response; - JSON::decode_json($http_response->content); + + return JSON::decode_json($http_response->content) if $params{wt} =~ /json/i; + $http_response->content; }; +sub setup_indexing { + my ( $self, $bucket ) = @_; + my $request = + $self->new_request( 'GET', + [ $self->prefix, $bucket ] ); + + my $http_response = $self->send_request($request); + + return if (!$http_response); + my $status = $http_response->code; + if ($status == 404) { + return; + } + + my $precommits = JSON::decode_json($http_response->content)->{props}->{precommit}; + + for (@$precommits){ + return JSON::decode_json($http_response->content) if $_->{mod} eq "riak_search_kv_hook"; + } + push ( @$precommits, { mod => "riak_search_kv_hook" , fun => "precommit" } ); + + $request = $self->new_request( 'PUT', [ $self->prefix, $bucket ] ); + $request->content( JSON::encode_json({ props => { precommit => $precommits } } ) ); + $request->header('Content-Type' => "application/json" ); + + $http_response = $self->send_request($request); + + return if (!$http_response); + $status = $http_response->code; + if ($status == 404) { + return; + } + $request = + $self->new_request( 'GET', + [ $self->prefix, $bucket ] ); + + $http_response = $self->send_request($request); + + JSON::decode_json($http_response->content); +} 1; diff --git a/lib/Net/Riak/Search.pm b/lib/Net/Riak/Search.pm index ac9f059..8cf42b7 100644 --- a/lib/Net/Riak/Search.pm +++ b/lib/Net/Riak/Search.pm @@ -1,7 +1,5 @@ package Net::Riak::Search; -# ABSTRACT: the riaklink object represents a link from one Riak object to another - use Moose; with 'Net::Riak::Role::Base' => {classes => @@ -12,4 +10,9 @@ sub search { $self->client->search($params); }; +sub setup_indexing { + my ($self, $bucket) = @_; + $self->client->setup_indexing($bucket); +}; + 1; |