From 1cfebf91a7bd3b56f7b00a67d4f82beb14db2127 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 11 Jul 2016 11:01:25 +0300 Subject: [PATCH] Latest version --- .../src/net/osmand/data/MapObject.java | 2 +- .../osmand/search/example/SearchUICore.java | 54 +++++++++++++------ .../example/core/SearchCoreFactory.java | 3 -- 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/data/MapObject.java b/OsmAnd-java/src/net/osmand/data/MapObject.java index 21780ca2b8..a4068ac8e0 100644 --- a/OsmAnd-java/src/net/osmand/data/MapObject.java +++ b/OsmAnd-java/src/net/osmand/data/MapObject.java @@ -151,7 +151,7 @@ public abstract class MapObject implements Comparable { } public String getName(String lang, boolean transliterate) { - if (lang != null) { + if (lang != null && lang.length() > 0) { if (lang.equals("en")) { // ignore transliterate option here for backward compatibility return getEnName(true); diff --git a/OsmAnd-java/src/net/osmand/search/example/SearchUICore.java b/OsmAnd-java/src/net/osmand/search/example/SearchUICore.java index 8dab2ce345..ebc95e0492 100644 --- a/OsmAnd-java/src/net/osmand/search/example/SearchUICore.java +++ b/OsmAnd-java/src/net/osmand/search/example/SearchUICore.java @@ -12,11 +12,8 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import org.apache.commons.logging.Log; - import net.osmand.PlatformUtil; import net.osmand.ResultMatcher; -import net.osmand.StringMatcher; import net.osmand.binary.BinaryMapIndexReader; import net.osmand.data.LatLon; import net.osmand.osm.MapPoiTypes; @@ -30,11 +27,13 @@ import net.osmand.search.example.core.SearchSettings; import net.osmand.search.example.core.SearchWord; import net.osmand.util.Algorithms; +import org.apache.commons.logging.Log; + public class SearchUICore { private static final Log LOG = PlatformUtil.getLog(SearchUICore.class); private SearchPhrase phrase; - private List currentSearchResults = new ArrayList<>(); + private SearchResultCollection currentSearchResult = new SearchResultCollection(); private ThreadPoolExecutor singleThreadedExecutor; private LinkedBlockingQueue taskQueue; @@ -58,6 +57,28 @@ public class SearchUICore { init(); } + public static class SearchResultCollection { + private List searchResults; + private SearchPhrase phrase; + + public SearchResultCollection(List requestResults, SearchPhrase phrase) { + searchResults = requestResults; + this.phrase = phrase; + } + + public SearchResultCollection() { + searchResults = new ArrayList<>(); + } + + public List getCurrentSearchResults() { + return searchResults; + } + + public SearchPhrase getPhrase() { + return phrase; + } + } + public int getTotalLimit() { return totalLimit; } @@ -76,8 +97,9 @@ public class SearchUICore { apis.add(new SearchCoreFactory.SearchAddressByNameAPI()); } - public List getCurrentSearchResults() { - return currentSearchResults; + + public SearchResultCollection getCurrentSearchResult() { + return currentSearchResult; } public SearchPhrase getPhrase() { @@ -93,9 +115,8 @@ public class SearchUICore { searchSettings = settings; } - private List filterCurrentResults(SearchPhrase phrase) { - List rr = new ArrayList<>(); - List l = currentSearchResults; + private List filterCurrentResults(List rr, SearchPhrase phrase) { + List l = currentSearchResult.searchResults; for(SearchResult r : l) { if(filterOneResult(r, phrase)) { rr.add(r); @@ -114,13 +135,14 @@ public class SearchUICore { return true; } - public List search(final String text, final ResultMatcher matcher) { - List list = new ArrayList<>(); + public SearchResultCollection search(final String text, final ResultMatcher matcher) { + SearchResultCollection quickRes = new SearchResultCollection(); final int request = requestNumber.incrementAndGet(); final SearchPhrase phrase = this.phrase.generateNewPhrase(text, searchSettings); this.phrase = phrase; - list.addAll(filterCurrentResults(phrase)); - System.out.println("> Search phrase " + phrase + " " + list.size()); + quickRes.phrase = phrase; + filterCurrentResults(quickRes.searchResults, phrase); + System.out.println("> Search phrase " + phrase + " " + quickRes.searchResults.size()); singleThreadedExecutor.submit(new Runnable() { @Override @@ -135,7 +157,9 @@ public class SearchUICore { if (!rm.isCancelled()) { sortSearchResults(phrase, rm.getRequestResults()); System.out.println(">> Search phrase " + phrase + " " + rm.getRequestResults().size()); - currentSearchResults = rm.getRequestResults(); + SearchResultCollection collection = new SearchResultCollection(rm.getRequestResults(), + phrase); + currentSearchResult = collection; if (onResultsComplete != null) { onResultsComplete.run(); } @@ -148,7 +172,7 @@ public class SearchUICore { }); - return list; + return quickRes; } private void searchInBackground(final SearchPhrase phrase, SearchResultMatcher matcher) { diff --git a/OsmAnd-java/src/net/osmand/search/example/core/SearchCoreFactory.java b/OsmAnd-java/src/net/osmand/search/example/core/SearchCoreFactory.java index 429ab93535..ef4e5a08ee 100644 --- a/OsmAnd-java/src/net/osmand/search/example/core/SearchCoreFactory.java +++ b/OsmAnd-java/src/net/osmand/search/example/core/SearchCoreFactory.java @@ -40,7 +40,6 @@ public class SearchCoreFactory { // TODO fix search bbox (+) // TODO fix search amenity by type (category/additional) - // TODO streets by city // TODO search only closest file // TODO limit to one file if city/street/village/poi selected @@ -57,8 +56,6 @@ public class SearchCoreFactory { // TODO exclude duplicate streets/cities... // TODO display results momentarily - // TODO map creator (setting for locale) - // TODO add full text search with comma // TODO add full text search without comma