Fix search
This commit is contained in:
parent
816ed5722b
commit
8a5ff11264
1 changed files with 24 additions and 28 deletions
|
@ -2163,7 +2163,7 @@ public class BinaryMapIndexReader {
|
||||||
private static boolean testAddressJustifySearch = false;
|
private static boolean testAddressJustifySearch = false;
|
||||||
private static boolean testPoiSearch = true;
|
private static boolean testPoiSearch = true;
|
||||||
private static boolean testPoiSearchOnPath = false;
|
private static boolean testPoiSearchOnPath = false;
|
||||||
private static boolean testTransportSearch = true;
|
private static boolean testTransportSearch = false;
|
||||||
|
|
||||||
private static int sleft = MapUtils.get31TileNumberX(27.55079);
|
private static int sleft = MapUtils.get31TileNumberX(27.55079);
|
||||||
private static int sright = MapUtils.get31TileNumberX(27.55317);
|
private static int sright = MapUtils.get31TileNumberX(27.55317);
|
||||||
|
@ -2177,7 +2177,7 @@ public class BinaryMapIndexReader {
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
File fl = new File(System.getProperty("maps") + "/Synthetic_test_rendering.obf");
|
File fl = new File(System.getProperty("maps") + "/Synthetic_test_rendering.obf");
|
||||||
fl = new File("/Users/plotva/work/osmand/maps/Wikivoyage.obf");
|
fl = new File(System.getProperty("maps") +"/Wikivoyage.obf__");
|
||||||
|
|
||||||
RandomAccessFile raf = new RandomAccessFile(fl, "r");
|
RandomAccessFile raf = new RandomAccessFile(fl, "r");
|
||||||
|
|
||||||
|
@ -2385,8 +2385,10 @@ public class BinaryMapIndexReader {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void readIndexedStringTable(Collator instance, List<String> queries, String prefix, List<TIntArrayList> listOffsets, TIntArrayList charMatchesList) throws IOException {
|
void readIndexedStringTable(Collator instance, List<String> queries, String prefix, List<TIntArrayList> listOffsets, TIntArrayList matchedCharacters) throws IOException {
|
||||||
String key = null;
|
String key = null;
|
||||||
|
boolean[] matched = new boolean[matchedCharacters.size()];
|
||||||
|
boolean shouldWeReadSubtable = false;
|
||||||
while (true) {
|
while (true) {
|
||||||
int t = codedIS.readTag();
|
int t = codedIS.readTag();
|
||||||
int tag = WireFormat.getTagFieldNumber(t);
|
int tag = WireFormat.getTagFieldNumber(t);
|
||||||
|
@ -2398,41 +2400,41 @@ public class BinaryMapIndexReader {
|
||||||
if (prefix.length() > 0) {
|
if (prefix.length() > 0) {
|
||||||
key = prefix + key;
|
key = prefix + key;
|
||||||
}
|
}
|
||||||
|
shouldWeReadSubtable = false;
|
||||||
for (int i = 0; i < queries.size(); i++) {
|
for (int i = 0; i < queries.size(); i++) {
|
||||||
int charMatches = charMatchesList.get(i);
|
int charMatches = matchedCharacters.get(i);
|
||||||
if (charMatches < 0) {
|
String query = queries.get(i);
|
||||||
|
matched[i] = false;
|
||||||
|
if (query == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String query = queries.get(i);
|
|
||||||
// check query is part of key (the best matching)
|
// check query is part of key (the best matching)
|
||||||
if (CollatorStringMatcher.cmatches(instance, key, query, StringMatcherMode.CHECK_ONLY_STARTS_WITH)) {
|
if (CollatorStringMatcher.cmatches(instance, key, query, StringMatcherMode.CHECK_ONLY_STARTS_WITH)) {
|
||||||
if (query.length() >= charMatches) {
|
if (query.length() >= charMatches) {
|
||||||
if (query.length() > charMatches) {
|
if (query.length() > charMatches) {
|
||||||
charMatchesList.set(i, query.length());
|
matchedCharacters.set(i, query.length());
|
||||||
listOffsets.get(i).clear();
|
listOffsets.get(i).clear();
|
||||||
}
|
}
|
||||||
} else {
|
matched[i] = true;
|
||||||
charMatchesList.set(i, -1);
|
|
||||||
}
|
}
|
||||||
// check key is part of query
|
// check key is part of query
|
||||||
} else if (CollatorStringMatcher.cmatches(instance, query, key, StringMatcherMode.CHECK_ONLY_STARTS_WITH)) {
|
} else if (CollatorStringMatcher.cmatches(instance, query, key, StringMatcherMode.CHECK_ONLY_STARTS_WITH)) {
|
||||||
if (key.length() >= charMatches) {
|
if (key.length() >= charMatches) {
|
||||||
if (key.length() > charMatches) {
|
if (key.length() > charMatches) {
|
||||||
charMatchesList.set(i, key.length());
|
matchedCharacters.set(i, key.length());
|
||||||
listOffsets.get(i).clear();
|
listOffsets.get(i).clear();
|
||||||
}
|
}
|
||||||
} else {
|
matched[i] = true;
|
||||||
charMatchesList.set(i, -1);
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
charMatchesList.set(i, -1);
|
|
||||||
}
|
}
|
||||||
|
shouldWeReadSubtable |= matched[i];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case OsmandOdb.IndexedStringTable.VAL_FIELD_NUMBER :
|
case OsmandOdb.IndexedStringTable.VAL_FIELD_NUMBER :
|
||||||
int val = readInt();
|
int val = readInt();
|
||||||
for (int i = 0; i < queries.size(); i++) {
|
for (int i = 0; i < queries.size(); i++) {
|
||||||
if (charMatchesList.get(i) >= 0) {
|
if (matched[i]) {
|
||||||
listOffsets.get(i).add(val);
|
listOffsets.get(i).add(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2440,21 +2442,15 @@ public class BinaryMapIndexReader {
|
||||||
case OsmandOdb.IndexedStringTable.SUBTABLES_FIELD_NUMBER :
|
case OsmandOdb.IndexedStringTable.SUBTABLES_FIELD_NUMBER :
|
||||||
int len = codedIS.readRawVarint32();
|
int len = codedIS.readRawVarint32();
|
||||||
int oldLim = codedIS.pushLimit(len);
|
int oldLim = codedIS.pushLimit(len);
|
||||||
boolean shouldWeReadSubtable = false;
|
|
||||||
for (int i = 0; i < queries.size(); i++) {
|
|
||||||
if (charMatchesList.get(i) >= 0) {
|
|
||||||
shouldWeReadSubtable = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (shouldWeReadSubtable && key != null) {
|
if (shouldWeReadSubtable && key != null) {
|
||||||
TIntArrayList subcharMatchesList = new TIntArrayList(charMatchesList);
|
List<String> subqueries = new ArrayList<>(queries);
|
||||||
readIndexedStringTable(instance, queries, key, listOffsets, subcharMatchesList);
|
// reset query so we don't search what was not matched
|
||||||
// looks like true
|
for(int i = 0; i < queries.size(); i++) {
|
||||||
for (int i = 0; i < queries.size(); i++) {
|
if(!matched[i]) {
|
||||||
if (subcharMatchesList.get(i) >= charMatchesList.get(i)) {
|
subqueries.set(i, null);
|
||||||
charMatchesList.set(i, subcharMatchesList.get(i));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
readIndexedStringTable(instance, subqueries, key, listOffsets, matchedCharacters);
|
||||||
} else {
|
} else {
|
||||||
codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
|
codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue