From f1c7d7e276fd3f2ea7cb80699387c3e8cfb7d809 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 4 Jul 2020 00:31:40 +0200 Subject: [PATCH] Try to fix #9329 --- .../net/osmand/search/core/ObjectType.java | 4 ++-- .../net/osmand/search/core/SearchResult.java | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/search/core/ObjectType.java b/OsmAnd-java/src/main/java/net/osmand/search/core/ObjectType.java index 9844f52646..c14d5cff07 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/core/ObjectType.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/core/ObjectType.java @@ -55,11 +55,11 @@ public enum ObjectType { return 4; case STREET: return 3; - case POI: - return 2; case CITY: case VILLAGE: case POSTCODE: + return 2; + case POI: return 1; default: return 1; 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 c72dd84079..578e629989 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 @@ -49,13 +49,14 @@ public class SearchResult { // maximum corresponds to the top entry public double getUnknownPhraseMatchWeight() { - // if result is a complete match in the search we prioritize it highers + // if result is a complete match in the search we prioritize it higher return getSumPhraseMatchWeight() / Math.pow(MAX_TYPE_WEIGHT, getDepth() - 1); } public double getSumPhraseMatchWeight() { - // if result is a complete match in the search we prioritize it highers - double res = ObjectType.getTypeWeight(objectType); + // if result is a complete match in the search we prioritize it higher + boolean match = requiredSearchPhrase.countWords(localeName) <= getSelfWordCount(); + double res = match ? ObjectType.getTypeWeight(objectType) : 0; if (parentSearchResult != null) { res = res + parentSearchResult.getSumPhraseMatchWeight() / MAX_TYPE_WEIGHT; } @@ -70,6 +71,14 @@ public class SearchResult { } public int getFoundWordCount() { + int inc = getSelfWordCount(); + if (parentSearchResult != null) { + inc += parentSearchResult.getFoundWordCount(); + } + return inc; + } + + private int getSelfWordCount() { int inc = 0; if (firstUnknownWordMatches) { inc = 1; @@ -77,9 +86,6 @@ public class SearchResult { if (otherWordsMatch != null) { inc += otherWordsMatch.size(); } - if (parentSearchResult != null) { - inc += parentSearchResult.getFoundWordCount(); - } return inc; }