Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes filtering on array values from the micro-analysis pop-out #431

Merged
merged 3 commits into from
Aug 27, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions js/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,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