diff --git a/OsmAnd-java/src/net/osmand/search/SearchUICore.java b/OsmAnd-java/src/net/osmand/search/SearchUICore.java index 3afc6ebcd7..1310f79db8 100644 --- a/OsmAnd-java/src/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/net/osmand/search/SearchUICore.java @@ -30,7 +30,9 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; +import java.util.ListIterator; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -68,6 +70,7 @@ public class SearchUICore { public static class SearchResultCollection { private List searchResults; private SearchPhrase phrase; + private static final int DEPTH_TO_CHECK_SAME_SEARCH_RESULTS = 20; public SearchResultCollection(SearchPhrase phrase) { searchResults = new ArrayList<>(); @@ -103,8 +106,16 @@ public class SearchUICore { while(j < addedResults.size()) { SearchResult addedResult = addedResults.get(j); if(i >= searchResults.size()) { - if(searchResults.size() == 0 || - !sameSearchResult(addedResult, searchResults.get(searchResults.size() - 1))) { + int k = 0; + boolean same = false; + while(searchResults.size() > k && k < DEPTH_TO_CHECK_SAME_SEARCH_RESULTS) { + if(sameSearchResult(addedResult, searchResults.get(searchResults.size() - k))) { + same = true; + break; + } + k++; + } + if(!same) { searchResults.add(addedResult); } j++; @@ -151,14 +162,24 @@ public class SearchUICore { } private void filterSearchDuplicateResults(List lst) { - Iterator it = lst.iterator(); - SearchResult found = null; + ListIterator it = lst.listIterator(); + LinkedList lstUnique = new LinkedList(); while(it.hasNext()) { SearchResult r = it.next(); - if(found != null && sameSearchResult(found, r)) { + boolean same = false; + for(SearchResult rs : lstUnique) { + same = sameSearchResult(rs, r); + if(same) { + break; + } + } + if(same) { it.remove(); } else { - found = r; + lstUnique.add(r); + if(lstUnique.size() > DEPTH_TO_CHECK_SAME_SEARCH_RESULTS) { + lstUnique.remove(0); + } } } } @@ -187,7 +208,7 @@ public class SearchUICore { return false; } if (type1.equals("natural")) { - similarityRadius = 10000; + similarityRadius = 50000; } else if (subType1.equals(subType2)) { if (subType1.contains("cn_ref") || subType1.contains("wn_ref") || (subType1.startsWith("route_hiking_") && subType1.endsWith("n_poi"))) {