]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9980 allow to search for words >15 chars in rule descriptions
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>
Fri, 13 Oct 2017 14:23:51 +0000 (16:23 +0200)
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>
Mon, 16 Oct 2017 09:19:42 +0000 (11:19 +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/RuleIndexTest.java

index f1401b90b4c36bf06e0b0083629ba8f1b528cb7c..5825312645e86f85f090576bbb335b50b1b4f40b 100644 (file)
@@ -206,7 +206,7 @@ public class RuleIndex {
           ).boost(20f)).should(
           matchPhraseQuery(
             ENGLISH_HTML_ANALYZER.subField(FIELD_RULE_HTML_DESCRIPTION),
-            StringUtils.left(token, DefaultIndexSettings.MAXIMUM_NGRAM_LENGTH)
+            token
           ).boost(3f))
       ).forEach(textQuery::must);
       qb.should(textQuery.boost(20f));
index ad994bad979eb73dc0c680497c31a907d0d5ea9e..0c0f15ee884c7d0fa790d95e8baf3804dc331e0a 100644 (file)
@@ -218,6 +218,8 @@ public class RuleIndexTest {
     RuleDefinitionDto rule3 = createRule(rule -> rule.setRuleKey("1000").setDescription("Another great rule CWE-1000"));
     RuleDefinitionDto rule4 = createRule(rule -> rule.setRuleKey("404")
       .setDescription("<h1>HTML-Geeks</h1><p style=\"color:blue\">special formatting!</p><table><tr><td>inside</td><td>tables</td></tr></table>"));
+    RuleDefinitionDto rule5 = createRule(rule -> rule.setRuleKey("405")
+      .setDescription("internationalization missunderstandings alsdkjfnadklsjfnadkdfnsksdjfn"));
     index();
 
     // partial match at word boundary
@@ -242,15 +244,18 @@ public class RuleIndexTest {
     assertThat(underTest.search(new RuleQuery().setQueryText("and"), new SearchOptions()).getIds()).isEmpty();
     assertThat(underTest.search(new RuleQuery().setQueryText("great and shiny"), new SearchOptions()).getIds()).isEmpty();
 
-    // stopwords
-    assertThat(underTest.search(new RuleQuery().setQueryText("and"), new SearchOptions()).getIds()).isEmpty();
-    assertThat(underTest.search(new RuleQuery().setQueryText("great and shiny"), new SearchOptions()).getIds()).isEmpty();
-
     // html
     assertThat(underTest.search(new RuleQuery().setQueryText("h1"), new SearchOptions()).getIds()).isEmpty();
     assertThat(underTest.search(new RuleQuery().setQueryText("style"), new SearchOptions()).getIds()).isEmpty();
     assertThat(underTest.search(new RuleQuery().setQueryText("special"), new SearchOptions()).getIds()).containsExactlyInAnyOrder(rule4.getKey());
     assertThat(underTest.search(new RuleQuery().setQueryText("geeks formatting inside tables"), new SearchOptions()).getIds()).containsExactlyInAnyOrder(rule4.getKey());
+
+    // long words
+    assertThat(underTest.search(new RuleQuery().setQueryText("missunderstand"), new SearchOptions()).getIds()).containsExactlyInAnyOrder(rule5.getKey());
+    assertThat(underTest.search(new RuleQuery().setQueryText("missunderstandings"), new SearchOptions()).getIds()).containsExactlyInAnyOrder(rule5.getKey());
+    assertThat(underTest.search(new RuleQuery().setQueryText("alsdkjfnadklsjfnadkdfnsksdjfn"), new SearchOptions()).getIds()).containsExactlyInAnyOrder(rule5.getKey());
+    assertThat(underTest.search(new RuleQuery().setQueryText("internationalization"), new SearchOptions()).getIds()).containsExactlyInAnyOrder(rule5.getKey());
+    assertThat(underTest.search(new RuleQuery().setQueryText("internationalizationBlaBla"), new SearchOptions()).getIds()).isEmpty();
   }
 
   @Test