]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9965 allow rule descriptions longer then 32766 characters
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>
Thu, 12 Oct 2017 14:18:53 +0000 (16:18 +0200)
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>
Fri, 13 Oct 2017 08:15:55 +0000 (10:15 +0200)
server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java
server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java

index f31814645c6d9fd369dfac3493b013cc35ba0055..6aa855b856a692147e74f7f15417942808aee6c3 100644 (file)
@@ -143,7 +143,12 @@ public class RuleIndexDefinition implements IndexDefinition {
     ruleMapping.keywordFieldBuilder(FIELD_RULE_INTERNAL_KEY).disableNorms().disableSearch().build();
 
     ruleMapping.keywordFieldBuilder(FIELD_RULE_NAME).addSubFields(SORTABLE_ANALYZER, SEARCH_GRAMS_ANALYZER).build();
-    ruleMapping.keywordFieldBuilder(FIELD_RULE_HTML_DESCRIPTION).addSubFields(ENGLISH_HTML_ANALYZER).build();
+    ruleMapping.keywordFieldBuilder(FIELD_RULE_HTML_DESCRIPTION)
+      .disableSearch()
+      .disableNorms()
+      .disableSortingAndAggregating()
+      .addSubFields(ENGLISH_HTML_ANALYZER)
+      .build();
     ruleMapping.keywordFieldBuilder(FIELD_RULE_SEVERITY).disableNorms().build();
     ruleMapping.keywordFieldBuilder(FIELD_RULE_STATUS).disableNorms().build();
     ruleMapping.keywordFieldBuilder(FIELD_RULE_LANGUAGE).disableNorms().build();
index aaf4de5a8f566860b49f3d4498d53f2c11549521..e62c8c28623e87b0bb33e68251d211da090d084d 100644 (file)
@@ -21,6 +21,8 @@ package org.sonar.server.rule.index;
 
 import com.google.common.collect.ImmutableSet;
 import java.util.Collections;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.internal.MapSettings;
@@ -114,6 +116,15 @@ public class RuleIndexerTest {
         .get()
         .getHits()
         .getHits()[0]
-          .getId()).isEqualTo(doc.getId());
+        .getId()).isEqualTo(doc.getId());
+  }
+
+  @Test
+  public void index_long_rule_description() {
+    String description = IntStream.range(0, 100000).map(i -> i % 100).mapToObj(Integer::toString).collect(Collectors.joining(" "));
+    RuleDefinitionDto rule = dbTester.rules().insert(r -> r.setDescription(description));
+    underTest.commitAndIndex(dbTester.getSession(), rule.getKey());
+
+    assertThat(esTester.countDocuments(RuleIndexDefinition.INDEX_TYPE_RULE)).isEqualTo(1);
   }
 }