aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>2017-08-25 15:08:55 +0200
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>2017-09-05 08:45:43 +0200
commit92e63318a312ad5ac0c24056b2b9e74c564f0029 (patch)
tree21c1814833b3a5bcf4091df6f221d703413b5a35
parent6c2cedfbdee3cd0533cddac355fa64054f1a653b (diff)
downloadsonarqube-92e63318a312ad5ac0c24056b2b9e74c564f0029.tar.gz
sonarqube-92e63318a312ad5ac0c24056b2b9e74c564f0029.zip
SONAR-8299 let the number of issues per rule be correct, even if many rules are selected in the facet
(in the issue search)
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/es/StickyFacetBuilder.java5
1 files changed, 5 insertions, 0 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/StickyFacetBuilder.java b/server/sonar-server/src/main/java/org/sonar/server/es/StickyFacetBuilder.java
index d8e387f10f1..f1e41fa06fb 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/es/StickyFacetBuilder.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/es/StickyFacetBuilder.java
@@ -38,6 +38,7 @@ import org.elasticsearch.search.aggregations.bucket.terms.Terms.Order;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude;
+import static java.lang.Math.max;
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
public class StickyFacetBuilder {
@@ -45,6 +46,9 @@ public class StickyFacetBuilder {
private static final int FACET_DEFAULT_MIN_DOC_COUNT = 1;
private static final int FACET_DEFAULT_SIZE = 10;
private static final Order FACET_DEFAULT_ORDER = Terms.Order.count(false);
+ /** In some cases the user selects >15 items for one facet. In that case, we want to calculate the doc count for all of them (not just the first 15 items, which would be the
+ * default for the TermsAggregation). */
+ private static final int MAXIMUM_NUMBER_OF_SELECTED_ITEMS_WHOSE_DOC_COUNT_WILL_BE_CALCULATED = 50;
private static final Collector<CharSequence, ?, String> PIPE_JOINER = Collectors.joining("|");
private final QueryBuilder query;
@@ -147,6 +151,7 @@ public class StickyFacetBuilder {
.collect(PIPE_JOINER);
TermsAggregationBuilder selectedTerms = AggregationBuilders.terms(facetName + "_selected")
+ .size(max(MAXIMUM_NUMBER_OF_SELECTED_ITEMS_WHOSE_DOC_COUNT_WILL_BE_CALCULATED, includes.length()))
.field(fieldName)
.includeExclude(new IncludeExclude(includes, null));
if (subAggregation != null) {