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()); rg.add(file.getName());
} }
String ls = rg.get(0); String ls = rg.get(0);
// .replaceAll("[0-9]+", "").trim()
if (ls.lastIndexOf('_') != -1) { 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; return ls;
} }

View file

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