Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
ff7792acd6
3 changed files with 40 additions and 19 deletions
|
@ -151,7 +151,7 @@ public abstract class MapObject implements Comparable<MapObject> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName(String lang, boolean transliterate) {
|
public String getName(String lang, boolean transliterate) {
|
||||||
if (lang != null) {
|
if (lang != null && lang.length() > 0) {
|
||||||
if (lang.equals("en")) {
|
if (lang.equals("en")) {
|
||||||
// ignore transliterate option here for backward compatibility
|
// ignore transliterate option here for backward compatibility
|
||||||
return getEnName(true);
|
return getEnName(true);
|
||||||
|
|
|
@ -12,11 +12,8 @@ import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
|
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.ResultMatcher;
|
import net.osmand.ResultMatcher;
|
||||||
import net.osmand.StringMatcher;
|
|
||||||
import net.osmand.binary.BinaryMapIndexReader;
|
import net.osmand.binary.BinaryMapIndexReader;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.osm.MapPoiTypes;
|
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.search.example.core.SearchWord;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
public class SearchUICore {
|
public class SearchUICore {
|
||||||
|
|
||||||
private static final Log LOG = PlatformUtil.getLog(SearchUICore.class);
|
private static final Log LOG = PlatformUtil.getLog(SearchUICore.class);
|
||||||
private SearchPhrase phrase;
|
private SearchPhrase phrase;
|
||||||
private List<SearchResult> currentSearchResults = new ArrayList<>();
|
private SearchResultCollection currentSearchResult = new SearchResultCollection();
|
||||||
|
|
||||||
private ThreadPoolExecutor singleThreadedExecutor;
|
private ThreadPoolExecutor singleThreadedExecutor;
|
||||||
private LinkedBlockingQueue<Runnable> taskQueue;
|
private LinkedBlockingQueue<Runnable> taskQueue;
|
||||||
|
@ -58,6 +57,28 @@ public class SearchUICore {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class SearchResultCollection {
|
||||||
|
private List<SearchResult> searchResults;
|
||||||
|
private SearchPhrase phrase;
|
||||||
|
|
||||||
|
public SearchResultCollection(List<SearchResult> requestResults, SearchPhrase phrase) {
|
||||||
|
searchResults = requestResults;
|
||||||
|
this.phrase = phrase;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SearchResultCollection() {
|
||||||
|
searchResults = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<SearchResult> getCurrentSearchResults() {
|
||||||
|
return searchResults;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SearchPhrase getPhrase() {
|
||||||
|
return phrase;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int getTotalLimit() {
|
public int getTotalLimit() {
|
||||||
return totalLimit;
|
return totalLimit;
|
||||||
}
|
}
|
||||||
|
@ -76,8 +97,9 @@ public class SearchUICore {
|
||||||
apis.add(new SearchCoreFactory.SearchAddressByNameAPI());
|
apis.add(new SearchCoreFactory.SearchAddressByNameAPI());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SearchResult> getCurrentSearchResults() {
|
|
||||||
return currentSearchResults;
|
public SearchResultCollection getCurrentSearchResult() {
|
||||||
|
return currentSearchResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SearchPhrase getPhrase() {
|
public SearchPhrase getPhrase() {
|
||||||
|
@ -93,9 +115,8 @@ public class SearchUICore {
|
||||||
searchSettings = settings;
|
searchSettings = settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<SearchResult> filterCurrentResults(SearchPhrase phrase) {
|
private List<SearchResult> filterCurrentResults(List<SearchResult> rr, SearchPhrase phrase) {
|
||||||
List<SearchResult> rr = new ArrayList<>();
|
List<SearchResult> l = currentSearchResult.searchResults;
|
||||||
List<SearchResult> l = currentSearchResults;
|
|
||||||
for(SearchResult r : l) {
|
for(SearchResult r : l) {
|
||||||
if(filterOneResult(r, phrase)) {
|
if(filterOneResult(r, phrase)) {
|
||||||
rr.add(r);
|
rr.add(r);
|
||||||
|
@ -114,13 +135,14 @@ public class SearchUICore {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SearchResult> search(final String text, final ResultMatcher<SearchResult> matcher) {
|
public SearchResultCollection search(final String text, final ResultMatcher<SearchResult> matcher) {
|
||||||
List<SearchResult> list = new ArrayList<>();
|
SearchResultCollection quickRes = new SearchResultCollection();
|
||||||
final int request = requestNumber.incrementAndGet();
|
final int request = requestNumber.incrementAndGet();
|
||||||
final SearchPhrase phrase = this.phrase.generateNewPhrase(text, searchSettings);
|
final SearchPhrase phrase = this.phrase.generateNewPhrase(text, searchSettings);
|
||||||
this.phrase = phrase;
|
this.phrase = phrase;
|
||||||
list.addAll(filterCurrentResults(phrase));
|
quickRes.phrase = phrase;
|
||||||
System.out.println("> Search phrase " + phrase + " " + list.size());
|
filterCurrentResults(quickRes.searchResults, phrase);
|
||||||
|
System.out.println("> Search phrase " + phrase + " " + quickRes.searchResults.size());
|
||||||
singleThreadedExecutor.submit(new Runnable() {
|
singleThreadedExecutor.submit(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -135,7 +157,9 @@ public class SearchUICore {
|
||||||
if (!rm.isCancelled()) {
|
if (!rm.isCancelled()) {
|
||||||
sortSearchResults(phrase, rm.getRequestResults());
|
sortSearchResults(phrase, rm.getRequestResults());
|
||||||
System.out.println(">> Search phrase " + phrase + " " + rm.getRequestResults().size());
|
System.out.println(">> Search phrase " + phrase + " " + rm.getRequestResults().size());
|
||||||
currentSearchResults = rm.getRequestResults();
|
SearchResultCollection collection = new SearchResultCollection(rm.getRequestResults(),
|
||||||
|
phrase);
|
||||||
|
currentSearchResult = collection;
|
||||||
if (onResultsComplete != null) {
|
if (onResultsComplete != null) {
|
||||||
onResultsComplete.run();
|
onResultsComplete.run();
|
||||||
}
|
}
|
||||||
|
@ -148,7 +172,7 @@ public class SearchUICore {
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
return list;
|
return quickRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void searchInBackground(final SearchPhrase phrase, SearchResultMatcher matcher) {
|
private void searchInBackground(final SearchPhrase phrase, SearchResultMatcher matcher) {
|
||||||
|
|
|
@ -40,7 +40,6 @@ public class SearchCoreFactory {
|
||||||
// TODO fix search bbox (+)
|
// TODO fix search bbox (+)
|
||||||
// TODO fix search amenity by type (category/additional)
|
// TODO fix search amenity by type (category/additional)
|
||||||
|
|
||||||
|
|
||||||
// TODO streets by city
|
// TODO streets by city
|
||||||
// TODO search only closest file
|
// TODO search only closest file
|
||||||
// TODO limit to one file if city/street/village/poi selected
|
// TODO limit to one file if city/street/village/poi selected
|
||||||
|
@ -57,8 +56,6 @@ public class SearchCoreFactory {
|
||||||
// TODO exclude duplicate streets/cities...
|
// TODO exclude duplicate streets/cities...
|
||||||
// TODO display results momentarily
|
// TODO display results momentarily
|
||||||
|
|
||||||
// TODO map creator (setting for locale)
|
|
||||||
|
|
||||||
// TODO add full text search with comma
|
// TODO add full text search with comma
|
||||||
// TODO add full text search without comma
|
// TODO add full text search without comma
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue