| 1 | package Net::Riak::Role::REST::Search; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | $Net::Riak::Role::REST::Search::VERSION = '0.1702'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | #ABSTRACT: Search interface | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 0 | ▶ | sub search { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
search: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | my %params = @_; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | my $request; | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | $request = | ||||||||||||||||||||||||||||||||||||||||||
| 16 | $self->new_request( 'GET', | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | [ $self->search_prefix, "select" ], \%params ) unless $params{index}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | if ( $params{index} ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | my $index = delete $params{index}; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | $request = | |||||||||||||||||||||||||||||||||||||||||
| 21 | $self->new_request( 'GET', | ||||||||||||||||||||||||||||||||||||||||||
| 22 | [ $self->search_prefix, $index, "select" ], \%params ); | ||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | my $http_response = $self->send_request($request); | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | return if (!$http_response); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | my $status = $http_response->code; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | if ($status == 404) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | return JSON::decode_json($http_response->content) if $params{wt} =~ /json/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | $http_response->content; | |||||||||||||||||||||||||||||||||||||||||
| 36 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub setup_indexing { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setup_indexing: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | my ( $self, $bucket ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my $request = | |||||||||||||||||||||||||||||||||||||||||
| 41 | $self->new_request( 'GET', | ||||||||||||||||||||||||||||||||||||||||||
| 42 | [ $self->prefix, $bucket ] ); | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my $http_response = $self->send_request($request); | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | return if (!$http_response); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $status = $http_response->code; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if ($status == 404) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $precommits = JSON::decode_json($http_response->content)->{props}->{precommit}; | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | for (@$precommits){ | |||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | return JSON::decode_json($http_response->content) if $_->{mod} eq "riak_search_kv_hook"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | push ( @$precommits, { mod => "riak_search_kv_hook" , fun => "precommit" } ); | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $request = $self->new_request( 'PUT', [ $self->prefix, $bucket ] ); | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | $request->content( JSON::encode_json({ props => { precommit => $precommits } } ) ); | |||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $request->header('Content-Type' => "application/json" ); | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $http_response = $self->send_request($request); | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | return if (!$http_response); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $status = $http_response->code; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if ($status == 404) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | $request = | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $self->new_request( 'GET', | |||||||||||||||||||||||||||||||||||||||||
| 72 | [ $self->prefix, $bucket ] ); | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $http_response = $self->send_request($request); | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | JSON::decode_json($http_response->content); | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub index { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
index: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | my ($self, $bucket, $index, $first, $last) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $request; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my @req = (); | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my $org_prefix = $self->prefix; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if (defined $bucket && defined $index && defined $first) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $bucket and defined $index and defined $first
defined $bucket and defined $index
MC/DC0%0/3
defined $bucket and defined $index and defined $first
defined $bucket
defined $index
defined $first
Truth table0%0/4
A and B and C
A= defined $bucketB= defined $indexC= defined $first
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | @req = ('buckets', $bucket, 'index', $index, $first); | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | push(@req, $last) if (defined $last); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | $request = $self->new_request('GET', [ @req ]); | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my $http_response = $self->send_request($request); | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | JSON::decode_json($http_response->content)->{keys}; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | __END__ | ||||||||||||||||||||||||||||||||||||||||||