From e604855a2fe3effdb814ec019459d420b932b79a Mon Sep 17 00:00:00 2001 From: Stephane Gamard Date: Tue, 7 Oct 2014 14:51:12 +0200 Subject: [PATCH] SONAR-5634 - Enforce query on aggregation in RuleIndex (and test) --- .../main/java/org/sonar/server/rule/index/RuleIndex.java | 6 +++--- .../org/sonar/server/rule/index/RuleIndexMediumTest.java | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) 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(); -- 2.39.5