From: Stephane Gamard Date: Tue, 7 Oct 2014 12:51:12 +0000 (+0200) Subject: SONAR-5634 - Enforce query on aggregation in RuleIndex (and test) X-Git-Tag: 4.5.1-RC1~85 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e604855a2fe3effdb814ec019459d420b932b79a;p=sonarqube.git SONAR-5634 - Enforce query on aggregation in RuleIndex (and test) --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java index 3207f4b5f9a..de01f4a7485 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java @@ -345,7 +345,7 @@ public class RuleIndex extends BaseIndex { protected Map getFacets(QueryBuilder query, HashMap filters) { Map aggregations = new HashMap(); - BoolFilterBuilder langFacetFilter = FilterBuilders.boolFilter();// .must(FilterBuilders.queryFilter(query)); + BoolFilterBuilder langFacetFilter = FilterBuilders.boolFilter().must(FilterBuilders.queryFilter(query)); for (Map.Entry filter : filters.entrySet()) { if (filter.getKey() != RuleNormalizer.RuleField.LANGUAGE.field()) { langFacetFilter.must(filter.getValue()); @@ -366,7 +366,7 @@ public class RuleIndex extends BaseIndex { .size(10) .minDocCount(1)))); - BoolFilterBuilder tagsFacetFilter = FilterBuilders.boolFilter();// .must(FilterBuilders.queryFilter(query)); + BoolFilterBuilder tagsFacetFilter = FilterBuilders.boolFilter().must(FilterBuilders.queryFilter(query)); for (Map.Entry filter : filters.entrySet()) { if (filter.getKey() != RuleNormalizer.RuleField._TAGS.field()) { tagsFacetFilter.must(filter.getValue()); @@ -387,7 +387,7 @@ public class RuleIndex extends BaseIndex { .size(10) .minDocCount(1)))); - BoolFilterBuilder repositoriesFacetFilter = FilterBuilders.boolFilter();// .must(FilterBuilders.queryFilter(query)); + BoolFilterBuilder repositoriesFacetFilter = FilterBuilders.boolFilter().must(FilterBuilders.queryFilter(query)); for (Map.Entry filter : filters.entrySet()) { if (filter.getKey() != RuleNormalizer.RuleField.REPOSITORY.field()) { repositoriesFacetFilter.must(filter.getValue()); diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexMediumTest.java index d385273a4ea..4f3ffc74066 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexMediumTest.java @@ -114,6 +114,10 @@ public class RuleIndexMediumTest extends SearchMediumTest { Result result = index.search(query, new QueryOptions().setFacet(false)); assertThat(result.getFacets()).isEmpty(); + // should not have any facet on non matching query! + result = index.search(new RuleQuery().setQueryText("aeiou"), new QueryOptions().setFacet(true)); + assertThat(result.getFacets()).isEmpty(); + // Repositories Facet is preset result = index.search(query, new QueryOptions().setFacet(true)); assertThat(result.getFacets()).isNotNull();