Commit 5a718f13 by James Delonay

now supporting the effect of limit in cases with and without query.

parent cca1ded9
......@@ -152,6 +152,7 @@ function serializeDoc(doc, maxDepth){
var interimResults = {}; //hold results here until converted to final format
// main cursor
var numDocuments = 0;
db[collection].find(query).sort(sort).limit(limit).forEach(function(obj) {
//printjson(obj)
flattened = serializeDoc(obj, maxDepth);
......@@ -174,9 +175,9 @@ db[collection].find(query).sort(sort).limit(limit).forEach(function(obj) {
interimResults[key]['totalOccurrences']++;
}
}
numDocuments++;
});
var varietyResults = [];
//now convert the interimResults into the proper format
for(var key in interimResults){
......@@ -189,8 +190,6 @@ for(var key in interimResults){
varietyResults.push(newEntry);
}
var numDocuments = db[collection].count(query);
// We throw away keys which end in an array index, since they are not useful
// for our analysis. (We still keep the key of their parent array, though.) -JC
var filter = function(item) {
......@@ -207,9 +206,7 @@ var map = function(item) {
}
// we don't need to set it if limit isn't being used. (it's set above.)
if(limit < numDocuments) {
var existsQuery = query;
existsQuery[keyName] = {$exists: true};
item.totalOccurrences = db[collection].count(existsQuery);
item.totalOccurrences = db[collection].count(query);
}
item.percentContaining = (item.totalOccurrences / numDocuments) * 100.0;
return item;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment