Hi Deepak, In-line
On Tue, Sep 11, 2012 at 10:16 AM, Deepak Balasubramanyam <deepak.b...@gmail.com> wrote: > I was researching the same question and found the answer after some > tinkering around. You need a JS source function. You must write the JS > source code for the sort algorithm too. > > JSSourceFunction phaseFunction = new JSSourceFunction( > "function(v) {" + > "return v.sort(function(a, b) {" + > "return a.field - b.field ;" + > "}" + > ");" + > "}"); > IndexQuery iq = new BinValueQuery(BinIndex.named("indx_name"),"bucket", > "value"); // get an index > MapReduceResult execute = client.mapReduce(iq).addMapPhase(new > NamedJSFunction("Riak.mapValuesJson"), > false).addReducePhase(phaseFunction).execute(); > String resultRaw = execute.getResultRaw(); // Raw data > Collection<YourType> result = execute.getResult(YourType .class); // > serialized to a domain object > > The result of this operation will depend on what you return in your reduce() > function. The result may be a YourType or YourType[] etc. I wanted to > mention that since Jackson can complain about serialization issues if you > return the wrong values. > > Anyone know how to get this into a wiki ? This would probably fit better on the Riak-Java-Client wiki. https://github.com/basho/riak-java-client/wiki/TODO There's an open TODO for MapReduce examples and I know Brian would love some help with it. Care to take a stab at adding that code? Mark > > Thanks > Deepak Bala > > On Wed, Aug 29, 2012 at 5:09 PM, Oved Machlev <omach...@interwise.com> > wrote: >> >> Hi, >> >> >> >> How can I use the sorting functions over 'real' fields in the stored >> objects? How can I set the field on which I want to sort by? >> >> >> >> It seems that the following refers to the key, in my case it's a UUID, and >> therefore useless to sort by: >> >> >> >> MapReduceResult result = riakClient. >> >> mapReduce("some_bucket"). >> >> addMapPhase(new >> NamedJSFunction("Riak.mapValuesJson"), false). >> >> addReducePhase(new >> NamedErlangFunction("riak_kv_mapreduce", "reduce_sort"), true). >> >> execute(); >> >> >> >> >> >> thanks, >> >> Oved. >> >> >> _______________________________________________ >> riak-users mailing list >> riak-users@lists.basho.com >> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com >> > > > _______________________________________________ > riak-users mailing list > riak-users@lists.basho.com > http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com > _______________________________________________ riak-users mailing list riak-users@lists.basho.com http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com