]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8568 drop fuzzy search, to increase search result relevancy
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>
Mon, 30 Jan 2017 11:22:08 +0000 (12:22 +0100)
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>
Mon, 30 Jan 2017 17:51:39 +0000 (18:51 +0100)
server/sonar-server/src/main/java/org/sonar/server/component/index/ComponentIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/component/index/ComponentIndexSearchFeature.java
server/sonar-server/src/main/java/org/sonar/server/es/DefaultIndexSettingsElement.java
server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexFeatureFuzzyTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexMultipleWordsTest.java
server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexScoreTest.java

index 9c0ff4d5e706c730002269e5cd246666c4318e0b..651c8a404f8f499745971b316cac4f98e8c93249 100644 (file)
@@ -24,7 +24,6 @@ import org.sonar.api.config.Settings;
 import org.sonar.server.es.IndexDefinition;
 import org.sonar.server.es.NewIndex;
 
-import static org.sonar.server.es.DefaultIndexSettingsElement.FUZZY_ANALYZER;
 import static org.sonar.server.es.DefaultIndexSettingsElement.SEARCH_GRAMS_ANALYZER;
 import static org.sonar.server.es.DefaultIndexSettingsElement.SORTABLE_ANALYZER;
 
@@ -63,7 +62,7 @@ public class ComponentIndexDefinition implements IndexDefinition {
     mapping.setAttribute("_routing", ImmutableMap.of("required", "true"));
     mapping.stringFieldBuilder(FIELD_PROJECT_UUID).build();
     mapping.stringFieldBuilder(FIELD_KEY).enable(SORTABLE_ANALYZER).build();
-    mapping.stringFieldBuilder(FIELD_NAME).enable(SEARCH_GRAMS_ANALYZER, FUZZY_ANALYZER).build();
+    mapping.stringFieldBuilder(FIELD_NAME).enable(SEARCH_GRAMS_ANALYZER).build();
     mapping.stringFieldBuilder(FIELD_QUALIFIER).build();
 
     // do not store document but only indexation of information
index 1f1da83826027853ff0d016db9f418796bbd707d..f2e046f23ab320f235d000ecef473455ae990932 100644 (file)
 package org.sonar.server.component.index;
 
 import java.util.Arrays;
-import java.util.function.Function;
 import java.util.stream.Stream;
 import org.apache.commons.lang.StringUtils;
-import org.elasticsearch.common.unit.Fuzziness;
 import org.elasticsearch.index.query.BoolQueryBuilder;
 import org.elasticsearch.index.query.QueryBuilder;
 import org.sonar.server.es.DefaultIndexSettings;
 
 import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
 import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
-import static org.elasticsearch.index.query.QueryBuilders.prefixQuery;
 import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_KEY;
 import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_NAME;
-import static org.sonar.server.es.DefaultIndexSettingsElement.FUZZY_ANALYZER;
 import static org.sonar.server.es.DefaultIndexSettingsElement.SEARCH_GRAMS_ANALYZER;
 import static org.sonar.server.es.DefaultIndexSettingsElement.SORTABLE_ANALYZER;
 
@@ -43,7 +39,6 @@ public enum ComponentIndexSearchFeature {
     @Override
     public QueryBuilder getQuery(String queryText) {
       BoolQueryBuilder query = boolQuery();
-
       split(queryText)
         .map(queryTerm -> {
 
@@ -57,23 +52,6 @@ public enum ComponentIndexSearchFeature {
       return query;
     }
   },
-  FUZZY {
-    @Override
-    public QueryBuilder getQuery(String queryText) {
-      BoolQueryBuilder query = boolQuery();
-
-      split(queryText)
-        .map(((Function<String, QueryBuilder>) queryTerm -> matchQuery(FUZZY_ANALYZER.subField(FIELD_NAME), queryTerm).fuzziness(Fuzziness.AUTO))::apply)
-        .forEach(query::must);
-      return query;
-    }
-  },
-  FUZZY_PREFIX {
-    @Override
-    public QueryBuilder getQuery(String queryText) {
-      return prefixQuery(FUZZY_ANALYZER.subField(FIELD_NAME), queryText);
-    }
-  },
   KEY {
     @Override
     public QueryBuilder getQuery(String queryText) {
index cac2461a5fb36cb546cb17c1a088f86d21da2693..ee2838d822cdfbb9c8143e6d8d0099aa6fc619cf 100644 (file)
@@ -100,14 +100,6 @@ public enum DefaultIndexSettingsElement {
       set(PATTERN, "\\.");
     }
   },
-  FUZZY_TOKENIZER(TOKENIZER) {
-
-    @Override
-    protected void setup() {
-      set(TYPE, PATTERN);
-      set(PATTERN, ComponentIndexSearchFeature.SEARCH_TERM_TOKENIZER_PATTERN);
-    }
-  },
 
   // Analyzers
 
@@ -201,22 +193,6 @@ public enum DefaultIndexSettingsElement {
       setArray(FILTER, TRIM);
     }
   },
-  FUZZY_ANALYZER(ANALYZER) {
-
-    @Override
-    protected void setup() {
-      set(TOKENIZER, FUZZY_TOKENIZER);
-      setArray(FILTER, LOWERCASE);
-    }
-
-    @Override
-    public SortedMap<String, String> fieldMapping() {
-      return ImmutableSortedMap.of(
-        TYPE, STRING,
-        INDEX, ANALYZED,
-        ANALYZER, getName());
-    }
-  },
 
   ;
 
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexFeatureFuzzyTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexFeatureFuzzyTest.java
deleted file mode 100644 (file)
index 96ac233..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.component.index;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.db.component.ComponentDto;
-
-public class ComponentIndexFeatureFuzzyTest extends ComponentIndexTest {
-
-  @Before
-  public void before() {
-    features.set(ComponentIndexSearchFeature.FUZZY, ComponentIndexSearchFeature.FUZZY_PREFIX);
-  }
-
-  @Test
-  public void should_find_item_despite_missing_character() {
-    ComponentDto project = indexProject("key-1", "SonarQube");
-
-    assertSearchResults("SonrQube", project);
-  }
-
-  @Test
-  public void should_find_item_despite_missing_character_and_lowercase() {
-    ComponentDto project = indexProject("key-1", "SonarQube");
-
-    assertSearchResults("sonrqube", project);
-  }
-
-  @Test
-  public void should_find_item_despite_two_missing_characters_and_lowercase() {
-    ComponentDto project = indexProject("key-1", "SonarQube");
-
-    assertSearchResults("sonqube", project);
-  }
-
-  @Test
-  public void missing_characters_should_reduce_score() {
-    assertResultOrder("SonarQube.java",
-      "sonarqube.java",
-      "sonaqube.java",
-      "sonqube.java");
-  }
-
-  @Test
-  public void fuzziness_for_filename_without_suffix() {
-    assertFileMatches("StringUtils",
-      "StringUtils.java",
-      "StringUils.java",
-      "StringUls.java");
-  }
-}
index f971c3df02093fa4d57ff9545a147666ad716ca9..6f6406da0e76b81b924b8c6fe1e3f1f85f5f0120 100644 (file)
@@ -29,13 +29,6 @@ public class ComponentIndexMultipleWordsTest extends ComponentIndexTest {
       "Struts.java");
   }
 
-  @Test
-  public void should_find_fuzzy_match() {
-    features.set(ComponentIndexSearchFeature.FUZZY);
-    assertResultOrder("StrutX ProjecX",
-      "Struts Project");
-  }
-
   @Test
   public void should_find_partial_match() {
     features.set(ComponentIndexSearchFeature.PARTIAL);
@@ -91,13 +84,6 @@ public class ComponentIndexMultipleWordsTest extends ComponentIndexTest {
       "Struts");
   }
 
-  @Test
-  public void should_require_all_words_to_match_for_fuzziness() {
-    features.set(ComponentIndexSearchFeature.FUZZY);
-    assertNoFileMatches("struts java",
-      "Struts");
-  }
-
   @Test
   public void should_require_all_words_to_match_for_partial() {
     features.set(ComponentIndexSearchFeature.PARTIAL);
index d4adf4e566d1664193e4be007e83a9f5c3c796d7..49ed535da958caf9c57887f32984ac99ca6e244b 100644 (file)
@@ -24,14 +24,6 @@ import org.sonar.db.component.ComponentDto;
 
 public class ComponentIndexScoreTest extends ComponentIndexTest {
 
-  @Test
-  public void should_order_results_by_score() {
-    assertResultOrder("struts",
-      "Struts",
-      "Apache Struts",
-      "Apache Struts Two");
-  }
-
   @Test
   public void should_prefer_components_without_prefix() {
     assertResultOrder("File.java",
@@ -53,11 +45,4 @@ public class ComponentIndexScoreTest extends ComponentIndexTest {
 
     assertExactResults("sonarqube", project2, project1);
   }
-
-  @Test
-  public void should_prefer_prefix_to_partial() {
-    assertResultOrder("corem",
-      "CoreMetrics.java",
-      "ScoreMatrix.java");
-  }
 }