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' })
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
[email protected]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com