From 08baaf7004e4c743734ab7ddb0ac915d80d8fd57 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 19 Apr 2021 20:10:19 +0200 Subject: [PATCH] Fix #11376 --- .../src/main/java/net/osmand/search/core/SearchResult.java | 4 +++- .../src/test/java/net/osmand/search/SearchUICoreTest.java | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java index 79d11a3fe0..60269fe5d4 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java @@ -55,7 +55,9 @@ public class SearchResult { public double getSumPhraseMatchWeight() { // if result is a complete match in the search we prioritize it higher - boolean match = requiredSearchPhrase.countWords(localeName) <= getSelfWordCount(); + int localWordsMatched = alternateName != null ? + requiredSearchPhrase.countWords(alternateName) : requiredSearchPhrase.countWords(localeName) ; + boolean match = localWordsMatched <= getSelfWordCount(); double res = ObjectType.getTypeWeight(match ? objectType : null); if (parentSearchResult != null) { res = res + parentSearchResult.getSumPhraseMatchWeight() / MAX_TYPE_WEIGHT; diff --git a/OsmAnd-java/src/test/java/net/osmand/search/SearchUICoreTest.java b/OsmAnd-java/src/test/java/net/osmand/search/SearchUICoreTest.java index f3ed25ca0b..07e7339401 100644 --- a/OsmAnd-java/src/test/java/net/osmand/search/SearchUICoreTest.java +++ b/OsmAnd-java/src/test/java/net/osmand/search/SearchUICoreTest.java @@ -80,9 +80,9 @@ public class SearchUICoreTest { if (files != null) { for (File file : files) { String fileName = file.getName(); - if(fileName.endsWith(".json")) { + if (fileName.endsWith(".json")) { String name = fileName.substring(0, fileName.length() - ".json".length()); - arrayList.add(new Object[] {name, file}); + arrayList.add(new Object[] { name, file }); } } } @@ -191,10 +191,10 @@ public class SearchUICoreTest { if (!Algorithms.stringsEqual(expected, present)) { System.out.println(String.format("Phrase: %s", phrase)); System.out.println(String.format("Mismatch for '%s' != '%s'. Result: ", expected, present)); + } for (SearchResult r : searchResults) { System.out.println(String.format("\t\"%s\",", formatResult(false, r, phrase))); } - } Assert.assertEquals(expected, present); } }