From 651688b3af1b71487abf11e3a12267c50aef43a3 Mon Sep 17 00:00:00 2001 From: crimean Date: Thu, 27 Jun 2019 14:51:06 +0300 Subject: [PATCH] Fix #7022 --- .../net/osmand/search/core/SearchCoreFactory.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java index 96c2726ce6..f42874d5ad 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java @@ -1225,7 +1225,9 @@ public class SearchCoreFactory { public static class SearchLocationAndUrlAPI extends SearchBaseAPI { + private static final int OLC_RECALC_DISTANCE_THRESHOLD = 100000; // 100 km private int olcPhraseHash; + private LatLon olcPhraseLocation; private ParsedOpenLocationCode cachedParsedCode; private final List citySubTypes = Arrays.asList("city", "town", "village"); @@ -1328,6 +1330,9 @@ public class SearchCoreFactory { } } } + if (latLon == null && !parsedCode.isFull()) { + latLon = parsedCode.recover(phrase.getSettings().getOriginalLocation()); + } if (latLon != null) { publishLocation(phrase, resultMatcher, lw, latLon); } @@ -1386,8 +1391,15 @@ public class SearchCoreFactory { return -1; } int olcPhraseHash = p.getUnknownSearchPhrase().hashCode(); + if (this.olcPhraseHash == olcPhraseHash && this.olcPhraseLocation != null) { + double distance = MapUtils.getDistance(p.getSettings().getOriginalLocation(), this.olcPhraseLocation); + if (distance > OLC_RECALC_DISTANCE_THRESHOLD) { + olcPhraseHash++; + } + } if (this.olcPhraseHash != olcPhraseHash) { this.olcPhraseHash = olcPhraseHash; + this.olcPhraseLocation = p.getSettings().getOriginalLocation(); cachedParsedCode = LocationParser.parseOpenLocationCode(p.getUnknownSearchPhrase()); } return cachedParsedCode == null ? SEARCH_LOCATION_PRIORITY : SEARCH_MAX_PRIORITY;