From: Daniel Schwarz Date: Mon, 30 Jan 2017 11:22:08 +0000 (+0100) Subject: SONAR-8568 drop fuzzy search, to increase search result relevancy X-Git-Tag: 6.3-RC1~328 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1afb541053de070d856dfdea90115dca5b9f17e0;p=sonarqube.git SONAR-8568 drop fuzzy search, to increase search result relevancy --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/index/ComponentIndexDefinition.java b/server/sonar-server/src/main/java/org/sonar/server/component/index/ComponentIndexDefinition.java index 9c0ff4d5e70..651c8a404f8 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/index/ComponentIndexDefinition.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/index/ComponentIndexDefinition.java @@ -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 diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/index/ComponentIndexSearchFeature.java b/server/sonar-server/src/main/java/org/sonar/server/component/index/ComponentIndexSearchFeature.java index 1f1da838260..f2e046f23ab 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/index/ComponentIndexSearchFeature.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/index/ComponentIndexSearchFeature.java @@ -20,20 +20,16 @@ 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) 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) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/DefaultIndexSettingsElement.java b/server/sonar-server/src/main/java/org/sonar/server/es/DefaultIndexSettingsElement.java index cac2461a5fb..ee2838d822c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/es/DefaultIndexSettingsElement.java +++ b/server/sonar-server/src/main/java/org/sonar/server/es/DefaultIndexSettingsElement.java @@ -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 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 index 96ac23331dd..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexFeatureFuzzyTest.java +++ /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"); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexMultipleWordsTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexMultipleWordsTest.java index f971c3df020..6f6406da0e7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexMultipleWordsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexMultipleWordsTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexScoreTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexScoreTest.java index d4adf4e566d..49ed535da95 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexScoreTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexScoreTest.java @@ -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"); - } }