Fix inversive search
This commit is contained in:
parent
fb0e6f8b44
commit
5dbacd68a2
3 changed files with 62 additions and 7 deletions
|
@ -18,6 +18,11 @@ public class CommonWords {
|
||||||
return i == null ? -1 : i.intValue();
|
return i == null ? -1 : i.intValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getCommonSearch(String name) {
|
||||||
|
Integer i = commonWordsDictionary.get(name);
|
||||||
|
return i == null ? -1 : i.intValue();
|
||||||
|
}
|
||||||
|
|
||||||
public static int getCommonGeocoding(String name) {
|
public static int getCommonGeocoding(String name) {
|
||||||
Integer i = commonWordsDictionary.get(name);
|
Integer i = commonWordsDictionary.get(name);
|
||||||
return i == null ? -1 : i.intValue();
|
return i == null ? -1 : i.intValue();
|
||||||
|
|
|
@ -10,6 +10,7 @@ import net.osmand.binary.BinaryMapAddressReaderAdapter;
|
||||||
import net.osmand.binary.BinaryMapIndexReader;
|
import net.osmand.binary.BinaryMapIndexReader;
|
||||||
import net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter;
|
import net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter;
|
||||||
import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
|
import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
|
||||||
|
import net.osmand.binary.CommonWords;
|
||||||
import net.osmand.data.Amenity;
|
import net.osmand.data.Amenity;
|
||||||
import net.osmand.data.Building;
|
import net.osmand.data.Building;
|
||||||
import net.osmand.data.City;
|
import net.osmand.data.City;
|
||||||
|
@ -131,6 +132,9 @@ public class SearchCoreFactory {
|
||||||
phrase.countUnknownWordsMatch(res);
|
phrase.countUnknownWordsMatch(res);
|
||||||
int cnt = resultMatcher.getCount();
|
int cnt = resultMatcher.getCount();
|
||||||
List<String> ws = phrase.getUnknownSearchWords(res.otherWordsMatch);
|
List<String> ws = phrase.getUnknownSearchWords(res.otherWordsMatch);
|
||||||
|
if(!res.firstUnknownWordMatches) {
|
||||||
|
ws.add(phrase.getUnknownSearchWord());
|
||||||
|
}
|
||||||
if (!ws.isEmpty() && api != null && api.isSearchAvailable(phrase)) {
|
if (!ws.isEmpty() && api != null && api.isSearchAvailable(phrase)) {
|
||||||
SearchPhrase nphrase = phrase.selectWord(res, ws,
|
SearchPhrase nphrase = phrase.selectWord(res, ws,
|
||||||
phrase.isLastUnknownSearchWordComplete());
|
phrase.isLastUnknownSearchWordComplete());
|
||||||
|
@ -323,6 +327,8 @@ public class SearchCoreFactory {
|
||||||
final int priority = phrase.isNoSelectedType() ?
|
final int priority = phrase.isNoSelectedType() ?
|
||||||
SEARCH_ADDRESS_BY_NAME_PRIORITY : SEARCH_ADDRESS_BY_NAME_PRIORITY_RADIUS2;
|
SEARCH_ADDRESS_BY_NAME_PRIORITY : SEARCH_ADDRESS_BY_NAME_PRIORITY_RADIUS2;
|
||||||
final BinaryMapIndexReader[] currentFile = new BinaryMapIndexReader[1];
|
final BinaryMapIndexReader[] currentFile = new BinaryMapIndexReader[1];
|
||||||
|
|
||||||
|
|
||||||
ResultMatcher<MapObject> rm = new ResultMatcher<MapObject>() {
|
ResultMatcher<MapObject> rm = new ResultMatcher<MapObject>() {
|
||||||
int limit = 0;
|
int limit = 0;
|
||||||
@Override
|
@Override
|
||||||
|
@ -422,12 +428,45 @@ public class SearchCoreFactory {
|
||||||
};
|
};
|
||||||
Iterator<BinaryMapIndexReader> offlineIterator = phrase.getRadiusOfflineIndexes(DEFAULT_ADDRESS_BBOX_RADIUS * 5,
|
Iterator<BinaryMapIndexReader> offlineIterator = phrase.getRadiusOfflineIndexes(DEFAULT_ADDRESS_BBOX_RADIUS * 5,
|
||||||
SearchPhraseDataType.ADDRESS);
|
SearchPhraseDataType.ADDRESS);
|
||||||
while (offlineIterator.hasNext()) {
|
List<String> unknownSearchWords = phrase.getUnknownSearchWords();
|
||||||
|
|
||||||
|
String wordToSearch = "";
|
||||||
|
if (phrase.getUnknownSearchWordLength() > 1) {
|
||||||
|
List<String> searchWords = new ArrayList<>(unknownSearchWords);
|
||||||
|
searchWords.add(0, phrase.getUnknownSearchWord());
|
||||||
|
Collections.sort(searchWords, new Comparator<String>() {
|
||||||
|
|
||||||
|
private int lengthWithoutNumbers(String s) {
|
||||||
|
int len = 0;
|
||||||
|
for(int k = 0; k < s.length(); k++) {
|
||||||
|
if(s.charAt(k) >= '0' && s.charAt(k) <= '9') {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
len++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(String o1, String o2) {
|
||||||
|
int i1 = CommonWords.getCommonSearch(o1);
|
||||||
|
int i2 = CommonWords.getCommonSearch(o2);
|
||||||
|
if (i1 != i2) {
|
||||||
|
return icompare(i1, i2);
|
||||||
|
}
|
||||||
|
// compare length without numbers to not include house numbers
|
||||||
|
return -icompare(lengthWithoutNumbers(o1), lengthWithoutNumbers(o2));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
wordToSearch = searchWords.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (offlineIterator.hasNext() && wordToSearch.length() > 0) {
|
||||||
BinaryMapIndexReader r = offlineIterator.next();
|
BinaryMapIndexReader r = offlineIterator.next();
|
||||||
currentFile[0] = r;
|
currentFile[0] = r;
|
||||||
immediateResults.clear();
|
immediateResults.clear();
|
||||||
SearchRequest<MapObject> req = BinaryMapIndexReader.buildAddressByNameRequest(rm, phrase
|
SearchRequest<MapObject> req = BinaryMapIndexReader.buildAddressByNameRequest(rm, wordToSearch.toLowerCase(),
|
||||||
.getUnknownSearchWord().toLowerCase(),
|
|
||||||
phrase.isUnknownSearchWordComplete() ? StringMatcherMode.CHECK_EQUALS_FROM_SPACE
|
phrase.isUnknownSearchWordComplete() ? StringMatcherMode.CHECK_EQUALS_FROM_SPACE
|
||||||
: StringMatcherMode.CHECK_STARTS_FROM_SPACE);
|
: StringMatcherMode.CHECK_STARTS_FROM_SPACE);
|
||||||
if (locSpecified) {
|
if (locSpecified) {
|
||||||
|
@ -436,9 +475,11 @@ public class SearchCoreFactory {
|
||||||
}
|
}
|
||||||
r.searchAddressDataByName(req);
|
r.searchAddressDataByName(req);
|
||||||
for (SearchResult res : immediateResults) {
|
for (SearchResult res : immediateResults) {
|
||||||
|
res.firstUnknownWordMatches = wordToSearch.equals(phrase.getUnknownSearchWord());
|
||||||
if (res.objectType == ObjectType.STREET) {
|
if (res.objectType == ObjectType.STREET) {
|
||||||
City ct = ((Street) res.object).getCity();
|
City ct = ((Street) res.object).getCity();
|
||||||
phrase.countUnknownWordsMatch(res, ct.getName(phrase.getSettings().getLang(), phrase.getSettings().isTransliterate()),
|
phrase.countUnknownWordsMatch(res,
|
||||||
|
ct.getName(phrase.getSettings().getLang(), phrase.getSettings().isTransliterate()),
|
||||||
ct.getAllNames(true));
|
ct.getAllNames(true));
|
||||||
subSearchApiOrPublish(phrase, resultMatcher, res, streetsApi);
|
subSearchApiOrPublish(phrase, resultMatcher, res, streetsApi);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1406,4 +1447,8 @@ public class SearchCoreFactory {
|
||||||
return SEARCH_LOCATION_PRIORITY;
|
return SEARCH_LOCATION_PRIORITY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int icompare(int x, int y) {
|
||||||
|
return (x < y) ? -1 : ((x == y) ? 0 : 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ public class SearchResult {
|
||||||
public String wordsSpan ;
|
public String wordsSpan ;
|
||||||
public SearchResult parentSearchResult;
|
public SearchResult parentSearchResult;
|
||||||
public Collection<String> otherWordsMatch = null;
|
public Collection<String> otherWordsMatch = null;
|
||||||
|
public boolean firstUnknownWordMatches = true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,10 +28,14 @@ public class SearchResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFoundWordCount() {
|
public int getFoundWordCount() {
|
||||||
if(otherWordsMatch != null) {
|
int inc = 0;
|
||||||
return otherWordsMatch.size() + 1;
|
if(firstUnknownWordMatches) {
|
||||||
|
inc = 1;
|
||||||
}
|
}
|
||||||
return 1;
|
if(otherWordsMatch != null) {
|
||||||
|
inc += otherWordsMatch.size();
|
||||||
|
}
|
||||||
|
return inc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getSearchDistance(LatLon location) {
|
public double getSearchDistance(LatLon location) {
|
||||||
|
|
Loading…
Reference in a new issue