]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5634 - Enforce query on aggregation in RuleIndex (and test)
authorStephane Gamard <stephane.gamard@sonarsource.com>
Tue, 7 Oct 2014 12:51:12 +0000 (14:51 +0200)
committerStephane Gamard <stephane.gamard@sonarsource.com>
Tue, 7 Oct 2014 12:51:12 +0000 (14:51 +0200)
server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java
server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexMediumTest.java

index 3207f4b5f9a83189f957f292cf723559618fc595..de01f4a74853fa1ae2033546c37dafa8bfe6b4b3 100644 (file)
@@ -345,7 +345,7 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
   protected Map<String, AggregationBuilder> getFacets(QueryBuilder query, HashMap<String, FilterBuilder> filters) {
     Map<String, AggregationBuilder> aggregations = new HashMap<String, AggregationBuilder>();
 
-    BoolFilterBuilder langFacetFilter = FilterBuilders.boolFilter();// .must(FilterBuilders.queryFilter(query));
+    BoolFilterBuilder langFacetFilter = FilterBuilders.boolFilter().must(FilterBuilders.queryFilter(query));
     for (Map.Entry<String, FilterBuilder> filter : filters.entrySet()) {
       if (filter.getKey() != RuleNormalizer.RuleField.LANGUAGE.field()) {
         langFacetFilter.must(filter.getValue());
@@ -366,7 +366,7 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
                 .size(10)
                 .minDocCount(1))));
 
-    BoolFilterBuilder tagsFacetFilter = FilterBuilders.boolFilter();// .must(FilterBuilders.queryFilter(query));
+    BoolFilterBuilder tagsFacetFilter = FilterBuilders.boolFilter().must(FilterBuilders.queryFilter(query));
     for (Map.Entry<String, FilterBuilder> filter : filters.entrySet()) {
       if (filter.getKey() != RuleNormalizer.RuleField._TAGS.field()) {
         tagsFacetFilter.must(filter.getValue());
@@ -387,7 +387,7 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
                 .size(10)
                 .minDocCount(1))));
 
-    BoolFilterBuilder repositoriesFacetFilter = FilterBuilders.boolFilter();// .must(FilterBuilders.queryFilter(query));
+    BoolFilterBuilder repositoriesFacetFilter = FilterBuilders.boolFilter().must(FilterBuilders.queryFilter(query));
     for (Map.Entry<String, FilterBuilder> filter : filters.entrySet()) {
       if (filter.getKey() != RuleNormalizer.RuleField.REPOSITORY.field()) {
         repositoriesFacetFilter.must(filter.getValue());
index d385273a4ead3221006cc1ef8e2b657bdbb6f90c..4f3ffc740661336a84e25b19c667d0d4db2f9f01 100644 (file)
@@ -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();