In Ox.api, allow for sums of text fields (= number of unique values, for example: number of artists in a list of works)

This commit is contained in:
rolux 2012-12-18 11:35:51 +01:00
parent 33db20f91c
commit 293c96a97d

View file

@ -214,7 +214,9 @@ Ox.api = function(items, options) {
}*/
});
if (options.keys || options.positions) {
result.data.items = sortBy(result.data.items, options.sort, map, options.query);
result.data.items = sortBy(
result.data.items, options.sort, map, options.query
);
}
}
if (options.positions) {
@ -230,10 +232,13 @@ Ox.api = function(items, options) {
// return totals
data = {};
api.sums.forEach(function(key) {
data[key] = Ox.sum(result.data.items.map(function(item) {
data[key] = result.data.items.map(function(item) {
return item[key];
}));
})
});
data[key] = Ox.isString(data[key][0])
? Ox.unique(data[key]).length
: Ox.sum(data[key]);
});
data.items = result.data.items.length;
if (api.geo) {
/*