]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5087 Match on name or key (like in qprofile management screen)
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 7 Mar 2014 12:45:03 +0000 (13:45 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 7 Mar 2014 12:45:09 +0000 (13:45 +0100)
sonar-server/src/main/java/org/sonar/server/rule/RuleRegistry.java
sonar-server/src/test/java/org/sonar/server/rule/RuleRegistryTest.java

index 5e68748543c6fd4db7fab00d4c89659ca80b4d92..f4237f879d1bb9a934a07bd54c570425c7103e6d 100644 (file)
@@ -130,7 +130,7 @@ public class RuleRegistry {
     BoolFilterBuilder mainFilter = FilterBuilders.boolFilter().mustNot(FilterBuilders.termFilter(RuleDocument.FIELD_STATUS, STATUS_REMOVED));
     if (StringUtils.isNotBlank(query.query())) {
       mainFilter.must(FilterBuilders.queryFilter(
-        QueryBuilders.matchQuery(RuleDocument.FIELD_NAME+".search", query.query()).operator(Operator.AND)));
+        QueryBuilders.multiMatchQuery(query.query(), RuleDocument.FIELD_NAME+".search", RuleDocument.FIELD_KEY).operator(Operator.AND)));
     }
     SearchHits hits = searchIndex.executeRequest(
       searchIndex.client().prepareSearch(INDEX_RULES).setTypes(TYPE_RULE)
index b91e362c1fb7658a36d78828cd1e6cec076edc95..cdec22ca68a0a803764abcc6ff1dae2d3023b6a1 100644 (file)
@@ -283,6 +283,10 @@ public class RuleRegistryTest {
 
     // Search is ngram based
     assertThat(registry.find(RuleQuery.builder().withPage(1).withPageSize(10).withSearchQuery("with param").build()).results()).hasSize(1);
+
+    // Search works also with key
+    assertThat(registry.find(RuleQuery.builder().withPage(1).withPageSize(10).withSearchQuery("OneIssuePerLine").build()).results()).hasSize(1);
+
   }
 
   private String testFileAsString(String testFile) throws Exception {