Fixed Issue 122: item_frequencies doesn't work if tag is also the name of a native js function

Did this by checking if the item is a native function, if it is I set it to an initial numeric value.  Future occurrences of the tag count correctly.
This commit is contained in:
Nick Vlku 2011-01-09 22:30:18 -05:00
parent ce8b3ea0a1
commit ba9813e5a3

View File

@ -1209,11 +1209,19 @@ class QuerySet(object):
db[collection].find(query).forEach(function(doc) { db[collection].find(query).forEach(function(doc) {
if (doc[field].constructor == Array) { if (doc[field].constructor == Array) {
doc[field].forEach(function(item) { doc[field].forEach(function(item) {
frequencies[item] = inc + (frequencies[item] || 0); var preValue = 0;
if (!isNaN(frequencies[item])) {
preValue = frequencies[item];
}
frequencies[item] = inc + preValue;
}); });
} else { } else {
var item = doc[field]; var item = doc[field];
frequencies[item] = inc + (frequencies[item] || 0); var preValue = 0;
if (!isNaN(frequencies[item])) {
preValue = frequencies[item];
}
frequencies[item] = inc + preValue;
} }
}); });
return frequencies; return frequencies;