Skip to content

Commit

Permalink
Merge pull request #431 from spenceralger/geo_point_filter
Browse files Browse the repository at this point in the history
Fixes filtering on array values from the micro-analysis pop-out
  • Loading branch information
spenceralger committed Aug 27, 2013
2 parents 77e1e00 + b160700 commit cb8f020
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions js/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,20 @@
};

kbn.top_field_values = function(docs,field,count) {
var counts = _.countBy(_.pluck(docs,field),function(field){
return _.isUndefined(field) ? '' : field;
var all_values = _.pluck(docs,field),
groups = {};

// manually grouping into pairs allows us to keep the original value,
_.each(all_values, function (value) {
var key = _.isUndefined(value) ? '' : value.toString();
if (_.has(groups, key)) {
groups[key][1] ++;
} else {
groups[key] = [value, 1];
}
});
return _.pairs(counts).sort(function(a, b) {

return _.values(groups).sort(function(a, b) {
return a[1] - b[1];
}).reverse().slice(0,count);
};
Expand Down

0 comments on commit cb8f020

Please sign in to comment.