Optimized POI OSM Live search for Android

This commit is contained in:
PaulStets 2017-09-14 16:48:46 +03:00
parent a6828c51ad
commit 8578b16842
2 changed files with 26 additions and 12 deletions

View file

@ -404,8 +404,18 @@ public class BinaryMapIndexReader {
rg.add(file.getName());
}
String ls = rg.get(0);
// .replaceAll("[0-9]+", "").trim()
if (ls.lastIndexOf('_') != -1) {
return ls.substring(0, ls.lastIndexOf('_')).replace('_', ' ').replaceAll("[0-9]+", "").trim();
if (ls.matches("[A-Za-z-_]+")) {
return ls.substring(0, ls.lastIndexOf('_')).replace('_', ' ');
} else if (ls.matches("([a-zA-Z_-]){3}([0-9]+_*){3}[.a-z]+")) {
String[] words = ls.split("_");
return words[0] + " " + words[1];
} else if (ls.matches("([a-zA-Z_-]){2}([0-9]+_*){3}[.a-z]+")) {
String[] words = ls.split("_");
return words[0];
}
}
return ls;
}

View file

@ -565,30 +565,34 @@ public class SearchPhrase {
return rc1;
}
});
if (!diffsByRegion.isEmpty()) {
List<BinaryMapIndexReader> finalSort = new ArrayList<>();
for (int i = 0; i < indexes.size(); i++) {
BinaryMapIndexReader currFile = indexes.get(i);
if (diffsByRegion.get(currFile.getRegionName()) != null) {
finalSort.addAll(diffsByRegion.get(currFile.getRegionName()));
finalSort.add(currFile);
}
}
indexes.clear();
indexes.addAll(finalSort);
}
}
}
private Map<String, List<BinaryMapIndexReader>> getDiffsByRegion() {
Map<String, List<BinaryMapIndexReader>> result = new HashMap<>();
for (BinaryMapIndexReader r : indexes) {
if (r.getFile().getName().matches("[a-zA-Z_-]+([0-9]+_*{3}).+[a-z]+")) {
List<BinaryMapIndexReader> listCopy = new ArrayList<>(indexes);
for (BinaryMapIndexReader r : listCopy) {
if (r.getFile().getName().matches("[a-zA-Z_-]+([0-9]+_*){3}[.a-z]+")) {
String currRegionName = r.getRegionName();
if (result.containsKey(currRegionName)) {
result.get(currRegionName).add(r);
} else {
result.put(currRegionName, Arrays.asList(r));
result.put(currRegionName, new ArrayList<>(Arrays.asList(r)));
}
indexes.remove(r);
}
}
return result;
}