Fix merge indexes
This commit is contained in:
parent
c569dba3c1
commit
5578226647
7 changed files with 56 additions and 22 deletions
|
@ -20,6 +20,7 @@ public class CollatorStringMatcher implements StringMatcher {
|
|||
CHECK_ONLY_STARTS_WITH,
|
||||
CHECK_STARTS_FROM_SPACE,
|
||||
CHECK_STARTS_FROM_SPACE_NOT_BEGINNING,
|
||||
CHECK_EQUALS_FROM_SPACE,
|
||||
CHECK_CONTAINS
|
||||
}
|
||||
|
||||
|
@ -43,12 +44,14 @@ public class CollatorStringMatcher implements StringMatcher {
|
|||
switch (mode) {
|
||||
case CHECK_CONTAINS:
|
||||
return ccontains(collator, base, part);
|
||||
case CHECK_EQUALS_FROM_SPACE:
|
||||
return cstartsWith(collator, base, part, true, true, true);
|
||||
case CHECK_STARTS_FROM_SPACE:
|
||||
return cstartsWith(collator, base, part, true, true);
|
||||
return cstartsWith(collator, base, part, true, true, false);
|
||||
case CHECK_STARTS_FROM_SPACE_NOT_BEGINNING:
|
||||
return cstartsWith(collator, base, part, false, true);
|
||||
return cstartsWith(collator, base, part, false, true, false);
|
||||
case CHECK_ONLY_STARTS_WITH:
|
||||
return cstartsWith(collator, base, part, true, false);
|
||||
return cstartsWith(collator, base, part, true, false, false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -97,7 +100,7 @@ public class CollatorStringMatcher implements StringMatcher {
|
|||
* @return true if searchIn starts with token
|
||||
*/
|
||||
public static boolean cstartsWith(Collator collator, String searchInParam, String theStart,
|
||||
boolean checkBeginning, boolean checkSpaces) {
|
||||
boolean checkBeginning, boolean checkSpaces, boolean equals) {
|
||||
String searchIn = searchInParam.toLowerCase(Locale.getDefault());
|
||||
int startLength = theStart.length();
|
||||
int searchInLength = searchIn.length();
|
||||
|
@ -111,14 +114,26 @@ public class CollatorStringMatcher implements StringMatcher {
|
|||
if (checkBeginning) {
|
||||
boolean starts = collator.equals(searchIn.substring(0, startLength), theStart);
|
||||
if (starts) {
|
||||
return true;
|
||||
if (equals) {
|
||||
if (startLength == searchInLength || isSpace(searchIn.charAt(startLength))) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (checkSpaces) {
|
||||
for (int i = 1; i <= searchInLength - startLength; i++) {
|
||||
if (isSpace(searchIn.charAt(i - 1)) && !isSpace(searchIn.charAt(i))) {
|
||||
if (collator.equals(searchIn.substring(i, i + startLength), theStart)) {
|
||||
return true;
|
||||
if(equals) {
|
||||
if(i + startLength == searchInLength || isSpace(searchIn.charAt(i + startLength))) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,10 +74,11 @@ public class BinaryInspector {
|
|||
// "-vmap", "-vmapobjects", // "-vmapcoordinates",
|
||||
// "-vrouting",
|
||||
"-vaddress", "-vcities","-vstreetgroups",
|
||||
"-vstreets", "-vbuildings", "-vintersections",
|
||||
"-vstreets", // "-vbuildings", "-vintersections",
|
||||
"-lang=ru",
|
||||
// "-bbox=12.8145,50.8025,12.9107,50.7365",
|
||||
// "-osm="+System.getProperty("maps.dir")+"/map.obf.osm"
|
||||
System.getProperty("maps.dir")+"/Map.obf"
|
||||
System.getProperty("maps.dir")+"/Ukraine_kiev-city_europe.obf"
|
||||
});
|
||||
} else {
|
||||
in.inspector(args);
|
||||
|
|
|
@ -555,9 +555,9 @@ public class BinaryMapAddressReaderAdapter {
|
|||
|
||||
public void searchAddressDataByName(AddressRegion reg, SearchRequest<MapObject> req, List<Integer> typeFilter) throws IOException {
|
||||
TIntArrayList loffsets = new TIntArrayList();
|
||||
CollatorStringMatcher stringMatcher = new CollatorStringMatcher(req.nameQuery, StringMatcherMode.CHECK_STARTS_FROM_SPACE);
|
||||
CollatorStringMatcher stringMatcher = new CollatorStringMatcher(req.nameQuery, req.matcherMode);
|
||||
String postcode = Postcode.normalize(req.nameQuery, map.getCountryName());
|
||||
final CityMatcher postcodeMatcher = new DefaultCityMatcher(new CollatorStringMatcher(postcode, StringMatcherMode.CHECK_STARTS_FROM_SPACE));
|
||||
final CityMatcher postcodeMatcher = new DefaultCityMatcher(new CollatorStringMatcher(postcode, req.matcherMode));
|
||||
final CityMatcher cityMatcher = new DefaultCityMatcher(stringMatcher);
|
||||
final CityMatcher cityPostcodeMatcher = new CityMatcher() {
|
||||
@Override
|
||||
|
|
|
@ -1455,10 +1455,12 @@ public class BinaryMapIndexReader {
|
|||
}
|
||||
|
||||
|
||||
public static <T> SearchRequest<T> buildAddressByNameRequest(ResultMatcher<T> resultMatcher, String nameRequest) {
|
||||
public static <T> SearchRequest<T> buildAddressByNameRequest(ResultMatcher<T> resultMatcher, String nameRequest,
|
||||
StringMatcherMode matcherMode) {
|
||||
SearchRequest<T> request = new SearchRequest<T>();
|
||||
request.resultMatcher = resultMatcher;
|
||||
request.nameQuery = nameRequest;
|
||||
request.matcherMode = matcherMode;
|
||||
return request;
|
||||
}
|
||||
|
||||
|
@ -1651,7 +1653,7 @@ public class BinaryMapIndexReader {
|
|||
|
||||
|
||||
String nameQuery = null;
|
||||
|
||||
StringMatcherMode matcherMode = StringMatcherMode.CHECK_STARTS_FROM_SPACE;
|
||||
SearchFilter searchFilter = null;
|
||||
|
||||
SearchPoiTypeFilter poiTypeFilter = null;
|
||||
|
@ -2000,8 +2002,9 @@ public class BinaryMapIndexReader {
|
|||
|
||||
private static boolean testMapSearch = false;
|
||||
private static boolean testAddressSearch = false;
|
||||
private static boolean testAddressSearchName = true;
|
||||
private static boolean testAddressJustifySearch = false;
|
||||
private static boolean testPoiSearch = true;
|
||||
private static boolean testPoiSearch = false;
|
||||
private static boolean testPoiSearchOnPath = false;
|
||||
private static boolean testTransportSearch = false;
|
||||
private static int sleft = MapUtils.get31TileNumberX(6.3);
|
||||
|
@ -2015,8 +2018,8 @@ public class BinaryMapIndexReader {
|
|||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
// File fl = new File("/Users/victorshcherb/osmand/maps/Synthetic_test_rendering.obf");
|
||||
File fl = new File("/Users/victorshcherb/osmand/maps/Netherlands_europe_2.road.obf");
|
||||
// File fl = new File(System.getProperty("maps") + /Synthetic_test_rendering.obf");
|
||||
File fl = new File(System.getProperty("maps") + "/Netherlands_noord-holland_europe_merge.obf");
|
||||
RandomAccessFile raf = new RandomAccessFile(fl, "r");
|
||||
|
||||
BinaryMapIndexReader reader = new BinaryMapIndexReader(raf, fl);
|
||||
|
@ -2026,8 +2029,10 @@ public class BinaryMapIndexReader {
|
|||
if (testMapSearch) {
|
||||
testMapSearch(reader);
|
||||
}
|
||||
if (testAddressSearch) {
|
||||
if (testAddressSearchName) {
|
||||
testAddressSearchByName(reader);
|
||||
}
|
||||
if (testAddressSearch) {
|
||||
testAddressSearch(reader);
|
||||
}
|
||||
if (testAddressJustifySearch) {
|
||||
|
@ -2299,7 +2304,7 @@ public class BinaryMapIndexReader {
|
|||
public boolean isCancelled() {
|
||||
return false;
|
||||
}
|
||||
}, "Reynaldo");
|
||||
}, "P", StringMatcherMode.CHECK_ONLY_STARTS_WITH);
|
||||
reader.searchAddressDataByName(req);
|
||||
}
|
||||
|
||||
|
@ -2334,7 +2339,7 @@ public class BinaryMapIndexReader {
|
|||
public boolean isCancelled() {
|
||||
return false;
|
||||
}
|
||||
}, streetName);
|
||||
}, streetName, StringMatcherMode.CHECK_EQUALS_FROM_SPACE);
|
||||
reader.searchAddressDataByName(req);
|
||||
TreeMap<MapObject, Street> resMap = new TreeMap<MapObject, Street>(new Comparator<MapObject>() {
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.binary;
|
|||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.ResultMatcher;
|
||||
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
||||
import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
|
||||
import net.osmand.data.Building;
|
||||
import net.osmand.data.Building.BuildingInterpolation;
|
||||
|
@ -276,7 +277,7 @@ public class GeocodingUtilities {
|
|||
public boolean isCancelled() {
|
||||
return result != null && result.isCancelled();
|
||||
}
|
||||
}, mainWord);
|
||||
}, mainWord, StringMatcherMode.CHECK_EQUALS_FROM_SPACE);// TODO search boundaries
|
||||
reader.searchAddressDataByName(req);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package net.osmand.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class City extends MapObject {
|
||||
|
@ -135,15 +137,23 @@ public class City extends MapObject {
|
|||
this.isin = isin;
|
||||
}
|
||||
|
||||
public void mergeWith(City city) {
|
||||
public Map<Street, Street> mergeWith(City city) {
|
||||
Map<Street, Street> m = new LinkedHashMap<>();
|
||||
for (Street street : city.listOfStreets) {
|
||||
if (listOfStreets.contains(street)) {
|
||||
listOfStreets.get(listOfStreets.indexOf(street)).mergeWith(street);
|
||||
} else {
|
||||
listOfStreets.add(street);
|
||||
Street s = new Street(this);
|
||||
s.copyNames(street);
|
||||
s.setLocation(street.getLocation().getLatitude(), street.getLocation().getLongitude());
|
||||
s.setId(street.getId());
|
||||
s.buildings.addAll(street.getBuildings());
|
||||
m.put(street, s);
|
||||
listOfStreets.add(s);
|
||||
}
|
||||
}
|
||||
copyNames(city);
|
||||
return m;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.util.Map;
|
|||
import java.util.TreeMap;
|
||||
|
||||
import net.osmand.Collator;
|
||||
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
||||
import net.osmand.OsmAndCollator;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.ResultMatcher;
|
||||
|
@ -171,7 +172,8 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
|
|||
// StringMatcherMode.CHECK_STARTS_FROM_SPACE_NOT_BEGINNING};
|
||||
|
||||
public synchronized List<MapObject> searchMapObjectsByName(String name, ResultMatcher<MapObject> resultMatcher, List<Integer> typeFilter) {
|
||||
SearchRequest<MapObject> req = BinaryMapIndexReader.buildAddressByNameRequest(resultMatcher, name);
|
||||
SearchRequest<MapObject> req = BinaryMapIndexReader.buildAddressByNameRequest(resultMatcher, name,
|
||||
StringMatcherMode.CHECK_STARTS_FROM_SPACE);
|
||||
try {
|
||||
log.debug("file=" + file + "; req=" + req);
|
||||
file.searchAddressDataByName(req, typeFilter);
|
||||
|
|
Loading…
Reference in a new issue