It works now. It feels a little bit clumsy and I have no clue if it is a
good solution (used as couchdb is intended) or if it performs well. Please
comment in case you see something that could be written more clearly or just
improved (syntactic sugar, please). Thanks for the help!

map:
function(doc) {
  if(doc["File"]) {
    var output = {
        "CountLineCode": doc.CountLineCode,
        "SumCyclomatic": doc.SumCyclomatic
    };
    // emit the root
    emit("*", output); // null provides a reference to the original node!

    // emit the whole path
    emit(doc["File"], output);

    // emit path elements
    var pathelements = doc["File"].split("/");
    var path = "";
    for(elem in pathelements.slice(0,-1)){
        path += pathelements[elem] + "/";
    emit(path, output);
    }

    //TODO add the "next" attribute
  }
}


reduce:
function(keys, values){
    var output = {
        "CountLineCode": 0,
        "SumCyclomatic": 0
    };

    for(var idx in values) {
        if (values[idx].CountLineCode !== undefined) {
            output.CountLineCode += values[idx].CountLineCode;
        }
        if (values[idx].SumCyclomatic !== undefined) {
            output.SumCyclomatic += values[idx].SumCyclomatic;
        }
    }
    return output;
}

Reply via email to