diff --git a/OsmAnd-java/src/net/osmand/search/SearchUICore.java b/OsmAnd-java/src/net/osmand/search/SearchUICore.java index 9e3783fbfe..18600f6d34 100644 --- a/OsmAnd-java/src/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/net/osmand/search/SearchUICore.java @@ -87,6 +87,10 @@ public class SearchUICore { } } + public void setPoiTypes(MapPoiTypes poiTypes) { + this.poiTypes = poiTypes; + } + public int getTotalLimit() { return totalLimit; } diff --git a/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java b/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java index ee06ceaa41..afc8c550dc 100644 --- a/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java +++ b/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java @@ -463,16 +463,20 @@ public class SearchCoreFactory { public static class SearchAmenityTypesAPI extends SearchBaseAPI { - private Map translatedNames; + private Map translatedNames = new LinkedHashMap<>(); private List topVisibleFilters; + private MapPoiTypes types; public SearchAmenityTypesAPI(MapPoiTypes types) { - translatedNames = types.getAllTranslatedNames(false); - topVisibleFilters = types.getTopVisibleFilters(); + this.types = types; } @Override public boolean search(SearchPhrase phrase, SearchResultMatcher resultMatcher) throws IOException { + if(translatedNames.isEmpty()) { + translatedNames = types.getAllTranslatedNames(false); + topVisibleFilters = types.getTopVisibleFilters(); + } // results.clear(); TreeSet results = new TreeSet<>(new Comparator() { @@ -491,7 +495,7 @@ public class SearchCoreFactory { Iterator> it = translatedNames.entrySet().iterator(); while (it.hasNext()) { Entry e = it.next(); - if (nm.matches(e.getKey())) { + if (nm.matches(e.getKey()) || nm.matches(e.getValue().getTranslation())) { results.add(e.getValue()); } } @@ -522,7 +526,6 @@ public class SearchCoreFactory { public static class SearchAmenityByTypeAPI extends SearchBaseAPI { - private MapPoiTypes types; public SearchAmenityByTypeAPI(MapPoiTypes types) { diff --git a/OsmAnd-java/test/java/net/osmand/router/TestEntry.java b/OsmAnd-java/test/java/net/osmand/router/TestEntry.java index a1139cc8b5..2049e371a4 100644 --- a/OsmAnd-java/test/java/net/osmand/router/TestEntry.java +++ b/OsmAnd-java/test/java/net/osmand/router/TestEntry.java @@ -15,7 +15,28 @@ public class TestEntry { private boolean ignore; private Map expectedResults; private Map params; + private int planRoadDirection; + private boolean shortWay; + + public void setShortWay(boolean shortWay) { + this.shortWay = shortWay; + } + + public boolean isShortWay() { + return shortWay; + } + + + public int getPlanRoadDirection() { + return planRoadDirection; + } + + + public void setPlanRoadDirection(int planRoadDirection) { + this.planRoadDirection = planRoadDirection; + } + public LatLon getStartPoint() { return startPoint; } diff --git a/OsmAnd-java/test/resources/test_routing.json b/OsmAnd-java/test/resources/test_routing.json index 55d00a1838..a052932000 100644 --- a/OsmAnd-java/test/resources/test_routing.json +++ b/OsmAnd-java/test/resources/test_routing.json @@ -4,7 +4,7 @@ "description": "При planRoadDirection='-1' маршрут неверный, при 0 - верный", "params": { "vehicle": "car", - "short_way": "true", + "shortWay": "true", "planRoadDirection": "0" }, "startPoint": { @@ -25,7 +25,7 @@ "description": "Подтверждается только неверный маршрут. От дистанции не зависит, но зависит от planRoadDirection. При -1 маршрут верный, при 0 - нет", "params": { "vehicle": "car", - "short_way": "true", + "shortWay": "true", "planRoadDirection": "0" }, "startPoint": { @@ -45,7 +45,7 @@ "description": "Не воспроизводится", "params": { "vehicle": "car", - "short_way": "true", + "shortWay": "true", "planRoadDirection": "-1" }, "startPoint": { @@ -65,7 +65,7 @@ "description": "Не воспроизводится", "params": { "vehicle": "car", - "short_way": "true", + "shortWay": "true", "planRoadDirection": "-1" }, "startPoint": { @@ -86,10 +86,10 @@ }, { "testName": "10.Longer route preferred? https://github.com/osmandapp/Osmand/issues/1941", - "description": "short_way строит не самый короткий путь. Транзит через MEX 261 короче.", + "description": "shortWay строит не самый короткий путь. Транзит через MEX 261 короче.", "params": { "vehicle": "car", - "short_way": "true", + "shortWay": "true", "planRoadDirection": "-1" }, "startPoint": { @@ -108,7 +108,7 @@ "testName": "12.Bizarre navigation at Sundance dr & Sentinel dr in Fremont, CA, USA https://github.com/osmandapp/Osmand/issues/1743", "params": { "vehicle": "car", - "short_way": "true", + "shortWay": "true", "planRoadDirection": "-1" }, "startPoint": { @@ -128,7 +128,7 @@ "testName": "12.1.Bizarre navigation at Sundance dr & Sentinel dr in Fremont, CA, USA (transit2 point) https://github.com/osmandapp/Osmand/issues/1743", "params": { "vehicle": "car", - "short_way": "true", + "shortWay": "true", "planRoadDirection": "-1" }, "startPoint": { @@ -151,7 +151,7 @@ "testName": "12.2.Bizarre navigation at Sundance dr & Sentinel dr in Fremont, CA, USA (reverse) https://github.com/osmandapp/Osmand/issues/1743", "params": { "vehicle": "car", - "short_way": "true", + "shortWay": "true", "planRoadDirection": "-1" }, "startPoint": { diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index 4c2a2903c4..a0a1b6479e 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -364,9 +364,7 @@ public class AppInitializer implements IProgress { app.geocodingLookupService = startupInit(new GeocodingLookupService(app), GeocodingLookupService.class); app.targetPointsHelper = startupInit(new TargetPointsHelper(app), TargetPointsHelper.class); app.mapMarkersHelper = startupInit(new MapMarkersHelper(app), MapMarkersHelper.class); - - app.searchUICore = startupInit(new SearchUICore(app.poiTypes, app.getSettings().MAP_PREFERRED_LOCALE.get(), new BinaryMapIndexReader[]{}), SearchUICore.class); - QuickSearchHelper.initSearchUICore(app); + app.searchUICore = startupInit(new QuickSearchHelper(app), QuickSearchHelper.class); } @@ -508,9 +506,9 @@ public class AppInitializer implements IProgress { // restore backuped favorites to normal file restoreBackupForFavoritesFiles(); notifyEvent(InitEvents.RESTORE_BACKUPS); + app.searchUICore.initSearchUICore(); checkLiveUpdatesAlerts(); - LocalIndexHelper helper = new LocalIndexHelper(app); - QuickSearchHelper.setRepositoriesForSearchUICore(app); + } catch (RuntimeException e) { e.printStackTrace(); warnings.add(e.getMessage()); diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index 3d534df78c..73e5f909bb 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -22,7 +22,6 @@ import android.view.accessibility.AccessibilityManager; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; - import net.osmand.CallbackWithObject; import net.osmand.PlatformUtil; import net.osmand.access.AccessibilityPlugin; @@ -46,9 +45,9 @@ import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.routing.RoutingHelper; +import net.osmand.plus.search.QuickSearchHelper; import net.osmand.plus.voice.CommandPlayer; import net.osmand.router.RoutingConfiguration; -import net.osmand.search.SearchUICore; import net.osmand.util.Algorithms; import java.io.BufferedWriter; @@ -98,7 +97,7 @@ public class OsmandApplication extends MultiDexApplication { BRouterServiceConnection bRouterServiceConnection; OsmandRegions regions; GeocodingLookupService geocodingLookupService; - SearchUICore searchUICore; + QuickSearchHelper searchUICore; RoutingConfiguration.Builder defaultRoutingConfig; private Locale preferredLocale = null; @@ -360,7 +359,7 @@ public class OsmandApplication extends MultiDexApplication { return geocodingLookupService; } - public SearchUICore getSearchUICore() { + public QuickSearchHelper getSearchUICore() { return searchUICore; } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java index d5eb364f25..bb113cff3e 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java @@ -26,13 +26,22 @@ public class QuickSearchHelper { public static final int SEARCH_WPT_OBJECT_PRIORITY = 10; public static final int SEARCH_HISTORY_API_PRIORITY = 3; public static final int SEARCH_HISTORY_OBJECT_PRIORITY = 10; + private OsmandApplication app; + private SearchUICore core; + + public QuickSearchHelper(OsmandApplication app) { + this.app = app; + core = new SearchUICore(app.getPoiTypes(), app.getSettings().MAP_PREFERRED_LOCALE.get(), new BinaryMapIndexReader[]{}); + } + + public SearchUICore getCore() { + return core; + } - public static void initSearchUICore(final OsmandApplication app) { - - SearchUICore searchUICore = app.getSearchUICore(); - + public void initSearchUICore() { + setRepositoriesForSearchUICore(app); // Register favorites search api - searchUICore.registerAPI(new SearchCoreFactory.SearchBaseAPI() { + core.registerAPI(new SearchCoreFactory.SearchBaseAPI() { @Override public boolean search(SearchPhrase phrase, SearchUICore.SearchResultMatcher resultMatcher) { @@ -66,17 +75,17 @@ public class QuickSearchHelper { }); // Register WptPt search api - searchUICore.registerAPI(new SearchWptAPI(app)); + core.registerAPI(new SearchWptAPI(app)); } - public static void setRepositoriesForSearchUICore(final OsmandApplication app) { + public void setRepositoriesForSearchUICore(final OsmandApplication app) { Collection regionAddressRepositories = app.getResourceManager().getAddressRepositories(); BinaryMapIndexReader[] binaryMapIndexReaderArray = new BinaryMapIndexReader[regionAddressRepositories.size()]; int i = 0; for (RegionAddressRepository rep : regionAddressRepositories) { binaryMapIndexReaderArray[i++] = rep.getFile(); } - app.getSearchUICore().getSearchSettings().setOfflineIndexes(Arrays.asList(binaryMapIndexReaderArray)); + core.getSearchSettings().setOfflineIndexes(Arrays.asList(binaryMapIndexReaderArray)); } public static class SearchWptAPI extends SearchCoreFactory.SearchBaseAPI { @@ -158,7 +167,7 @@ public class QuickSearchHelper { @Override public int getSearchPriority(SearchPhrase p) { - if(!p.isNoSelectedType()) { + if (!p.isNoSelectedType()) { return -1; } return SEARCH_HISTORY_API_PRIORITY;