Update search api

This commit is contained in:
Victor Shcherb 2016-07-13 22:32:52 +02:00
parent 11282acb28
commit 8e1fb14c04
3 changed files with 14 additions and 2 deletions

View file

@ -16,6 +16,7 @@ import net.osmand.ResultMatcher;
import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.data.LatLon;
import net.osmand.osm.MapPoiTypes;
import net.osmand.search.core.ObjectType;
import net.osmand.search.core.SearchCoreAPI;
import net.osmand.search.core.SearchCoreFactory;
import net.osmand.search.core.SearchPhrase;
@ -202,6 +203,7 @@ public class SearchUICore {
}
try {
api.search(phrase, matcher);
matcher.apiSearchFinished(api, phrase);
} catch (Throwable e) {
e.printStackTrace();
LOG.error(e.getMessage(), e);
@ -213,7 +215,7 @@ public class SearchUICore {
private void sortSearchResults(SearchPhrase sp, List<SearchResult> searchResults) {
public void sortSearchResults(SearchPhrase sp, List<SearchResult> searchResults) {
// sort SearchResult by 1. searchDistance 2. Name
final LatLon loc = sp.getLastTokenLocation();
final net.osmand.Collator clt = OsmAndCollator.primaryCollator();
@ -258,6 +260,15 @@ public class SearchUICore {
return requestResults;
}
public void apiSearchFinished(SearchCoreAPI api, SearchPhrase phrase) {
if(matcher != null) {
SearchResult sr = new SearchResult(phrase);
sr.objectType = ObjectType.SEARCH_API_FINISHED;
sr.object = api;
matcher.publish(sr);
}
}
@Override
public boolean publish(SearchResult object) {
if(matcher == null || matcher.publish(object)) {

View file

@ -3,6 +3,7 @@ package net.osmand.search.core;
public enum ObjectType {
CITY(true), VILLAGE(true), POSTCODE(true), STREET(true), HOUSE(true),
STREET_INTERSECTION(true), POI_TYPE(false), POI(true), LOCATION(true), PARTIAL_LOCATION(false), FAVORITE(true),
SEARCH_API_FINISHED(false),
REGION(true), RECENT_OBJ(true), WPT(true), UNKNOWN_NAME_FILTER(false);
private boolean hasLocation;
private ObjectType(boolean location) {

View file

@ -812,7 +812,7 @@ public class SearchCoreFactory {
sp.objectType = ObjectType.LOCATION;
sp.wordsSpan = 2;
resultMatcher.publish(sp);
} else {
} else if (phrase.isNoSelectedType()) {
SearchResult sp = new SearchResult(phrase);
sp.priority = 0;
sp.object = sp.location = new LatLon(dd, 0);