Merge pull request #9646 from androiddevkotlin/street_complete_parsing

Fix #9532
This commit is contained in:
vshcherb 2020-08-21 10:29:35 +02:00 committed by GitHub
commit 133e8a25ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 54 deletions

View file

@ -133,19 +133,19 @@ public class SearchCoreFactory {
public int getMinimalSearchRadius(SearchPhrase phrase) {
return 0;
}
@Override
public int getNextSearchRadius(SearchPhrase phrase) {
return 0;
}
protected void subSearchApiOrPublish(SearchPhrase phrase, SearchResultMatcher resultMatcher, SearchResult res, SearchBaseAPI api)
protected void subSearchApiOrPublish(SearchPhrase phrase, SearchResultMatcher resultMatcher, SearchResult res, SearchBaseAPI api)
throws IOException {
subSearchApiOrPublish(phrase, resultMatcher, res, api, true);
}
protected void subSearchApiOrPublish(SearchPhrase phrase, SearchResultMatcher resultMatcher, SearchResult res, SearchBaseAPI api,
boolean publish)
boolean publish)
throws IOException {
phrase.countUnknownWordsMatchMainResult(res);
boolean firstUnknownWordMatches = res.firstUnknownWordMatches;
@ -154,7 +154,7 @@ public class SearchCoreFactory {
leftUnknownSearchWords.removeAll(res.otherWordsMatch);
}
SearchResult newParentSearchResult = null;
if (res.parentSearchResult == null && resultMatcher.getParentSearchResult() == null &&
if (res.parentSearchResult == null && resultMatcher.getParentSearchResult() == null &&
res.objectType == ObjectType.STREET && res.object instanceof Street && ((Street) res.object).getCity() != null) {
City ct = ((Street) res.object).getCity();
SearchResult cityResult = new SearchResult(phrase);
@ -204,15 +204,15 @@ public class SearchCoreFactory {
}
}
if (!leftUnknownSearchWords.isEmpty() && api != null && api.isSearchAvailable(phrase)) {
SearchPhrase nphrase = phrase.selectWord(res, leftUnknownSearchWords,
phrase.isLastUnknownSearchWordComplete() ||
!leftUnknownSearchWords.contains(phrase.getLastUnknownSearchWord()));
SearchResult prev = resultMatcher.setParentSearchResult(publish ? res :
resultMatcher.getParentSearchResult());
SearchPhrase nphrase = phrase.selectWord(res, leftUnknownSearchWords,
phrase.isLastUnknownSearchWordComplete() ||
!leftUnknownSearchWords.contains(phrase.getLastUnknownSearchWord()));
SearchResult prev = resultMatcher.setParentSearchResult(publish ? res :
resultMatcher.getParentSearchResult());
api.search(nphrase, resultMatcher);
resultMatcher.setParentSearchResult(prev);
}
}
@Override
@ -307,7 +307,7 @@ public class SearchCoreFactory {
public int getMinimalSearchRadius(SearchPhrase phrase) {
return phrase.getRadiusSearch(DEFAULT_ADDRESS_BBOX_RADIUS);
}
@Override
public int getNextSearchRadius(SearchPhrase phrase) {
return phrase.getNextRadiusSearch(DEFAULT_ADDRESS_BBOX_RADIUS);
@ -383,7 +383,7 @@ public class SearchCoreFactory {
private void searchByName(final SearchPhrase phrase, final SearchResultMatcher resultMatcher)
throws IOException {
if (phrase.getRadiusLevel() > 1 || phrase.getUnknownWordToSearch().length() > 3 ||
if (phrase.getRadiusLevel() > 1 || phrase.getUnknownWordToSearch().length() > 3 ||
phrase.hasMoreThanOneUnknownSearchWord()|| phrase.isSearchTypeAllowed(ObjectType.POSTCODE, true)) {
final boolean locSpecified = phrase.getLastTokenLocation() != null;
LatLon loc = phrase.getLastTokenLocation();
@ -424,7 +424,7 @@ public class SearchCoreFactory {
if (object.getName().startsWith("<")) {
return false;
}
if (!phrase.getUnknownWordToSearchBuildingNameMatcher().matches(stripBraces(sr.localeName))) {
sr.priorityDistance = 5;
}
@ -558,7 +558,7 @@ public class SearchCoreFactory {
}
// Take into account POI [bar] - 'Hospital 512'
// BEFORE: it was searching exact match of whole phrase.getUnknownSearchPhrase() [ Check feedback ]
final BinaryMapIndexReader[] currentFile = new BinaryMapIndexReader[1];
Iterator<BinaryMapIndexReader> offlineIterator = phrase.getRadiusOfflineIndexes(BBOX_RADIUS,
SearchPhraseDataType.POI);
@ -670,7 +670,7 @@ public class SearchCoreFactory {
return phrase.getNextRadiusSearch(BBOX_RADIUS);
}
}
protected static class PoiTypeResult {
public AbstractPoiType pt;
public Set<String> foundWords = new LinkedHashSet<String>();
@ -709,7 +709,7 @@ public class SearchCoreFactory {
this.activePoiFilters.put(filterOrder.get(i), i);
}
}
public Map<String, PoiTypeResult> getPoiTypeResults(NameStringMatcher nm, NameStringMatcher nmAdditional) {
Map<String, PoiTypeResult> results = new LinkedHashMap<>();
for (AbstractPoiType pf : topVisibleFilters) {
@ -764,7 +764,7 @@ public class SearchCoreFactory {
} else {
String enTranslation = a.getEnTranslation().toLowerCase();
if (!"no".equals(enTranslation) // && !"yes".equals(enTranslation)
) {
) {
PoiTypeResult ptr = checkPoiType(nm, a);
if (ptr != null) {
results.put(a.getKeyName(), ptr);
@ -816,12 +816,12 @@ public class SearchCoreFactory {
categories = types.getCategories(false);
}
}
@Override
public boolean search(SearchPhrase phrase, SearchResultMatcher resultMatcher) throws IOException {
boolean showTopFiltersOnly = !phrase.isUnknownSearchWordPresent();
NameStringMatcher nm = phrase.getFirstUnknownNameStringMatcher();
initPoiTypes();
if (showTopFiltersOnly) {
for (AbstractPoiType pt : topVisibleFilters) {
@ -830,10 +830,10 @@ public class SearchCoreFactory {
res.object = pt;
addPoiTypeResult(phrase, resultMatcher, showTopFiltersOnly, getStandardFilterId(pt), res);
}
} else {
boolean includeAdditional = !phrase.hasMoreThanOneUnknownSearchWord();
NameStringMatcher nmAdditional = includeAdditional ?
NameStringMatcher nmAdditional = includeAdditional ?
new NameStringMatcher(phrase.getFirstUnknownSearchWord(), StringMatcherMode.CHECK_EQUALS_FROM_SPACE) : null;
Map<String, PoiTypeResult> poiTypes = getPoiTypeResults(nm, nmAdditional);
for (PoiTypeResult ptr : poiTypes.values()) {
@ -869,7 +869,7 @@ public class SearchCoreFactory {
}
private void addPoiTypeResult(SearchPhrase phrase, SearchResultMatcher resultMatcher, boolean showTopFiltersOnly,
String stdFilterId, SearchResult res) {
String stdFilterId, SearchResult res) {
res.priorityDistance = 0;
res.objectType = ObjectType.POI_TYPE;
res.firstUnknownWordMatches = true;
@ -893,7 +893,7 @@ public class SearchCoreFactory {
return SEARCH_AMENITY_TYPE_PRIORITY + i.intValue();
}
public String getStandardFilterId(AbstractPoiType poi) {
return STD_POI_FILTER_PREFIX + poi.getKeyName();
@ -926,7 +926,7 @@ public class SearchCoreFactory {
private MapPoiTypes types;
private AbstractPoiType unselectedPoiType;
private String nameFilter;
public SearchAmenityByTypeAPI(MapPoiTypes types, SearchAmenityTypesAPI searchAmenityTypesAPI) {
super(ObjectType.POI);
this.types = types;
@ -975,7 +975,7 @@ public class SearchCoreFactory {
nameFilter = phrase.getUnknownSearchPhrase();
} else if (searchAmenityTypesAPI != null && phrase.isFirstUnknownSearchWordComplete()) {
NameStringMatcher nm = phrase.getFirstUnknownNameStringMatcher();
NameStringMatcher nmAdditional = new NameStringMatcher(phrase.getFirstUnknownSearchWord(),
NameStringMatcher nmAdditional = new NameStringMatcher(phrase.getFirstUnknownSearchWord(),
StringMatcherMode.CHECK_EQUALS_FROM_SPACE) ;
searchAmenityTypesAPI.initPoiTypes();
Map<String, PoiTypeResult> poiTypeResults = searchAmenityTypesAPI.getPoiTypeResults(nm, nmAdditional);
@ -1010,7 +1010,7 @@ public class SearchCoreFactory {
List<BinaryMapIndexReader> offlineIndexes = phrase.getOfflineIndexes();
Set<String> searchedPois = new TreeSet<>();
for (BinaryMapIndexReader r : offlineIndexes) {
ResultMatcher<Amenity> rm = getResultMatcher(phrase, poiTypeFilter, resultMatcher, nameFilter, r,
ResultMatcher<Amenity> rm = getResultMatcher(phrase, poiTypeFilter, resultMatcher, nameFilter, r,
searchedPois, poiAdditionals, countExtraWords);
if (poiTypeFilter instanceof CustomSearchPoiFilter) {
rm = ((CustomSearchPoiFilter) poiTypeFilter).wrapResultMatcher(rm);
@ -1025,12 +1025,12 @@ public class SearchCoreFactory {
}
private ResultMatcher<Amenity> getResultMatcher(final SearchPhrase phrase, final SearchPoiTypeFilter poiTypeFilter,
final SearchResultMatcher resultMatcher, final String nameFilter,
private ResultMatcher<Amenity> getResultMatcher(final SearchPhrase phrase, final SearchPoiTypeFilter poiTypeFilter,
final SearchResultMatcher resultMatcher, final String nameFilter,
final BinaryMapIndexReader selected, final Set<String> searchedPois,
final Collection<String> poiAdditionals, final int countExtraWords) {
final NameStringMatcher ns = nameFilter == null ? null : new NameStringMatcher(nameFilter, StringMatcherMode.CHECK_STARTS_FROM_SPACE);
return new ResultMatcher<Amenity>() {
@ -1186,7 +1186,7 @@ public class SearchCoreFactory {
NameStringMatcher nm = phrase.getMainUnknownNameStringMatcher();
for (Street object : c.getStreets()) {
SearchResult res = new SearchResult(phrase);
res.localeName = object.getName(phrase.getSettings().getLang(), phrase.getSettings().isTransliterate());
res.otherNames = object.getAllNames(true);
boolean pub = true;
@ -1266,7 +1266,7 @@ public class SearchCoreFactory {
if (s != null) {
BinaryMapIndexReader file = phrase.getLastSelectedWord().getResult().file;
if (cacheBuilding != s) {
cacheBuilding = s;
SearchRequest<Building> sr = BinaryMapIndexReader
@ -1325,13 +1325,13 @@ public class SearchCoreFactory {
res.location = b.getLocation();
}
res.preferredZoom = 17;
resultMatcher.publish(res);
}
String streetIntersection = phrase.getUnknownWordToSearch();
NameStringMatcher streetMatch = phrase.getMainUnknownNameStringMatcher();
if (Algorithms.isEmpty(streetIntersection) ||
(!Character.isDigit(streetIntersection.charAt(0)) &&
if (Algorithms.isEmpty(streetIntersection) ||
(!Character.isDigit(streetIntersection.charAt(0)) &&
CommonWords.getCommonSearch(streetIntersection) == -1) ) {
for (Street street : s.getIntersectedStreets()) {
SearchResult res = new SearchResult(phrase);
@ -1369,7 +1369,7 @@ public class SearchCoreFactory {
return SEARCH_BUILDING_BY_STREET_PRIORITY;
}
}
protected static class PoiAdditionalCustomFilter extends AbstractPoiType {
protected List<PoiType> additionalPoiTypes = new ArrayList<PoiType>();
@ -1378,7 +1378,7 @@ public class SearchCoreFactory {
super(pt.getKeyName(), registry);
additionalPoiTypes.add(pt);
}
@Override
public boolean isAdditional() {
return true;
@ -1397,7 +1397,7 @@ public class SearchCoreFactory {
}
return acceptedTypes;
}
}
public static class SearchLocationAndUrlAPI extends SearchBaseAPI {
@ -1569,7 +1569,7 @@ public class SearchCoreFactory {
}
return retName;
}
public static boolean isLastWordCityGroup(SearchPhrase p ) {
return p.isLastWord(ObjectType.CITY) || p.isLastWord(ObjectType.POSTCODE) ||
p.isLastWord(ObjectType.VILLAGE);

View file

@ -13,7 +13,7 @@ import java.util.regex.Pattern;
public class GeoPointParserUtil {
private static String getQueryParameter(final String param, URI uri) {
final String query = uri.getQuery();
String value = null;
@ -103,7 +103,7 @@ public class GeoPointParserUtil {
if(uri.getSchemeSpecificPart() == null) {
return null;
} else if(!uri.getSchemeSpecificPart().contains("=")) {
params = getQueryParameters("q="+uri.getSchemeSpecificPart());
params = getQueryParameters("q="+uri.getSchemeSpecificPart());
} else {
params = getQueryParameters(uri.getSchemeSpecificPart());
}
@ -181,7 +181,7 @@ public class GeoPointParserUtil {
}
} else if (host.startsWith("map.baidu.")) { // .com and .cn both work
/* Baidu Map uses a custom format for lat/lon., it is basically standard lat/lon
* multiplied by 100,000, then rounded to an integer */
* multiplied by 100,000, then rounded to an integer */
String zm = params.get("l");
String[] vls = silentSplit(params.get("c"), ",");
if (vls != null && vls.length >= 2) {
@ -219,7 +219,7 @@ public class GeoPointParserUtil {
String latString = null;
String lonString = null;
String z = String.valueOf(GeoParsedPoint.NO_ZOOM);
if (params.containsKey("q")) {
System.out.println("q=" + params.get("q"));
Matcher matcher = commaSeparatedPairPattern.matcher(params.get("q"));
@ -297,7 +297,7 @@ public class GeoPointParserUtil {
Pattern p;
Matcher matcher;
final String[] patterns = {
/* though this looks like Query String, it is also used as part of the Fragment */
/* though this looks like Query String, it is also used as part of the Fragment */
".*q=([+-]?\\d+(?:\\.\\d+)?),([+-]?\\d+(?:\\.\\d+)?).*&radius=(\\d+).*",
".*q=([+-]?\\d+(?:\\.\\d+)?),([+-]?\\d+(?:\\.\\d+)?).*",
".*p=(?:[A-Z0-9]+),([+-]?\\d+(?:\\.\\d+)?),([+-]?\\d+(?:\\.\\d+)?).*",};
@ -315,7 +315,7 @@ public class GeoPointParserUtil {
}
}
}
} else if (host.equals("here.com") || host.endsWith(".here.com")) { // www.here.com, share.here.com, here.com
} else if (host.equals("here.com") || host.endsWith(".here.com")) { // www.here.com, share.here.com, here.com
String z = String.valueOf(GeoParsedPoint.NO_ZOOM);
String label = null;
if (params.containsKey("msg")) {
@ -492,7 +492,7 @@ public class GeoPointParserUtil {
}
if ("z".equals(paramName) && paramValue != null) {
zoom = Integer.parseInt(paramValue);
zoom = (int) Float.parseFloat(paramValue);
} else if ("q".equals(paramName) && paramValue != null) {
searchRequest = URLDecoder.decode(paramValue);
}
@ -587,7 +587,7 @@ public class GeoPointParserUtil {
private static int parseZoom(String zoom) {
try {
if (zoom != null) {
return Integer.valueOf(zoom);
return (int) Float.parseFloat(zoom);
}
} catch (NumberFormatException e) {
}
@ -597,7 +597,7 @@ public class GeoPointParserUtil {
private static double parseSilentDouble(String zoom) {
return parseSilentDouble(zoom, 0);
}
private static double parseSilentDouble(String zoom, double vl) {
try {
if (zoom != null) {
@ -772,9 +772,9 @@ public class GeoPointParserUtil {
@Override
public String toString() {
return isGeoPoint() ?
String.format("GeoParsedPoint [lat=%.5f, lon=%.5f, zoom=%d, label=%s]", lat, lon, zoom, label) :
String.format("GeoParsedPoint [query=%s]",query);
return isGeoPoint() ?
String.format("GeoParsedPoint [lat=%.5f, lon=%.5f, zoom=%d, label=%s]", lat, lon, zoom, label) :
String.format("GeoParsedPoint [query=%s]",query);
}
}
}

View file

@ -716,7 +716,7 @@ public class GeoPointParserUtilTest {
actual = GeoPointParserUtil.parse(url);
assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z));
/* URLs straight from various services, instead of generated here */
/* URLs straight from various services, instead of generated here */
String urls[] = {
"https://openstreetmap.org/go/0LQ127-?m",

View file

@ -307,7 +307,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
int position = getListView().getPositionForView(selected);
if ((position != AdapterView.INVALID_POSITION) && (position >= getListView().getHeaderViewsCount())) {
dialogFragment.getNavigationInfo().updateTargetDirection(
listAdapter.getItem(position - getListView().getHeaderViewsCount()).getSearchResult().location,
listAdapter.getItem(position - getListView().getHeaderViewsCount()).getSearchResult().location,
heading.floatValue());
}
} catch (Exception e) {