On Sat, Dec 26, 2009 at 19:56, Fink Mark <[email protected]> wrote: > 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 > } > }
Why do you emit "*" and doc.["File"]? Isn't last emit enough? But if you need all this emits, map function looks ok to me. Reduce looks good too. I can't see any way of improvement, but maybe somebody else? Regards -- Paweł Stawicki http://pawelstawicki.blogspot.com http://szczecin.jug.pl http://www.java4people.com
