diff --git a/OsmAnd-java/src/net/osmand/search/SearchUICore.java b/OsmAnd-java/src/net/osmand/search/SearchUICore.java index bf2966af1f..a839cc8ab6 100644 --- a/OsmAnd-java/src/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/net/osmand/search/SearchUICore.java @@ -490,6 +490,17 @@ public class SearchUICore { return false; } + public int getMinimalSearchRadius(SearchPhrase phrase) { + int radius = Integer.MAX_VALUE; + for (SearchCoreAPI api : apis) { + int apiMinimalRadius = api.getMinimalSearchRadius(phrase); + if (apiMinimalRadius > 0 && apiMinimalRadius < radius) { + radius = apiMinimalRadius; + } + } + return radius; + } + private void searchInBackground(final SearchPhrase phrase, SearchResultMatcher matcher) { preparePhrase(phrase); ArrayList lst = new ArrayList<>(apis); diff --git a/OsmAnd-java/src/net/osmand/search/core/SearchCoreAPI.java b/OsmAnd-java/src/net/osmand/search/core/SearchCoreAPI.java index 8eafc712b2..024253140c 100644 --- a/OsmAnd-java/src/net/osmand/search/core/SearchCoreAPI.java +++ b/OsmAnd-java/src/net/osmand/search/core/SearchCoreAPI.java @@ -21,4 +21,10 @@ public interface SearchCoreAPI { public boolean isSearchMoreAvailable(SearchPhrase phrase); boolean isSearchAvailable(SearchPhrase p); + + /** + * @param phrase + * @return minimal search radius in meters + */ + int getMinimalSearchRadius(SearchPhrase phrase); } diff --git a/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java b/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java index 45fa55f09c..62721b265b 100644 --- a/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java +++ b/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java @@ -129,6 +129,11 @@ public class SearchCoreFactory { return phrase.getRadiusLevel() < MAX_DEFAULT_SEARCH_RADIUS; } + @Override + public int getMinimalSearchRadius(SearchPhrase phrase) { + return 0; + } + protected void subSearchApiOrPublish(SearchPhrase phrase, SearchResultMatcher resultMatcher, SearchResult res, SearchBaseAPI api) throws IOException { @@ -258,6 +263,11 @@ public class SearchCoreFactory { return getSearchPriority(phrase) != -1 && super.isSearchMoreAvailable(phrase); } + @Override + public int getMinimalSearchRadius(SearchPhrase phrase) { + return phrase.getRadiusSearch(DEFAULT_ADDRESS_BBOX_RADIUS); + } + @Override public boolean search(final SearchPhrase phrase, final SearchResultMatcher resultMatcher) throws IOException { if (!phrase.isUnknownSearchWordPresent() && !phrase.isEmptyQueryAllowed()) { @@ -575,6 +585,11 @@ public class SearchCoreFactory { public boolean isSearchMoreAvailable(SearchPhrase phrase) { return super.isSearchMoreAvailable(phrase) && getSearchPriority(phrase) != -1; } + + @Override + public int getMinimalSearchRadius(SearchPhrase phrase) { + return phrase.getRadiusSearch(BBOX_RADIUS); + } } @@ -700,6 +715,7 @@ public class SearchCoreFactory { public static class SearchAmenityByTypeAPI extends SearchBaseAPI { + private static final int BBOX_RADIUS = 10000; private MapPoiTypes types; @@ -713,6 +729,11 @@ public class SearchCoreFactory { return getSearchPriority(phrase) != -1 && super.isSearchMoreAvailable(phrase); } + @Override + public int getMinimalSearchRadius(SearchPhrase phrase) { + return phrase.getRadiusSearch(BBOX_RADIUS); + } + private Map> acceptedTypes = new LinkedHashMap>(); private Map poiAdditionals = new HashMap(); @@ -750,7 +771,7 @@ public class SearchCoreFactory { throw new UnsupportedOperationException(); } - QuadRect bbox = phrase.getRadiusBBoxToSearch(10000); + QuadRect bbox = phrase.getRadiusBBoxToSearch(BBOX_RADIUS); List oo = phrase.getOfflineIndexes(); Set searchedPois = new TreeSet<>(); for (BinaryMapIndexReader o : oo) {