Commit 4c6c5045 by Tomas Dvorak

Merge pull request #63 from jamesdelonay/master

parents a1a10a63 5a718f13
...@@ -152,6 +152,7 @@ function serializeDoc(doc, maxDepth){ ...@@ -152,6 +152,7 @@ function serializeDoc(doc, maxDepth){
var interimResults = {}; //hold results here until converted to final format var interimResults = {}; //hold results here until converted to final format
// main cursor // main cursor
var numDocuments = 0;
db[collection].find(query).sort(sort).limit(limit).forEach(function(obj) { db[collection].find(query).sort(sort).limit(limit).forEach(function(obj) {
//printjson(obj) //printjson(obj)
flattened = serializeDoc(obj, maxDepth); flattened = serializeDoc(obj, maxDepth);
...@@ -174,9 +175,9 @@ db[collection].find(query).sort(sort).limit(limit).forEach(function(obj) { ...@@ -174,9 +175,9 @@ db[collection].find(query).sort(sort).limit(limit).forEach(function(obj) {
interimResults[key]['totalOccurrences']++; interimResults[key]['totalOccurrences']++;
} }
} }
numDocuments++;
}); });
var varietyResults = []; var varietyResults = [];
//now convert the interimResults into the proper format //now convert the interimResults into the proper format
for(var key in interimResults){ for(var key in interimResults){
...@@ -185,12 +186,10 @@ for(var key in interimResults){ ...@@ -185,12 +186,10 @@ for(var key in interimResults){
newEntry['_id'] = {'key':key}; newEntry['_id'] = {'key':key};
newEntry['value'] = {'types':Object.keys(entry['types'])}; newEntry['value'] = {'types':Object.keys(entry['types'])};
newEntry['totalOccurrences'] = entry['totalOccurrences']; newEntry['totalOccurrences'] = entry['totalOccurrences'];
newEntry['percentContaining'] = entry['totalOccurrences']*100/limit; newEntry['percentContaining'] = entry['totalOccurrences']*100/limit;
varietyResults.push(newEntry); varietyResults.push(newEntry);
} }
var numDocuments = db[collection].count();
// We throw away keys which end in an array index, since they are not useful // 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 // for our analysis. (We still keep the key of their parent array, though.) -JC
var filter = function(item) { var filter = function(item) {
...@@ -207,9 +206,7 @@ var map = 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.) // we don't need to set it if limit isn't being used. (it's set above.)
if(limit < numDocuments) { if(limit < numDocuments) {
var existsQuery = {}; item.totalOccurrences = db[collection].count(query);
existsQuery[keyName] = {$exists: true};
item.totalOccurrences = db[collection].count(existsQuery);
} }
item.percentContaining = (item.totalOccurrences / numDocuments) * 100.0; item.percentContaining = (item.totalOccurrences / numDocuments) * 100.0;
return item; 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