diff --git a/OsmAnd-java/src/net/osmand/search/SearchUICore.java b/OsmAnd-java/src/net/osmand/search/SearchUICore.java index eaf6f1ae3d..45d700690f 100644 --- a/OsmAnd-java/src/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/net/osmand/search/SearchUICore.java @@ -354,7 +354,14 @@ public class SearchUICore { } - + public boolean isSearchMoreAvailable(SearchPhrase phrase) { + for(SearchCoreAPI api : apis) { + if(api.getSearchPriority(phrase) >= 0 && api.isSearchMoreAvailable(phrase)) { + return true; + } + } + return false; + } private void searchInBackground(final SearchPhrase phrase, SearchResultMatcher matcher) { preparePhrase(phrase); diff --git a/OsmAnd-java/src/net/osmand/search/core/SearchCoreAPI.java b/OsmAnd-java/src/net/osmand/search/core/SearchCoreAPI.java index 9cd9deefa1..df783735da 100644 --- a/OsmAnd-java/src/net/osmand/search/core/SearchCoreAPI.java +++ b/OsmAnd-java/src/net/osmand/search/core/SearchCoreAPI.java @@ -14,4 +14,10 @@ public interface SearchCoreAPI { public boolean search(SearchPhrase phrase, SearchResultMatcher resultMatcher) throws IOException; + /** + * @param phrase + * @return true if search more available (should be consistent with -1 search priority) + */ + public boolean isSearchMoreAvailable(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 b02c997453..ab0eee3efd 100644 --- a/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java +++ b/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java @@ -50,6 +50,7 @@ import com.jwetherell.openmap.common.UTMPoint; public class SearchCoreFactory { + public static final int MAX_DEFAULT_SEARCH_RADIUS = 7; //////////////// CONSTANTS ////////// public static final int SEARCH_REGION_API_PRIORITY = 3; @@ -90,6 +91,11 @@ public class SearchCoreFactory { return 1; } + @Override + public boolean isSearchMoreAvailable(SearchPhrase phrase) { + return phrase.getRadiusLevel() < MAX_DEFAULT_SEARCH_RADIUS; + } + protected void subSearchApiOrPublish(SearchPhrase phrase, SearchResultMatcher resultMatcher, SearchResult res, SearchBaseAPI api) throws IOException { @@ -113,8 +119,6 @@ public class SearchCoreFactory { public static class SearchRegionByNameAPI extends SearchBaseAPI { - - @Override public boolean search(SearchPhrase phrase, SearchResultMatcher resultMatcher) { for (BinaryMapIndexReader bmir : phrase.getOfflineIndexes()) { @@ -137,6 +141,11 @@ public class SearchCoreFactory { return true; } + @Override + public boolean isSearchMoreAvailable(SearchPhrase phrase) { + return false; + } + @Override public int getSearchPriority(SearchPhrase p) { if(!p.isNoSelectedType()) { @@ -175,6 +184,12 @@ public class SearchCoreFactory { } return SEARCH_ADDRESS_BY_NAME_API_PRIORITY_RADIUS2; } + + @Override + public boolean isSearchMoreAvailable(SearchPhrase phrase) { + // case when street is not found for given city is covered by SearchStreetByCityAPI + return getSearchPriority(phrase) == -1 && super.isSearchMoreAvailable(phrase); + } @Override public boolean search(final SearchPhrase phrase, final SearchResultMatcher resultMatcher) throws IOException { @@ -450,17 +465,18 @@ public class SearchCoreFactory { return -1; } if(p.hasObjectType(ObjectType.POI_TYPE)) { - if(p.getRadiusLevel() > 1) { - return SEARCH_AMENITY_BY_NAME_API_PRIORITY_IF_POI_TYPE; - } else { - return -1; - } + return -1; } if(p.getUnknownSearchWordLength() > 3 || p.getRadiusLevel() > 1) { return SEARCH_AMENITY_BY_NAME_API_PRIORITY_IF_3_CHAR; } return -1; } + + @Override + public boolean isSearchMoreAvailable(SearchPhrase phrase) { + return super.isSearchMoreAvailable(phrase) && getSearchPriority(phrase) != -1; + } } @@ -531,6 +547,11 @@ public class SearchCoreFactory { return true; } + @Override + public boolean isSearchMoreAvailable(SearchPhrase phrase) { + return false; + } + @Override public int getSearchPriority(SearchPhrase p) { if (p.hasObjectType(ObjectType.POI) || p.hasObjectType(ObjectType.POI_TYPE)) { @@ -551,6 +572,10 @@ public class SearchCoreFactory { this.types = types; } + @Override + public boolean isSearchMoreAvailable(SearchPhrase phrase) { + return getSearchPriority(phrase) != -1 && super.isSearchMoreAvailable(phrase); + } private Map> acceptedTypes = new LinkedHashMap>(); @@ -646,6 +671,7 @@ public class SearchCoreFactory { return resultMatcher.isCancelled(); } }; + } private SearchPoiTypeFilter getPoiTypeFilter(AbstractPoiType pt) { @@ -700,6 +726,12 @@ public class SearchCoreFactory { this.streetsAPI = streetsAPI; } + @Override + public boolean isSearchMoreAvailable(SearchPhrase phrase) { + // case when street is not found for given city is covered here + return phrase.getRadiusLevel() == 1 && getSearchPriority(phrase) != -1; + } + private static int LIMIT = 10000; @Override public boolean search(SearchPhrase phrase, SearchResultMatcher resultMatcher) throws IOException { @@ -762,6 +794,11 @@ public class SearchCoreFactory { public static class SearchBuildingAndIntersectionsByStreetAPI extends SearchBaseAPI { Street cacheBuilding; + @Override + public boolean isSearchMoreAvailable(SearchPhrase phrase) { + return false; + } + @Override public boolean search(SearchPhrase phrase, final SearchResultMatcher resultMatcher) throws IOException { Street s = null; @@ -889,6 +926,10 @@ public class SearchCoreFactory { public static class SearchLocationAndUrlAPI extends SearchBaseAPI { + @Override + public boolean isSearchMoreAvailable(SearchPhrase phrase) { + return false; + } // newFormat = PointDescription.FORMAT_DEGREES; // newFormat = PointDescription.FORMAT_MINUTES;