I have some code:
IRiakClient riakClient = cluster.CreateClient();
var query = new RiakMapReduceQuery()
.Inputs(productBucketName)
.MapJs(m => m.Source(@"function(v,d,a) {" +
"var p = JSON.parse(v.values[0].data);" +
"var r = [];" +
"if(p.Department != '') {" +
"var o = {};" +
"o[p.Department] = 1;" +
"r.push(o);" +
"}" +
"return r;" +
"}"))
.ReduceJs(m => m.Source(@"function(v,d,a) {" +
"var r = {};" +
"for(var i in v) {" +
" for(var w in v[i]) {" +
" if(w in r) r[w] += v[i][w];" +
" else r[w] = v[i][w];" +
" }" +
"}" +
"return [r];" +
"}")
.Keep(true));
RiakResult<RiakStreamedMapReduceResult> result =
riakClient.StreamMapReduce(query);
if (result.IsSuccess)
{
foreach (RiakMapReduceResultPhase phaseResult in
result.Value.PhaseResults)
{
if (phaseResult.Success)
This is obviously using CorrugatedIron. Is what I am tying to acheive is
to essentially do the standard word count only I want to find how many
each 'Department' is in the bucket. Each document in the database is a
JSON serialized version of a Product object. One of the fields in this
document is 'Department'. It can have various values. I want to count
how many each of the distinct department names are in the bucket. This
is my first pass. The IsSuccess returns true so there are results coming
back. In the foreach loop the individual phaseResult is returning false
from the Success "method". Any ideas on how I can get this to work? Or
make it better? Thank you.
_______________________________________________
riak-users mailing list
[email protected]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com