Hi Kari On Wed, Jun 12, 2013 at 9:09 AM, Kari Lehtomaa <lehtomaa.k...@gmail.com>wrote:
> Hi! > > I have modified Riak contrib custom JS function to sort results in reduce. > I also set the JS dir in app.config but result is > always: <<"ReferenceError: Contrib is not defined">>. I couldn't find any > instructions how to add custom JS functions to Riak. How I call it from the > reduce in Node.js? Here is my line in Node.js Map/Reduce: > .reduce('Contrib.sort', { by: 'title', order: 'desc' }) > Have you edited app.config to set `js_source_dir` in the `riak_kv` section? Once you have set that, you'll need to restart your nodes to pick up the change to app.config. After that, you should be able to edit your javascript files in that directory and only run `riak-admin js-reload` on each node to pick up those changes. [1] is the FAQ that relates to your query. I hope this is helpful. If you're looking for more information, Mattias Meyer's Riak Handbook [2] has lots of documentation on using javascript in mapreduce tasks, so it's a good resource about this. [1] http://docs.basho.com/riak/latest/cookbooks/faqs/developing-faq/#how-do-i-load-3rd-party-javascript-libraries-for-u [2] http://riakhandbook.com/ Sam > > > Here is JS code of custom sort function: > var Contrib = (function() { > return { sort: function(values, arg) { > var field = (typeof arg === "undefined" || arg === null) ? undefined : > arg.by; > var reverse = ((typeof arg === "undefined" || arg === null) ? > undefined : arg.order) === 'desc'; > values.sort(function(a, b) { > if (reverse) { > var _ref = [b, a]; > a = _ref[0]; > b = _ref[1]; > } > if (((typeof a === "undefined" || a === null) ? undefined : > a[field]) < ((typeof b === "undefined" || b === null) ? undefined : > b[field])) { > return -1; > } else if (((typeof a === "undefined" || a === null) ? undefined : > a[field]) === ((typeof b === "undefined" || b === null) ? undefined : > b[field])) { > return 0; > } else if (((typeof a === "undefined" || a === null) ? undefined : > a[field]) > ((typeof b === "undefined" || b === null) ? undefined : > b[field])) { > return 1; > } > }); > }; > } > }); > > > > - KL - > > > _______________________________________________ > 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