Fix #5921
This commit is contained in:
parent
492555ef6c
commit
6740fec58b
2 changed files with 78 additions and 23 deletions
|
@ -309,9 +309,10 @@ public class SearchUICore {
|
|||
|
||||
public void init() {
|
||||
apis.add(new SearchCoreFactory.SearchLocationAndUrlAPI());
|
||||
apis.add(new SearchCoreFactory.SearchAmenityTypesAPI(poiTypes));
|
||||
apis.add(new SearchCoreFactory.SearchAmenityByTypeAPI(poiTypes));
|
||||
apis.add(new SearchCoreFactory.SearchAmenityByNameAPI());
|
||||
SearchAmenityTypesAPI searchAmenityTypesAPI = new SearchAmenityTypesAPI(poiTypes);
|
||||
apis.add(searchAmenityTypesAPI);
|
||||
apis.add(new SearchCoreFactory.SearchAmenityByTypeAPI(poiTypes, searchAmenityTypesAPI));
|
||||
apis.add(new SearchCoreFactory.SearchAmenityByNameAPI(searchAmenityTypesAPI));
|
||||
SearchBuildingAndIntersectionsByStreetAPI streetsApi =
|
||||
new SearchCoreFactory.SearchBuildingAndIntersectionsByStreetAPI();
|
||||
apis.add(streetsApi);
|
||||
|
|
|
@ -500,14 +500,20 @@ public class SearchCoreFactory {
|
|||
private static final int LIMIT = 10000;
|
||||
private static final int BBOX_RADIUS = 500 * 1000;
|
||||
private static final int BBOX_RADIUS_INSIDE = 10000 * 1000; // to support city search for basemap
|
||||
private SearchAmenityTypesAPI searchAmenityTypesAPI;
|
||||
|
||||
public SearchAmenityByNameAPI() {
|
||||
public SearchAmenityByNameAPI(SearchAmenityTypesAPI searchAmenityTypesAPI) {
|
||||
super(ObjectType.POI);
|
||||
this.searchAmenityTypesAPI = searchAmenityTypesAPI;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean search(final SearchPhrase phrase, final SearchResultMatcher resultMatcher) throws IOException {
|
||||
if(!phrase.isUnknownSearchWordPresent()) {
|
||||
if (!phrase.isUnknownSearchWordPresent()) {
|
||||
return false;
|
||||
}
|
||||
if (phrase.isNoSelectedType() && phrase.isUnknownSearchWordPresent()
|
||||
&& phrase.isUnknownSearchWordComplete() && searchAmenityTypesAPI.hasFoundPoiTypes()) {
|
||||
return false;
|
||||
}
|
||||
final BinaryMapIndexReader[] currentFile = new BinaryMapIndexReader[1];
|
||||
|
@ -602,7 +608,7 @@ public class SearchCoreFactory {
|
|||
public int getMinimalSearchRadius(SearchPhrase phrase) {
|
||||
return phrase.getRadiusSearch(BBOX_RADIUS);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getNextSearchRadius(SearchPhrase phrase) {
|
||||
return phrase.getNextRadiusSearch(BBOX_RADIUS);
|
||||
|
@ -619,12 +625,21 @@ public class SearchCoreFactory {
|
|||
private List<CustomSearchPoiFilter> customPoiFilters = new ArrayList<>();
|
||||
private TIntArrayList customPoiFiltersPriorites = new TIntArrayList();
|
||||
private MapPoiTypes types;
|
||||
private List<AbstractPoiType> foundPoiTypes = new ArrayList<>();
|
||||
|
||||
public SearchAmenityTypesAPI(MapPoiTypes types) {
|
||||
super(ObjectType.POI_TYPE);
|
||||
this.types = types;
|
||||
}
|
||||
|
||||
public List<AbstractPoiType> getFoundPoiTypes() {
|
||||
return foundPoiTypes;
|
||||
}
|
||||
|
||||
public boolean hasFoundPoiTypes() {
|
||||
return foundPoiTypes.size() > 0;
|
||||
}
|
||||
|
||||
public void clearCustomFilters() {
|
||||
this.customPoiFilters.clear();
|
||||
this.customPoiFiltersPriorites.clear();
|
||||
|
@ -642,7 +657,6 @@ public class SearchCoreFactory {
|
|||
topVisibleFilters = types.getTopVisibleFilters();
|
||||
categories = types.getCategories(false);
|
||||
}
|
||||
// results.clear();
|
||||
List<AbstractPoiType> results = new ArrayList<AbstractPoiType>();
|
||||
NameStringMatcher nm = phrase.getNameStringMatcher();
|
||||
for (PoiFilter pf : topVisibleFilters) {
|
||||
|
@ -687,6 +701,8 @@ public class SearchCoreFactory {
|
|||
}
|
||||
}
|
||||
}
|
||||
foundPoiTypes = new ArrayList<>(results);
|
||||
|
||||
for (AbstractPoiType pt : results) {
|
||||
SearchResult res = new SearchResult(phrase);
|
||||
res.localeName = pt.getTranslation();
|
||||
|
@ -733,12 +749,14 @@ public class SearchCoreFactory {
|
|||
|
||||
public static class SearchAmenityByTypeAPI extends SearchBaseAPI {
|
||||
private static final int BBOX_RADIUS = 10000;
|
||||
private SearchAmenityTypesAPI searchAmenityTypesAPI;
|
||||
|
||||
private MapPoiTypes types;
|
||||
|
||||
public SearchAmenityByTypeAPI(MapPoiTypes types) {
|
||||
public SearchAmenityByTypeAPI(MapPoiTypes types, SearchAmenityTypesAPI searchAmenityTypesAPI) {
|
||||
super(ObjectType.POI);
|
||||
this.types = types;
|
||||
this.searchAmenityTypesAPI = searchAmenityTypesAPI;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -750,7 +768,7 @@ public class SearchCoreFactory {
|
|||
public int getMinimalSearchRadius(SearchPhrase phrase) {
|
||||
return phrase.getRadiusSearch(BBOX_RADIUS);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getNextSearchRadius(SearchPhrase phrase) {
|
||||
return phrase.getNextRadiusSearch(BBOX_RADIUS);
|
||||
|
@ -792,29 +810,66 @@ public class SearchCoreFactory {
|
|||
} else {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
QuadRect bbox = phrase.getRadiusBBoxToSearch(BBOX_RADIUS);
|
||||
List<BinaryMapIndexReader> oo = phrase.getOfflineIndexes();
|
||||
Set<String> searchedPois = new TreeSet<>();
|
||||
for (BinaryMapIndexReader o : oo) {
|
||||
ResultMatcher<Amenity> rm = getResultMatcher(phrase, resultMatcher, o, searchedPois);
|
||||
ResultMatcher<Amenity> rm = getResultMatcher(phrase, resultMatcher, null, o, searchedPois);
|
||||
if (obj instanceof CustomSearchPoiFilter) {
|
||||
rm = ((CustomSearchPoiFilter) obj).wrapResultMatcher(rm);
|
||||
}
|
||||
SearchRequest<Amenity> req = BinaryMapIndexReader.buildSearchPoiRequest(
|
||||
(int)bbox.left, (int)bbox.right,
|
||||
(int)bbox.top, (int)bbox.bottom, -1, ptf,
|
||||
rm);
|
||||
o.searchPoi(req);
|
||||
resultMatcher.apiSearchRegionFinished(this, o, phrase);
|
||||
searchPoi(phrase, resultMatcher, ptf, bbox, o, rm);
|
||||
}
|
||||
} else {
|
||||
List<AbstractPoiType> poiTypes = searchAmenityTypesAPI.getFoundPoiTypes();
|
||||
for (AbstractPoiType pt : poiTypes) {
|
||||
SearchPoiTypeFilter ptf = getPoiTypeFilter(pt);
|
||||
QuadRect bbox = phrase.getRadiusBBoxToSearch(BBOX_RADIUS);
|
||||
String customName = null;
|
||||
NameStringMatcher nm = phrase.getNameStringMatcher(phrase.getUnknownSearchWord(), true);
|
||||
String unknownSearchPhrase = phrase.getUnknownSearchPhrase();
|
||||
String enTranslation = pt.getEnTranslation();
|
||||
String translation = pt.getTranslation();
|
||||
String synonyms = pt.getSynonyms();
|
||||
if (unknownSearchPhrase.length() > enTranslation.length() && nm.matches(enTranslation)) {
|
||||
customName = unknownSearchPhrase.substring(enTranslation.length()).trim();
|
||||
} else if (unknownSearchPhrase.length() > translation.length() && nm.matches(translation)) {
|
||||
customName = unknownSearchPhrase.substring(translation.length()).trim();
|
||||
} else if (unknownSearchPhrase.length() > synonyms.length() && nm.matches(synonyms)) {
|
||||
customName = unknownSearchPhrase.substring(synonyms.length()).trim();
|
||||
}
|
||||
if (!Algorithms.isEmpty(customName)) {
|
||||
List<BinaryMapIndexReader> oo = phrase.getOfflineIndexes();
|
||||
Set<String> searchedPois = new TreeSet<>();
|
||||
for (BinaryMapIndexReader o : oo) {
|
||||
ResultMatcher<Amenity> rm = getResultMatcher(phrase, resultMatcher, customName, o, searchedPois);
|
||||
searchPoi(phrase, resultMatcher, ptf, bbox, o, rm);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void searchPoi(SearchPhrase phrase, SearchResultMatcher resultMatcher, SearchPoiTypeFilter ptf, QuadRect bbox, BinaryMapIndexReader o, ResultMatcher<Amenity> rm) throws IOException {
|
||||
SearchRequest<Amenity> req = BinaryMapIndexReader.buildSearchPoiRequest(
|
||||
(int) bbox.left, (int) bbox.right,
|
||||
(int) bbox.top, (int) bbox.bottom, -1, ptf,
|
||||
rm);
|
||||
o.searchPoi(req);
|
||||
resultMatcher.apiSearchRegionFinished(this, o, phrase);
|
||||
}
|
||||
|
||||
private ResultMatcher<Amenity> getResultMatcher(final SearchPhrase phrase, final SearchResultMatcher resultMatcher,
|
||||
final BinaryMapIndexReader selected, final Set<String> searchedPois) {
|
||||
final NameStringMatcher ns = phrase.getNameStringMatcher();
|
||||
final String customName, final BinaryMapIndexReader selected,
|
||||
final Set<String> searchedPois) {
|
||||
final NameStringMatcher ns;
|
||||
final boolean hasCustomName = !Algorithms.isEmpty(customName);
|
||||
if (hasCustomName) {
|
||||
ns = phrase.getNameStringMatcher(customName, phrase.isLastUnknownSearchWordComplete());
|
||||
} else {
|
||||
ns = phrase.getNameStringMatcher();
|
||||
}
|
||||
return new ResultMatcher<Amenity>() {
|
||||
|
||||
@Override
|
||||
|
@ -846,7 +901,7 @@ public class SearchCoreFactory {
|
|||
res.preferredZoom = 17;
|
||||
res.file = selected;
|
||||
res.location = object.getLocation();
|
||||
res.priority = SEARCH_AMENITY_BY_TYPE_PRIORITY;
|
||||
res.priority = hasCustomName ? SEARCH_AMENITY_TYPE_PRIORITY - 1 : SEARCH_AMENITY_BY_TYPE_PRIORITY;
|
||||
res.priorityDistance = 1;
|
||||
res.objectType = ObjectType.POI;
|
||||
resultMatcher.publish(res);
|
||||
|
@ -894,13 +949,12 @@ public class SearchCoreFactory {
|
|||
|
||||
@Override
|
||||
public int getSearchPriority(SearchPhrase p) {
|
||||
if (p.isLastWord(ObjectType.POI_TYPE) &&
|
||||
p.getLastTokenLocation() != null) {
|
||||
if ((p.isLastWord(ObjectType.POI_TYPE) && p.getLastTokenLocation() != null)
|
||||
|| (p.isNoSelectedType() && p.isUnknownSearchWordComplete() && searchAmenityTypesAPI.hasFoundPoiTypes())) {
|
||||
return SEARCH_AMENITY_BY_TYPE_PRIORITY;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue