Added maxDistance to generate limited test data

This commit is contained in:
max-klaus 2020-06-06 16:39:04 +03:00
parent 6fad0f9a51
commit 6b12e5b9a9
4 changed files with 27 additions and 14 deletions

View file

@ -778,14 +778,28 @@ public class SearchUICore {
return exportedCities;
}
public void exportObject(MapObject object) {
public void exportObject(SearchPhrase phrase, MapObject object) {
double maxDistance = phrase.getSettings().getExportSettings().getMaxDistance();
if (maxDistance > 0) {
double distance = MapUtils.getDistance(phrase.getSettings().getOriginalLocation(), object.getLocation());
if (distance > maxDistance) {
return;
}
}
if (exportedObjects == null) {
exportedObjects = new ArrayList<>();
}
exportedObjects.add(object);
}
public void exportCity(City city) {
public void exportCity(SearchPhrase phrase, City city) {
double maxDistance = phrase.getSettings().getExportSettings().getMaxDistance();
if (maxDistance > 0) {
double distance = MapUtils.getDistance(phrase.getSettings().getOriginalLocation(), city.getLocation());
if (distance > maxDistance) {
return;
}
}
if (exportedCities == null) {
exportedCities = new ArrayList<>();
}

View file

@ -343,7 +343,7 @@ public class SearchCoreFactory {
int limit = 0;
for (City c : resArray) {
if (phrase.getSettings().isExportObjects()) {
resultMatcher.exportCity(c);
resultMatcher.exportCity(phrase, c);
}
SearchResult res = new SearchResult(phrase);
res.object = c;
@ -388,7 +388,7 @@ public class SearchCoreFactory {
@Override
public boolean publish(MapObject object) {
if (phrase.getSettings().isExportObjects()) {
resultMatcher.exportObject(object);
resultMatcher.exportObject(phrase, object);
}
if (isCancelled()) {
return false;
@ -546,7 +546,7 @@ public class SearchCoreFactory {
@Override
public boolean publish(Amenity object) {
if (phrase.getSettings().isExportObjects()) {
resultMatcher.exportObject(object);
resultMatcher.exportObject(phrase, object);
}
if (limit++ > LIMIT) {
return false;
@ -952,7 +952,7 @@ public class SearchCoreFactory {
@Override
public boolean publish(Amenity object) {
if (phrase.getSettings().isExportObjects()) {
resultMatcher.exportObject(object);
resultMatcher.exportObject(phrase, object);
}
SearchResult res = new SearchResult(phrase);
String poiID = object.getType().getKeyName() + "_" + object.getId();

View file

@ -3,30 +3,29 @@ package net.osmand.search.core;
public class SearchExportSettings {
private boolean exportEmptyCities;
private boolean exportBuildings;
private double maxDistance;
public SearchExportSettings() {
exportEmptyCities = true;
exportBuildings = true;
maxDistance = -1;
}
public SearchExportSettings(boolean exportEmptyCities, boolean exportBuildings) {
public SearchExportSettings(boolean exportEmptyCities, boolean exportBuildings, double maxDistance) {
this.exportEmptyCities = exportEmptyCities;
this.exportBuildings = exportBuildings;
this.maxDistance = maxDistance;
}
public boolean isExportEmptyCities() {
return exportEmptyCities;
}
public void setExportEmptyCities(boolean exportEmptyCities) {
this.exportEmptyCities = exportEmptyCities;
}
public boolean isExportBuildings() {
return exportBuildings;
}
public void setExportBuildings(boolean exportBuildings) {
this.exportBuildings = exportBuildings;
public double getMaxDistance() {
return maxDistance;
}
}

View file

@ -24,7 +24,7 @@ public class SearchSettings {
private boolean emptyQueryAllowed;
private boolean sortByName;
private SearchExportSettings exportSettings;
//private SearchExportSettings exportSettings = new SearchExportSettings(false, false);
//private SearchExportSettings exportSettings = new SearchExportSettings(false, false, -1);
public SearchSettings(SearchSettings s) {
if(s != null) {