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

Add countDistinct and cardinality for hits stats #269

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/app/panels/hits/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</div>
<div class="span2" ng-show="panel.show_stats">
<label class="small">Type</label>
<select ng-change="set_refresh(true)" class="input-small" ng-model="panel.stats_type" ng-options="f for f in ['count','min','mean','max','sum','stddev','sumOfSquares','missing']"></select>
<select ng-change="set_refresh(true)" class="input-small" ng-model="panel.stats_type" ng-options="f for f in ['count','min','mean','max','sum','stddev','sumOfSquares','missing','countDistinct','cardinality']"></select>
</div>
<div class="span2" ng-show="panel.show_stats">
<label class="small">Stats Field <tip>Not all statistics are supported for all field types. Check Solr documentation for details.</tip></label>
Expand Down
10 changes: 8 additions & 2 deletions src/app/panels/hits/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ define([
}
// if Show Stats
var stats = '';
if ($scope.panel.show_stats) {
if ($scope.panel.show_stats && ($scope.panel.stats_type === 'countDistinct' || $scope.panel.stats_type === 'cardinality')) {
stats = '&stats=true&stats.field={!'+$scope.panel.stats_type+'=true}' + $scope.panel.stats_field;
}
else if ($scope.panel.show_stats) {
stats = '&stats=true&stats.field=' + $scope.panel.stats_field;
}
var wt_json = '&wt=json';
Expand Down Expand Up @@ -151,7 +154,10 @@ define([
} else {
result_value = results[i].stats.stats_fields[$scope.panel.stats_field][$scope.panel.stats_type];
$scope.hits += results[i].stats.stats_fields[$scope.panel.stats_field][$scope.panel.stats_type];
$scope.hits = $scope.hits.toFixed($scope.panel.stats_decimal_points);
// don't round if the stats_type is countDistinct or cardinality
if (!($scope.panel.stats_type === 'countDistinct' || $scope.panel.stats_type === 'cardinality')) {
$scope.hits = $scope.hits.toFixed($scope.panel.stats_decimal_points);
}
}

// Check for error and abort if found
Expand Down