From 6234b771352cac5e48ebb3748c10db06f7309a71 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Mon, 3 Feb 2020 13:51:42 +0200 Subject: [PATCH] Small fixes p.3 --- .../osmand/search/core/SearchCoreFactory.java | 20 +++++++++++++------ .../osmand/plus/search/QuickSearchHelper.java | 7 ++++++- 2 files changed, 20 insertions(+), 7 deletions(-) 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 963c36656e..c0a27ee3a4 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 @@ -633,6 +633,8 @@ public class SearchCoreFactory { public static class SearchAmenityTypesAPI extends SearchBaseAPI { + public final static String STD_POI_FILTER_PREFIX = "std_"; + private Map translatedNames = new LinkedHashMap<>(); private List topVisibleFilters; private List categories; @@ -671,6 +673,7 @@ public class SearchCoreFactory { List searchWordTypes = new ArrayList(); NameStringMatcher nm; String unknownSearchPhrase = phrase.getUnknownSearchPhrase(); + boolean showTopFiltersOnly = !phrase.isUnknownSearchWordPresent(); if (phrase.getUnknownSearchWord().length() < unknownSearchPhrase.length()) { nm = new NameStringMatcher(unknownSearchPhrase, StringMatcherMode.CHECK_ONLY_STARTS_WITH_TRIM); } else { @@ -725,7 +728,6 @@ public class SearchCoreFactory { phrase.setUnknownSearchWordPoiTypes(searchWordTypes); if (resultMatcher != null) { - boolean defaultMode = !phrase.isUnknownSearchWordPresent(); String word = phrase.getUnknownSearchWord(); NameStringMatcher startMatch = new NameStringMatcher(word, StringMatcherMode.CHECK_ONLY_STARTS_WITH); for (AbstractPoiType pt : results) { @@ -735,10 +737,11 @@ public class SearchCoreFactory { res.priorityDistance = 0; res.objectType = ObjectType.POI_TYPE; res.firstUnknownWordMatches = startMatch.matches(res.localeName); - if (defaultMode) { - String stdFilterId = "std_" + pt.getKeyName(); + if (showTopFiltersOnly) { + String stdFilterId = getStandardFilterId(pt); if (filterOrders.containsKey(stdFilterId)) { - res.priority = filterOrders.get(stdFilterId); + int p = filterOrders.get(stdFilterId); + res.priority = SEARCH_AMENITY_TYPE_PRIORITY + p; resultMatcher.publish(res); } } else { @@ -753,9 +756,10 @@ public class SearchCoreFactory { res.localeName = csf.getName(); res.object = csf; res.objectType = ObjectType.POI_TYPE; - if (defaultMode) { + if (showTopFiltersOnly) { if (filterOrders.containsKey(csf.getFilterId())) { - res.priority = filterOrders.get(csf.getFilterId()); + int p = filterOrders.get(csf.getFilterId()); + res.priority = SEARCH_AMENITY_TYPE_PRIORITY + p; resultMatcher.publish(res); } } else { @@ -769,6 +773,10 @@ public class SearchCoreFactory { return true; } + public String getStandardFilterId(AbstractPoiType poi) { + return STD_POI_FILTER_PREFIX + poi.getKeyName(); + } + @Override public boolean isSearchMoreAvailable(SearchPhrase phrase) { return false; diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java index 659eae9344..2b3d14ac47 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java @@ -102,6 +102,7 @@ public class QuickSearchHelper implements ResourceListener { core.registerAPI(new SearchOnlineApi(app)); refreshCustomPoiFilters(); + refreshFilterOrders(); } public void refreshCustomPoiFilters() { @@ -115,7 +116,11 @@ public class QuickSearchHelper implements ResourceListener { core.addCustomSearchPoiFilter(localWikiPoiFilter, 1); } core.addCustomSearchPoiFilter(poiFilters.getShowAllPOIFilter(), 1); - core.setFilterOrders(poiFilters.getPoiFilterOrders(true)); + } + + public void refreshFilterOrders() { + PoiFiltersHelper filtersHelper = app.getPoiFilters(); + core.setFilterOrders(filtersHelper.getPoiFilterOrders(true)); } public void setRepositoriesForSearchUICore(final OsmandApplication app) {