From ca6915933284f5c155176d5aba27287322f7d3a3 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 4 Jun 2020 16:46:05 +0200 Subject: [PATCH] Add fuel test --- .../java/net/osmand/search/SearchUICore.java | 13 ++++++++++ .../osmand/search/core/SearchCoreFactory.java | 4 +++ .../src/test/resources/search/poi_fuel.json | 25 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 OsmAnd-java/src/test/resources/search/poi_fuel.json 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 e23e8a87ac..a10eaf8b9c 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java @@ -9,6 +9,7 @@ import net.osmand.data.City; import net.osmand.data.LatLon; import net.osmand.data.MapObject; import net.osmand.data.Street; +import net.osmand.osm.AbstractPoiType; import net.osmand.osm.MapPoiTypes; import net.osmand.search.core.CustomSearchPoiFilter; import net.osmand.search.core.ObjectType; @@ -858,6 +859,7 @@ public class SearchUICore { TOP_VISIBLE, FOUND_WORD_COUNT, // more is better (top) UNKNOWN_PHRASE_MATCH_WEIGHT, // more is better (top) + COMPARE_AMENITY_TYPE_ADDITIONAL, SEARCH_DISTANCE_IF_NOT_BY_NAME, COMPARE_FIRST_NUMBER_IN_NAME, COMPARE_DISTANCE_TO_PARENT_SEARCH_RESULT, // makes sense only for inner subqueries @@ -908,6 +910,17 @@ public class SearchUICore { } break; } + case COMPARE_AMENITY_TYPE_ADDITIONAL: { + if(o1.object instanceof AbstractPoiType && o2.object instanceof AbstractPoiType ) { + boolean additional1 = ((AbstractPoiType) o1.object).isAdditional(); + boolean additional2 = ((AbstractPoiType) o2.object).isAdditional(); + if (additional1 != additional2) { + // -1 - means 1st is less than 2nd + return additional1 ? 1 : -1; + } + } + break; + } case COMPARE_DISTANCE_TO_PARENT_SEARCH_RESULT: double ps1 = o1.parentSearchResult == null ? 0 : o1.parentSearchResult.getSearchDistance(c.loc); double ps2 = o2.parentSearchResult == null ? 0 : o2.parentSearchResult.getSearchDistance(c.loc); diff --git a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java index 4d8f414650..425e66cacf 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java @@ -702,6 +702,9 @@ public class SearchCoreFactory { if (nm.matches(pf.getEnTranslation())) { lst = addToList(pf.getEnTranslation(), lst); } + if (nm.matches(pf.getKeyName())) { + lst = addToList(pf.getKeyName().replace('_', ' '), lst); + } if (nm.matches(pf.getSynonyms())) { String[] synonyms = pf.getSynonyms().split(";"); @@ -784,6 +787,7 @@ public class SearchCoreFactory { String stdFilterId , SearchResult res) { res.priorityDistance = 0; res.objectType = ObjectType.POI_TYPE; + res.firstUnknownWordMatches = true; if (showTopFiltersOnly) { if (activePoiFilters.containsKey(stdFilterId)) { res.priority = getPoiTypePriority(stdFilterId); diff --git a/OsmAnd-java/src/test/resources/search/poi_fuel.json b/OsmAnd-java/src/test/resources/search/poi_fuel.json new file mode 100644 index 0000000000..8115349b2f --- /dev/null +++ b/OsmAnd-java/src/test/resources/search/poi_fuel.json @@ -0,0 +1,25 @@ +{ + "settings": { + "lat": "51.04933", + "lon": "13.73815", + "radiusLevel": 1, + "totalLimit": -1, + "lang": "", + "transliterateIfMissing": false, + "emptyQueryAllowed": false, + "sortByName": false + }, + "phrase": ["Fuel", "Fuel "], + "results": [[ + "Aircraft fuel station (Filling station) [[1, POI_TYPE, 1.000, 0.00 km]]", + "Gas station (Filling station) [[1, POI_TYPE, 1.000, 0.00 km]]", + "Gas station for boats (Filling station) [[1, POI_TYPE, 1.000, 0.00 km]]" + ], + [ + "Aircraft fuel station (Filling station) [[1, POI_TYPE, 1.000, 0.00 km]]", + "Gas station (Filling station) [[1, POI_TYPE, 1.000, 0.00 km]]", + "Gas station for boats (Filling station) [[1, POI_TYPE, 1.000, 0.00 km]]" + ]], + "amenities": [], + "cities": [] +} \ No newline at end of file