Commit f88768a6 by Tomas Dvorak

Removed Object.keys call, property 'types' is array instead of dictionary.…

Removed Object.keys call, property 'types' is array instead of dictionary. Duplicity check on insert.
parent 5a9fc8b4
...@@ -165,13 +165,12 @@ db[collection].find(query).sort(sort).limit(limit).forEach(function(obj) { ...@@ -165,13 +165,12 @@ db[collection].find(query).sort(sort).limit(limit).forEach(function(obj) {
var valueType = varietyTypeOf(value); var valueType = varietyTypeOf(value);
if(!(key in interimResults)){ //if it's a new key we haven't seen yet if(!(key in interimResults)){ //if it's a new key we haven't seen yet
//for the moment, store 'types' as a dictionary. An easy way to prevent duplicates interimResults[key] = {'types':[valueType],'totalOccurrences':1};
var newEntry = {'types':{},'totalOccurrences':1};
newEntry['types'][valueType] = true;
interimResults[key] = newEntry;
} }
else{ //we've seen this key before else{ //we've seen this key before
interimResults[key]['types'][valueType] = true; if(interimResults[key]['types'].indexOf(valueType) == -1) {
interimResults[key]['types'].push(valueType);
}
interimResults[key]['totalOccurrences']++; interimResults[key]['totalOccurrences']++;
} }
} }
...@@ -184,7 +183,7 @@ for(var key in interimResults){ ...@@ -184,7 +183,7 @@ for(var key in interimResults){
var entry = interimResults[key]; var entry = interimResults[key];
var newEntry = {}; var newEntry = {};
newEntry['_id'] = {'key':key}; newEntry['_id'] = {'key':key};
newEntry['value'] = {'types':Object.keys(entry['types'])}; newEntry['value'] = {'types':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);
......
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