Added getMinimalSearchRadius to searchuicore

This commit is contained in:
Alexey Kulish 2018-03-22 17:13:41 +03:00
parent d2ab7c0477
commit b49156d938
3 changed files with 39 additions and 1 deletions

View file

@ -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<SearchCoreAPI> lst = new ArrayList<>(apis);

View file

@ -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);
}

View file

@ -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<PoiCategory, LinkedHashSet<String>> acceptedTypes = new LinkedHashMap<PoiCategory,
LinkedHashSet<String>>();
private Map<String, PoiType> poiAdditionals = new HashMap<String, PoiType>();
@ -750,7 +771,7 @@ public class SearchCoreFactory {
throw new UnsupportedOperationException();
}
QuadRect bbox = phrase.getRadiusBBoxToSearch(10000);
QuadRect bbox = phrase.getRadiusBBoxToSearch(BBOX_RADIUS);
List<BinaryMapIndexReader> oo = phrase.getOfflineIndexes();
Set<String> searchedPois = new TreeSet<>();
for (BinaryMapIndexReader o : oo) {