summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2011-07-07 13:24:37 +0200
committerfranck cuny <franck@lumberjaph.net>2011-07-07 13:24:37 +0200
commit99ea7825711a11b7fe7978838bca5880ba2e6231 (patch)
tree119cc0b0d866f29857a7e04bd06ac29b607cb7c4
parentMerge pull request #13 from gmaurice/master (diff)
parentremoved more white spaces (diff)
downloadnet-riak-99ea7825711a11b7fe7978838bca5880ba2e6231.tar.gz
Merge branch 'review/gmaurice'
* review/gmaurice:
  removed more white spaces
  perltidy + whitespaces removed
  remove white spaces
  documentation added for search
-rw-r--r--lib/Net/Riak.pm26
-rw-r--r--lib/Net/Riak/Role/REST/Search.pm18
-rw-r--r--lib/Net/Riak/Search.pm71
3 files changed, 102 insertions, 13 deletions
diff --git a/lib/Net/Riak.pm b/lib/Net/Riak.pm
index dbfc6a5..45d445a 100644
--- a/lib/Net/Riak.pm
+++ b/lib/Net/Riak.pm
@@ -37,7 +37,7 @@ sub bucket {
 1;
 
 =head1 SYNOPSIS
-    
+
     # REST interface
     my $client = Net::Riak->new(
         host => 'http://10.0.0.40:8098',
@@ -59,6 +59,14 @@ sub bucket {
     $obj = $bucket->get('new_post');
     say "title for ".$obj->key." is ".$obj->data->{title};
 
+    # Indexing and searching (REST interface)
+    $client->setup_indexing("bucket_name");
+    ...adding documents to riak...
+    my $response = $client->search(
+    	index => 'bucket_name',
+    	q 	  => 'field:value'
+    );
+
 =head1 DESCRIPTION
 
 =head2 ATTRIBUTES
@@ -117,7 +125,7 @@ Disable returning of object content in response in a store operation.
 
 If set  to true and the object has siblings these will not be available without an additional fetch.
 
-This will become the default behaviour in 0.17 
+This will become the default behaviour in 0.17
 
 =back
 
@@ -166,13 +174,25 @@ Start assembling a Map/Reduce operation
 Start assembling a Map/Reduce operation
 
 =head2 server_info (PBC only)
-    
+
     $client->server_info->{server_version};
 
 =head2 stats (REST only)
 
     say Dumper $client->stats;
 
+=head2 search (REST only)
+
+    $client->search( index => 'bucket_name', q => 'field:value' );
+
+Makes a query to the index (see L<Net::Riak::Search> for more details on parameters)
+
+=head2 setup_indexing (REST only)
+
+    $client->setup_indexing('bucket_name');
+
+Define precommit hook in order to enable indexing documents written into the given bucket
+
 =head1 SEE ALSO
 
 L<Net::Riak::MapReduce>
diff --git a/lib/Net/Riak/Role/REST/Search.pm b/lib/Net/Riak/Role/REST/Search.pm
index 642964b..b83e3d4 100644
--- a/lib/Net/Riak/Role/REST/Search.pm
+++ b/lib/Net/Riak/Role/REST/Search.pm
@@ -2,6 +2,8 @@ package Net::Riak::Role::REST::Search;
 use Moose::Role;
 use JSON;
 
+#ABSTRACT: Search interface
+
 sub search {
     my $self = shift;
     my %params = @_;
@@ -16,7 +18,7 @@ sub search {
             $self->new_request( 'GET',
                 [ $self->search_prefix, $index, "select" ], \%params );
     }
-    
+
     my $http_response = $self->send_request($request);
 
     return if (!$http_response);
@@ -32,23 +34,23 @@ sub search {
 
 sub setup_indexing {
     my ( $self, $bucket ) = @_;
-    my $request = 
+    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 ] );
@@ -56,19 +58,19 @@ sub setup_indexing {
     $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 = 
+    $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 8cf42b7..ee2ed57 100644
--- a/lib/Net/Riak/Search.pm
+++ b/lib/Net/Riak/Search.pm
@@ -1,7 +1,9 @@
-package Net::Riak::Search;
-
+package
+Net::Riak::Search;
 use Moose;
 
+#ABSTRACT: Search interface
+
 with 'Net::Riak::Role::Base' => {classes =>
       [{name => 'client', required => 0},]};
 
@@ -16,3 +18,68 @@ sub setup_indexing {
 };
 
 1;
+
+=head1 SYNOPSIS
+
+    my $client = Net::Riak->new(...);
+    my $bucket = $client->bucket('foo');
+
+    # retrieve an existing object
+    my $obj1 = $bucket->get('foo');
+
+    # create/store a new object
+    my $obj2 = $bucket->new_object('foo2', {...});
+    $object->store;
+
+    $bucket->delete_object($key, 3); # optional w val
+
+=head1 DESCRIPTION
+
+L<Net::Riak::Search> allows you to enable indexing documents for a given bucket and querying/searching the index.
+
+=head2 METHODS
+
+=head3 setup_indexing
+
+    $client->setup_indexing('bucket_name');
+
+Does the same as :
+
+    curl -X PUT -H "content-type:application/json" http://localhost:8098/riak/bucket_name -d '{"props":{"precommit":[{"mod":"riak_search_kv_hook","fun":"precommit"}]}'
+
+but takes in account previouses precommits.
+
+=head3 search
+
+    my $response = $client->search(
+        index => 'bucket_name',
+        q => 'field:value'
+    );
+    # is the same as :
+    my $response = $client->search(
+        q => 'bucket_name.field:value'
+    );
+
+Search the index
+
+=over 4
+
+=item wt => 'XML|JSON'
+
+defines the response format (XML is the default value as for Solr/Lucene)
+
+=item q
+
+the query string
+
+=item index
+
+is the default index you want to query, if no index is provided you have to add it as a prefix of the fields in the query string
+
+=item rows
+
+is the number of documents you want to be returned in the response
+
+=back
+
+More parameters are available, just check at L<http://wiki.basho.com/Riak-Search---Querying.html#Querying-via-the-Solr-Interface>