]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5007 - Fixed hasDebt filter in RuleIndex
authorStephane Gamard <stephane.gamard@searchbox.com>
Mon, 7 Jul 2014 14:41:36 +0000 (16:41 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Mon, 7 Jul 2014 14:41:36 +0000 (16:41 +0200)
sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java
sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexMediumTest.java

index df2756104bceab93efb59d9829eb4a91751d2bef..3906b7f27fdd751dc6bc14eb09299b29cb2b2d25 100644 (file)
@@ -58,7 +58,6 @@ import org.sonar.server.search.QueryOptions;
 import org.sonar.server.search.Result;
 
 import javax.annotation.CheckForNull;
-
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -233,16 +232,16 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
     if (debtCharacteristics != null && !debtCharacteristics.isEmpty()) {
       fb.must(
         FilterBuilders.orFilter(
-          // Match only when NOT NONE overriden
+          // Match only when NONE (overridden)
           FilterBuilders.andFilter(
             FilterBuilders.notFilter(
               FilterBuilders.termsFilter(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field(), DebtCharacteristic.NONE)),
             FilterBuilders.orFilter(
               FilterBuilders.termsFilter(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field(), debtCharacteristics),
               FilterBuilders.termsFilter(RuleNormalizer.RuleField.CHARACTERISTIC.field(), debtCharacteristics))
-            ),
+          ),
 
-          // Match only when NOT NONE overriden
+          // Match only when NOT NONE (not overridden)
           FilterBuilders.andFilter(
             FilterBuilders.orFilter(
               FilterBuilders.termsFilter(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field(), ""),
@@ -250,14 +249,19 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
             FilterBuilders.orFilter(
               FilterBuilders.termsFilter(RuleNormalizer.RuleField.DEFAULT_SUB_CHARACTERISTIC.field(), debtCharacteristics),
               FilterBuilders.termsFilter(RuleNormalizer.RuleField.DEFAULT_CHARACTERISTIC.field(), debtCharacteristics)))
-          )
-        );
+        )
+      );
     }
 
     // Debt char exist filter
     Boolean hasDebtCharacteristic = query.getHasDebtCharacteristic();
     if (hasDebtCharacteristic != null && hasDebtCharacteristic) {
-      fb.must(FilterBuilders.existsFilter(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field()));
+      fb.mustNot(
+        FilterBuilders.termsFilter(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field(), DebtCharacteristic.NONE))
+        .should(
+          FilterBuilders.existsFilter(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field()))
+        .should(
+          FilterBuilders.existsFilter(RuleNormalizer.RuleField.DEFAULT_SUB_CHARACTERISTIC.field()));
     }
 
     if (query.getAvailableSince() != null) {
index f6fd64b2513e80193461aa8f468d2ce0883598f7..3b3950d699361e1a4557eb14627c563c2f8399be 100644 (file)
@@ -24,7 +24,10 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Sets;
 import org.apache.commons.lang.time.DateUtils;
-import org.junit.*;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rule.RuleStatus;
 import org.sonar.api.rule.Severity;
@@ -47,8 +50,12 @@ import org.sonar.server.search.Result;
 import org.sonar.server.tester.ServerTester;
 
 import javax.annotation.Nullable;
-
-import java.util.*;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
 
 import static com.google.common.collect.Lists.newArrayList;
 import static org.fest.assertions.Assertions.assertThat;
@@ -284,8 +291,7 @@ public class RuleIndexMediumTest {
   }
 
   @Test
-  @Ignore("To be fixed")
-  public void search_by_has_debt_characteristic() {
+  public void search_by_has_debt_characteristic() throws InterruptedException {
     CharacteristicDto char1 = DebtTesting.newCharacteristicDto("c1")
       .setEnabled(true)
       .setName("char1");