We wrote a recursive query as a server side JavaScript function that takes the parent "rid" as a parameter. Have not tested the performance but seems powerful and flexible, since as you traverse down you get to analyze your current results.
var db = orient.getGraph();
var root;
var roorArr;
var children = [];
var cmd;
cmd = "select from #"+ rid;
rootArr = db.command("sql",cmd,[]);
root = rootArr[0];
root = JSON.parse(root.getRecord().toJSON());
root.children = [];
children.push(root);
queryChildren(root.children, "#" + rid);
function queryChildren(childrenArray, rid) {
var arr;
var record;
var child;
arr = NavTreeGetChildrenByFullId(rid);
for (var j = 0; j < arr.length; j++) {
record = arr[ j ];
child = {};
child = JSON.parse(record.getRecord().toJSON());
child.children = [];
childrenArray.push(child);
queryChildren(child.children, child[ "@rid" ]);
}
}
return children;