Merge branch 'dev' into indexpatches

This commit is contained in:
Ross Lawley
2011-07-11 16:58:17 +01:00
7 changed files with 130 additions and 18 deletions

View File

@@ -1453,7 +1453,7 @@ class QuerySet(object):
path = '{{~%(field)s}}'.split('.');
field = this;
for (p in path) { field = field[path[p]]; }
if (field.constructor == Array) {
if (field && field.constructor == Array) {
field.forEach(function(item) {
emit(item, 1);
});
@@ -1499,7 +1499,7 @@ class QuerySet(object):
db[collection].find(query).forEach(function(doc) {
field = doc;
for (p in path) { field = field[path[p]]; }
if (field.constructor == Array) {
if (field && field.constructor == Array) {
total += field.length;
} else {
total++;
@@ -1515,7 +1515,7 @@ class QuerySet(object):
db[collection].find(query).forEach(function(doc) {
field = doc;
for (p in path) { field = field[path[p]]; }
if (field.constructor == Array) {
if (field && field.constructor == Array) {
field.forEach(function(item) {
frequencies[item] = inc + (isNaN(frequencies[item]) ? 0: frequencies[item]);
});
@@ -1527,8 +1527,11 @@ class QuerySet(object):
return frequencies;
}
"""
return self.exec_js(freq_func, field, normalize=normalize)
data = self.exec_js(freq_func, field, normalize=normalize)
if 'undefined' in data:
data[None] = data['undefined']
del(data['undefined'])
return data
def __repr__(self):
limit = REPR_OUTPUT_SIZE + 1