summary refs log tree commit diff
path: root/lib/Net
diff options
context:
space:
mode:
authorgmaurice <germain.maurice@linkfluence.net>2011-07-07 13:19:06 +0200
committergmaurice <germain.maurice@linkfluence.net>2011-07-07 13:19:06 +0200
commit08cf0c72671e94086352b03683e1ad57348bee1f (patch)
tree621a78228ff694e030ca72a4b30ab8b30e992a63 /lib/Net
parentfix conflict (diff)
downloadnet-riak-08cf0c72671e94086352b03683e1ad57348bee1f.tar.gz
documentation added for search
Diffstat (limited to '')
-rw-r--r--lib/Net/Riak.pm20
-rw-r--r--lib/Net/Riak/Role/REST/Search.pm4
-rw-r--r--lib/Net/Riak/Search.pm69
3 files changed, 91 insertions, 2 deletions
diff --git a/lib/Net/Riak.pm b/lib/Net/Riak.pm
index dbfc6a5..49a4d0f 100644
--- a/lib/Net/Riak.pm
+++ b/lib/Net/Riak.pm
@@ -58,6 +58,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
 
@@ -173,6 +181,18 @@ Start assembling a Map/Reduce operation
 
     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..6748b20 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 = @_;
@@ -71,4 +73,4 @@ sub setup_indexing {
     JSON::decode_json($http_response->content);
 } 
 
-1;
+1;
\ No newline at end of file
diff --git a/lib/Net/Riak/Search.pm b/lib/Net/Riak/Search.pm
index 8cf42b7..a6282de 100644
--- a/lib/Net/Riak/Search.pm
+++ b/lib/Net/Riak/Search.pm
@@ -1,7 +1,8 @@
 package Net::Riak::Search;
-
 use Moose;
 
+#ABSTRACT: Search interface
+
 with 'Net::Riak::Role::Base' => {classes =>
       [{name => 'client', required => 0},]};
 
@@ -16,3 +17,69 @@ 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>
\ No newline at end of file