diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/sonar-server/src/main/java/org/sonar/server/es/StickyFacetBuilder.java | 5 |
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) { |