diff --git a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java index 7eec13cd94..1739d83fb6 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java @@ -872,16 +872,18 @@ public class SearchUICore { return topVisible1 ? -1 : 1; } break; - case UNKNOWN_PHRASE_MATCH_WEIGHT: - if (o1.getUnknownPhraseMatchWeight() != o2.getUnknownPhraseMatchWeight()) { - return -Double.compare(o1.getUnknownPhraseMatchWeight(), o2.getUnknownPhraseMatchWeight()); - } - break; case FOUND_WORD_COUNT: if (o1.getFoundWordCount() != o2.getFoundWordCount()) { return -Algorithms.compare(o1.getFoundWordCount(), o2.getFoundWordCount()); } break; + case UNKNOWN_PHRASE_MATCH_WEIGHT: + // here we check how much each sub search result matches the phrase + // also we sort it by type house -> street/poi -> city/postcode/village/other + if (o1.getUnknownPhraseMatchWeight() != o2.getUnknownPhraseMatchWeight()) { + return -Double.compare(o1.getUnknownPhraseMatchWeight(), o2.getUnknownPhraseMatchWeight()); + } + break; case SEARCH_DISTANCE_IF_NOT_BY_NAME: if (!c.sortByName) { double s1 = o1.getSearchDistance(c.loc); 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 4de83b932d..3236fa6032 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 @@ -50,20 +50,16 @@ public enum ObjectType { return 1; } switch (t) { - case CITY: - return 1; - case VILLAGE: - return 1; - case POSTCODE: - return 1; - case STREET: - return 2; case HOUSE: - return 3; case STREET_INTERSECTION: return 3; + case STREET: case POI: return 2; + case CITY: + case VILLAGE: + case POSTCODE: + 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 8c235713b4..9319e225ef 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 @@ -33,13 +33,17 @@ public class SearchResult { this.requiredSearchPhrase = sp; } - public int getUnknownPhraseMatchWeight() { + public double getUnknownPhraseMatchWeight() { + // if result is a complete match in the search we prioritize it highers + double res = 0; if (unknownPhraseMatches) { - return ObjectType.getTypeWeight(objectType); - } else if (parentSearchResult != null) { - return parentSearchResult.getUnknownPhraseMatchWeight(); + res = ObjectType.getTypeWeight(objectType); } - return 0; + if (parentSearchResult != null) { + // 5 is a maximum type + res += parentSearchResult.getUnknownPhraseMatchWeight() / 5; + } + return res; } public int getFoundWordCount() { diff --git a/OsmAnd-java/src/test/resources/search/free_street_portland.json b/OsmAnd-java/src/test/resources/search/free_street_portland.json index a4926a4877..d39fbcab43 100644 --- a/OsmAnd-java/src/test/resources/search/free_street_portland.json +++ b/OsmAnd-java/src/test/resources/search/free_street_portland.json @@ -12,20 +12,16 @@ "phrase": "48 Free Street Portland", "results": [ "48.0, ", - "48, Free Street (Downtown), Portland"], + "48, Free Street (Downtown), Portland" + ], "extra-results": [ - "48, Portland Street, North Berwick", + "48, Portland Street, North Berwick", "Free Street (Downtown), Portland", "Free Street (Ferry Village), South Portland", "Portland Street", - "48, Portland Avenue, Old Orchard Beach", "Portland Street (Downtown), Portland", "Portland Street Pier, South Portland", - "Portland Street, Yarmouth", - "Portland Street, North Berwick", - "Portland Street, Berwick", - "Portland Street, South Berwick", - "Portland Street, Fryeburg" + "Portland Street, Yarmouth" ], "amenities": [ { diff --git a/OsmAnd-java/src/test/resources/search/navacerrada.json b/OsmAnd-java/src/test/resources/search/navacerrada.json index 1358fb0e32..b4c94a734e 100644 --- a/OsmAnd-java/src/test/resources/search/navacerrada.json +++ b/OsmAnd-java/src/test/resources/search/navacerrada.json @@ -14,8 +14,9 @@ "5, Calle de las Eras (Uranización Los Corales), Navacerrada" ], "extra-results": [ - "Calle de las Eras (Uranización Los Corales), Pasaje de las Eras (Uranización Los Corales), Navacerrada", + "Calle de las Eras (Uranización Los Corales), Navacerrada", "Calle del Sotillo (Uranización Los Corales), Pasaje de las Eras (Uranización Los Corales), Navacerrada", + "Calle del Puerto de Navacerrada, Las Nieves", "5, Calle Navacerrada (Urb. Las Suertes), Las Suertes", "50, Calle de Francisco Navacerrada, Salamanca", "52, Calle de Francisco Navacerrada, Salamanca", @@ -26,7 +27,6 @@ "57, Calle de Francisco Navacerrada, Salamanca", "58, Calle de Francisco Navacerrada, Salamanca", "59, Calle de Francisco Navacerrada, Salamanca", - "Calle del Puerto de Navacerrada, Las Nieves", "Pasaje de las Eras (Uranización Los Corales), Navacerrada", "Calle Barrio de las Peñas, Navacerrada", "Calle de las Cruces (Residencial Sanabria), Navacerrada", @@ -47,6 +47,33 @@ "Calle de los Enebros (Uranización Los Corales), Navacerrada", "Calle de la Bola del Mundo (Residencial Sanabria), Navacerrada", "Calle de la Maliciosa (Residencial Sanabria), Navacerrada", + "Calle de la Perdiz, Navacerrada", + "Calle de la Magdalena, Navacerrada", + "Calle las Jaras, Navacerrada", + "Calle de la Audiencia, Navacerrada", + "Calle de Prado Jerez, Navacerrada", + "Calle de Carmen Conde (Residencial Sanabria), Navacerrada", + "Calle de la Iglesia, Navacerrada", + "Calle de la Tejera, Navacerrada", + "Calle de la Encinilla, Navacerrada", + "Calle de la Canaleja (Residencial Sanabria), Navacerrada", + "Calle de Rafael Alvarado, Navacerrada", + "Calle de Andrés Segovia, Navacerrada", + "Calle de los Pradillos (Residencial Sanabria), Navacerrada", + "Calle de Abel, Navacerrada", + "Calle Praderas de San Sebastián, Navacerrada", + "Calle de San Sebastián (Residencial Sanabria), Navacerrada", + "Calle de Álvaro Iglesia, Navacerrada", + "Calle de los Arcos, Navacerrada", + "Calle de Peñalara, Puerto de Navacerrada", + "Calle de la Bola del Mundo, Puerto de Navacerrada", + "Calle de la Estación, Puerto de Navacerrada", + "Calle Ginos, Puerto de Navacerrada", + "Calle Vitoria, Puerto de Navacerrada", + "Calle Dos Castillas, Puerto de Navacerrada", + "Travesía de las Huertas, Navacerrada", + "Vereda de las Encinillas, Navacerrada", + "Centro Municipal de Mayores «Navacerrada»", ], "amenities": [ {