]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8694 make perfect name matches score higher in global search
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>
Thu, 9 Feb 2017 17:03:14 +0000 (18:03 +0100)
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>
Fri, 10 Feb 2017 17:02:55 +0000 (18:02 +0100)
server/sonar-server/src/main/java/org/sonar/server/component/index/ComponentIndexSearchFeature.java
server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexScoreTest.java

index a930855ae0f11bd78b62c3de321adeb56aa1acec..603224b04cd289acaf71760a0ca1d4f91869557c 100644 (file)
@@ -39,6 +39,13 @@ import static org.sonar.server.es.DefaultIndexSettingsElement.SORTABLE_ANALYZER;
 
 public enum ComponentIndexSearchFeature {
 
+  EXACT_IGNORE_CASE {
+    @Override
+    public QueryBuilder getQuery(String queryText) {
+      return matchQuery(SORTABLE_ANALYZER.subField(FIELD_NAME), queryText)
+        .boost(2.5f);
+    }
+  },
   PREFIX {
     @Override
     public QueryBuilder getQuery(String queryText) {
@@ -69,7 +76,7 @@ public enum ComponentIndexSearchFeature {
     @Override
     public QueryBuilder getQuery(String queryText) {
       return matchQuery(SORTABLE_ANALYZER.subField(FIELD_KEY), queryText)
-        .boost(5f);
+        .boost(50f);
     }
   };
 
index 8e9324aa581a9713e467648d86bac8f7855663e1..13ebac31f0c80b0706efd40c43071d2ff6e85796 100644 (file)
@@ -82,6 +82,13 @@ public class ComponentIndexScoreTest extends ComponentIndexTest {
       "ThisIsAVeryLongNameToSearchForAndItEndsDifferently.java");
   }
 
+  @Test
+  public void scoring_perfect_match_dispite_case_changes() {
+    assertResultOrder("sonarqube",
+      "SonarQube",
+      "SonarQube SCM Git");
+  }
+
   @Test
   public void do_not_match_wrong_file_extension() {
     ComponentDto file1 = indexFile("MyClass.java");