]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4922 Use ngram analyzer for search on rule names
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Thu, 6 Feb 2014 18:00:02 +0000 (19:00 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 7 Feb 2014 13:42:02 +0000 (14:42 +0100)
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileRuleLookup.java
sonar-server/src/main/resources/org/sonar/server/es/config/elasticsearch.json
sonar-server/src/main/resources/org/sonar/server/es/config/mappings/rule_mapping.json
sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileRuleLookupTest.java

index 0981ae2b217edcb7160df5cc1a5d7d10061f14a7..34a158fe9e28e09c008ba60e796ea86847405b9c 100644 (file)
@@ -284,7 +284,7 @@ public class QProfileRuleLookup implements ServerExtension {
     if (StringUtils.isNotBlank(query.nameOrKey())) {
       result.must(
         queryFilter(
-          multiMatchQuery(query.nameOrKey(), RuleDocument.FIELD_NAME, RuleDocument.FIELD_KEY)
+          multiMatchQuery(query.nameOrKey(), RuleDocument.FIELD_NAME + ".search", RuleDocument.FIELD_KEY)
             .operator(Operator.AND)));
     }
 
index 391462f97cf3dea2cc87910df2bcae3d99418255..96d220e81746c060f5a591df93e24143b60cb094 100644 (file)
           "type": "custom",
           "tokenizer": "keyword",
           "filter": "lowercase"
+        },
+        "rule_name": {
+          "type": "custom",
+          "tokenizer": "rule_name_ngram",
+          "filter": "lowercase"
+        }
+      },
+      "tokenizer": {
+        "rule_name_ngram": {
+          "type": "nGram",
+          "min_gram": 3,
+          "max_gram": 5,
+          "token_chars": [ "letter", "digit" ]
         }
       }
     }
index 53f87b54e6d0b008f6f5fbdf8305037f0479d4e3..d50c2deee9f56d800b8efef338600cbdddd82eaa 100644 (file)
@@ -20,7 +20,8 @@
         "type": "multi_field",
         "fields": {
           "name": { "type": "string", "index": "analyzed" },
-          "raw": { "type": "string", "index": "analyzed", "analyzer": "sortable" }
+          "raw": { "type": "string", "index": "analyzed", "analyzer": "sortable" },
+          "search": { "type": "string", "index": "analyzed", "analyzer": "rule_name" }
         }
       },
       "description": {
index 7cfd3f71f8db28fa8c89a6a5a3398d199849f36d..3813dd4e2705ba34b79d28604f79505488d4041d 100644 (file)
@@ -153,6 +153,7 @@ public class QProfileRuleLookupTest {
 
     // Match on name
     assertThat(profileRules.search(ProfileRuleQuery.create(1).setNameOrKey("Unused Check"), paging).rules()).hasSize(1);
+    assertThat(profileRules.search(ProfileRuleQuery.create(1).setNameOrKey("unus"), paging).rules()).hasSize(1);
 
     // Match on repositoryKey
     assertThat(profileRules.search(ProfileRuleQuery.create(1).addRepositoryKeys("findbugs"), paging).rules()).hasSize(1);