Fix merge indexes

This commit is contained in:
Victor Shcherb 2016-06-21 01:24:25 +02:00
parent c569dba3c1
commit 5578226647
7 changed files with 56 additions and 22 deletions

View file

@ -20,6 +20,7 @@ public class CollatorStringMatcher implements StringMatcher {
CHECK_ONLY_STARTS_WITH, CHECK_ONLY_STARTS_WITH,
CHECK_STARTS_FROM_SPACE, CHECK_STARTS_FROM_SPACE,
CHECK_STARTS_FROM_SPACE_NOT_BEGINNING, CHECK_STARTS_FROM_SPACE_NOT_BEGINNING,
CHECK_EQUALS_FROM_SPACE,
CHECK_CONTAINS CHECK_CONTAINS
} }
@ -43,12 +44,14 @@ public class CollatorStringMatcher implements StringMatcher {
switch (mode) { switch (mode) {
case CHECK_CONTAINS: case CHECK_CONTAINS:
return ccontains(collator, base, part); return ccontains(collator, base, part);
case CHECK_EQUALS_FROM_SPACE:
return cstartsWith(collator, base, part, true, true, true);
case CHECK_STARTS_FROM_SPACE: 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: 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: case CHECK_ONLY_STARTS_WITH:
return cstartsWith(collator, base, part, true, false); return cstartsWith(collator, base, part, true, false, false);
} }
return false; return false;
} }
@ -97,7 +100,7 @@ public class CollatorStringMatcher implements StringMatcher {
* @return true if searchIn starts with token * @return true if searchIn starts with token
*/ */
public static boolean cstartsWith(Collator collator, String searchInParam, String theStart, 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()); String searchIn = searchInParam.toLowerCase(Locale.getDefault());
int startLength = theStart.length(); int startLength = theStart.length();
int searchInLength = searchIn.length(); int searchInLength = searchIn.length();
@ -111,14 +114,26 @@ public class CollatorStringMatcher implements StringMatcher {
if (checkBeginning) { if (checkBeginning) {
boolean starts = collator.equals(searchIn.substring(0, startLength), theStart); boolean starts = collator.equals(searchIn.substring(0, startLength), theStart);
if (starts) { if (starts) {
return true; if (equals) {
if (startLength == searchInLength || isSpace(searchIn.charAt(startLength))) {
return true;
}
} else {
return true;
}
} }
} }
if (checkSpaces) { if (checkSpaces) {
for (int i = 1; i <= searchInLength - startLength; i++) { for (int i = 1; i <= searchInLength - startLength; i++) {
if (isSpace(searchIn.charAt(i - 1)) && !isSpace(searchIn.charAt(i))) { if (isSpace(searchIn.charAt(i - 1)) && !isSpace(searchIn.charAt(i))) {
if (collator.equals(searchIn.substring(i, i + startLength), theStart)) { 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;
}
} }
} }
} }

View file

@ -74,10 +74,11 @@ public class BinaryInspector {
// "-vmap", "-vmapobjects", // "-vmapcoordinates", // "-vmap", "-vmapobjects", // "-vmapcoordinates",
// "-vrouting", // "-vrouting",
"-vaddress", "-vcities","-vstreetgroups", "-vaddress", "-vcities","-vstreetgroups",
"-vstreets", "-vbuildings", "-vintersections", "-vstreets", // "-vbuildings", "-vintersections",
"-lang=ru",
// "-bbox=12.8145,50.8025,12.9107,50.7365", // "-bbox=12.8145,50.8025,12.9107,50.7365",
// "-osm="+System.getProperty("maps.dir")+"/map.obf.osm" // "-osm="+System.getProperty("maps.dir")+"/map.obf.osm"
System.getProperty("maps.dir")+"/Map.obf" System.getProperty("maps.dir")+"/Ukraine_kiev-city_europe.obf"
}); });
} else { } else {
in.inspector(args); in.inspector(args);

View file

@ -555,9 +555,9 @@ public class BinaryMapAddressReaderAdapter {
public void searchAddressDataByName(AddressRegion reg, SearchRequest<MapObject> req, List<Integer> typeFilter) throws IOException { public void searchAddressDataByName(AddressRegion reg, SearchRequest<MapObject> req, List<Integer> typeFilter) throws IOException {
TIntArrayList loffsets = new TIntArrayList(); 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()); 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 cityMatcher = new DefaultCityMatcher(stringMatcher);
final CityMatcher cityPostcodeMatcher = new CityMatcher() { final CityMatcher cityPostcodeMatcher = new CityMatcher() {
@Override @Override

View file

@ -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>(); SearchRequest<T> request = new SearchRequest<T>();
request.resultMatcher = resultMatcher; request.resultMatcher = resultMatcher;
request.nameQuery = nameRequest; request.nameQuery = nameRequest;
request.matcherMode = matcherMode;
return request; return request;
} }
@ -1651,7 +1653,7 @@ public class BinaryMapIndexReader {
String nameQuery = null; String nameQuery = null;
StringMatcherMode matcherMode = StringMatcherMode.CHECK_STARTS_FROM_SPACE;
SearchFilter searchFilter = null; SearchFilter searchFilter = null;
SearchPoiTypeFilter poiTypeFilter = null; SearchPoiTypeFilter poiTypeFilter = null;
@ -2000,8 +2002,9 @@ public class BinaryMapIndexReader {
private static boolean testMapSearch = false; private static boolean testMapSearch = false;
private static boolean testAddressSearch = false; private static boolean testAddressSearch = false;
private static boolean testAddressSearchName = true;
private static boolean testAddressJustifySearch = false; private static boolean testAddressJustifySearch = false;
private static boolean testPoiSearch = true; private static boolean testPoiSearch = false;
private static boolean testPoiSearchOnPath = false; private static boolean testPoiSearchOnPath = false;
private static boolean testTransportSearch = false; private static boolean testTransportSearch = false;
private static int sleft = MapUtils.get31TileNumberX(6.3); private static int sleft = MapUtils.get31TileNumberX(6.3);
@ -2015,8 +2018,8 @@ public class BinaryMapIndexReader {
} }
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
// File fl = new File("/Users/victorshcherb/osmand/maps/Synthetic_test_rendering.obf"); // File fl = new File(System.getProperty("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") + "/Netherlands_noord-holland_europe_merge.obf");
RandomAccessFile raf = new RandomAccessFile(fl, "r"); RandomAccessFile raf = new RandomAccessFile(fl, "r");
BinaryMapIndexReader reader = new BinaryMapIndexReader(raf, fl); BinaryMapIndexReader reader = new BinaryMapIndexReader(raf, fl);
@ -2026,8 +2029,10 @@ public class BinaryMapIndexReader {
if (testMapSearch) { if (testMapSearch) {
testMapSearch(reader); testMapSearch(reader);
} }
if (testAddressSearch) { if (testAddressSearchName) {
testAddressSearchByName(reader); testAddressSearchByName(reader);
}
if (testAddressSearch) {
testAddressSearch(reader); testAddressSearch(reader);
} }
if (testAddressJustifySearch) { if (testAddressJustifySearch) {
@ -2299,7 +2304,7 @@ public class BinaryMapIndexReader {
public boolean isCancelled() { public boolean isCancelled() {
return false; return false;
} }
}, "Reynaldo"); }, "P", StringMatcherMode.CHECK_ONLY_STARTS_WITH);
reader.searchAddressDataByName(req); reader.searchAddressDataByName(req);
} }
@ -2334,7 +2339,7 @@ public class BinaryMapIndexReader {
public boolean isCancelled() { public boolean isCancelled() {
return false; return false;
} }
}, streetName); }, streetName, StringMatcherMode.CHECK_EQUALS_FROM_SPACE);
reader.searchAddressDataByName(req); reader.searchAddressDataByName(req);
TreeMap<MapObject, Street> resMap = new TreeMap<MapObject, Street>(new Comparator<MapObject>() { TreeMap<MapObject, Street> resMap = new TreeMap<MapObject, Street>(new Comparator<MapObject>() {

View file

@ -2,6 +2,7 @@ package net.osmand.binary;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
import net.osmand.CollatorStringMatcher.StringMatcherMode;
import net.osmand.binary.BinaryMapIndexReader.SearchRequest; import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
import net.osmand.data.Building; import net.osmand.data.Building;
import net.osmand.data.Building.BuildingInterpolation; import net.osmand.data.Building.BuildingInterpolation;
@ -276,7 +277,7 @@ public class GeocodingUtilities {
public boolean isCancelled() { public boolean isCancelled() {
return result != null && result.isCancelled(); return result != null && result.isCancelled();
} }
}, mainWord); }, mainWord, StringMatcherMode.CHECK_EQUALS_FROM_SPACE);// TODO search boundaries
reader.searchAddressDataByName(req); reader.searchAddressDataByName(req);
} }

View file

@ -1,7 +1,9 @@
package net.osmand.data; package net.osmand.data;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map;
public class City extends MapObject { public class City extends MapObject {
@ -135,15 +137,23 @@ public class City extends MapObject {
this.isin = isin; 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) { for (Street street : city.listOfStreets) {
if (listOfStreets.contains(street)) { if (listOfStreets.contains(street)) {
listOfStreets.get(listOfStreets.indexOf(street)).mergeWith(street); listOfStreets.get(listOfStreets.indexOf(street)).mergeWith(street);
} else { } 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); copyNames(city);
return m;
} }
} }

View file

@ -11,6 +11,7 @@ import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import net.osmand.Collator; import net.osmand.Collator;
import net.osmand.CollatorStringMatcher.StringMatcherMode;
import net.osmand.OsmAndCollator; import net.osmand.OsmAndCollator;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
@ -171,7 +172,8 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
// StringMatcherMode.CHECK_STARTS_FROM_SPACE_NOT_BEGINNING}; // StringMatcherMode.CHECK_STARTS_FROM_SPACE_NOT_BEGINNING};
public synchronized List<MapObject> searchMapObjectsByName(String name, ResultMatcher<MapObject> resultMatcher, List<Integer> typeFilter) { 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 { try {
log.debug("file=" + file + "; req=" + req); log.debug("file=" + file + "; req=" + req);
file.searchAddressDataByName(req, typeFilter); file.searchAddressDataByName(req, typeFilter);