Fix search order (full match)
This commit is contained in:
parent
09512f2256
commit
ffd9c5c6cb
3 changed files with 55 additions and 2 deletions
|
@ -22,7 +22,8 @@ public class CollatorStringMatcher implements StringMatcher {
|
|||
CHECK_STARTS_FROM_SPACE_NOT_BEGINNING,
|
||||
CHECK_EQUALS_FROM_SPACE,
|
||||
CHECK_CONTAINS,
|
||||
CHECK_ONLY_STARTS_WITH_TRIM
|
||||
CHECK_ONLY_STARTS_WITH_TRIM,
|
||||
CHECK_EQUALS,
|
||||
}
|
||||
|
||||
public CollatorStringMatcher(String part, StringMatcherMode mode) {
|
||||
|
@ -55,6 +56,8 @@ public class CollatorStringMatcher implements StringMatcher {
|
|||
return cstartsWith(collator, base, part, true, false, false, false);
|
||||
case CHECK_ONLY_STARTS_WITH_TRIM:
|
||||
return cstartsWith(collator, base, part, true, false, false, true);
|
||||
case CHECK_EQUALS:
|
||||
return cstartsWith(collator, base, part, false, false, true, false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -160,6 +163,9 @@ public class CollatorStringMatcher implements StringMatcher {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!checkBeginning && !checkSpaces && equals) {
|
||||
return collator.equals(searchIn, theStart);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -317,6 +317,11 @@ public class SearchCoreFactory {
|
|||
&& phrase.isSearchTypeAllowed(ObjectType.CITY)) {
|
||||
String wrd = phrase.getUnknownWordToSearch();
|
||||
NameStringMatcher nm = phrase.getNameStringMatcher(wrd, phrase.isUnknownSearchWordComplete());
|
||||
String unknownSearchPhrase = phrase.getUnknownSearchPhrase().trim();
|
||||
NameStringMatcher phraseMatcher = null;
|
||||
if (!Algorithms.isEmpty(unknownSearchPhrase)) {
|
||||
phraseMatcher = new NameStringMatcher(unknownSearchPhrase, StringMatcherMode.CHECK_EQUALS);
|
||||
}
|
||||
// NameStringMatcher nm = phrase.getNameStringMatcher();
|
||||
resArray.clear();
|
||||
resArray = townCitiesQR.queryInBox(bbox, resArray);
|
||||
|
@ -337,6 +342,9 @@ public class SearchCoreFactory {
|
|||
resultMatcher.publish(res);
|
||||
} else if (nm.matches(res.localeName) || nm.matches(res.otherNames)) {
|
||||
res.firstUnknownWordMatches = wrd.equals(phrase.getUnknownSearchWord());
|
||||
if (phraseMatcher != null) {
|
||||
res.unknownPhraseMatches = phraseMatcher.matches(res.localeName) || phraseMatcher.matches(res.otherNames);
|
||||
}
|
||||
subSearchApiOrPublish(phrase, resultMatcher, res, cityApi);
|
||||
}
|
||||
if (limit++ > LIMIT * phrase.getRadiusLevel()) {
|
||||
|
@ -464,6 +472,11 @@ public class SearchCoreFactory {
|
|||
SearchPhraseDataType.ADDRESS);
|
||||
|
||||
String wordToSearch = phrase.getUnknownWordToSearch();
|
||||
String unknownSearchPhrase = phrase.getUnknownSearchPhrase().trim();
|
||||
NameStringMatcher phraseMatcher = null;
|
||||
if (!Algorithms.isEmpty(unknownSearchPhrase)) {
|
||||
phraseMatcher = new NameStringMatcher(unknownSearchPhrase, StringMatcherMode.CHECK_EQUALS);
|
||||
}
|
||||
while (offlineIterator.hasNext() && wordToSearch.length() > 0) {
|
||||
BinaryMapIndexReader r = offlineIterator.next();
|
||||
currentFile[0] = r;
|
||||
|
@ -478,6 +491,9 @@ public class SearchCoreFactory {
|
|||
r.searchAddressDataByName(req);
|
||||
for (SearchResult res : immediateResults) {
|
||||
res.firstUnknownWordMatches = wordToSearch.equals(phrase.getUnknownSearchWord());
|
||||
if (phraseMatcher != null) {
|
||||
res.unknownPhraseMatches = phraseMatcher.matches(res.localeName) || phraseMatcher.matches(res.otherNames);
|
||||
}
|
||||
if (res.objectType == ObjectType.STREET) {
|
||||
City ct = ((Street) res.object).getCity();
|
||||
phrase.countUnknownWordsMatch(res,
|
||||
|
@ -522,6 +538,13 @@ public class SearchCoreFactory {
|
|||
SearchPhraseDataType.POI);
|
||||
String searchWord = phrase.getUnknownWordToSearch();
|
||||
final NameStringMatcher nm = phrase.getNameStringMatcher(searchWord, phrase.isUnknownSearchWordComplete());
|
||||
String unknownSearchPhrase = phrase.getUnknownSearchPhrase().trim();
|
||||
final NameStringMatcher phraseMatcher;
|
||||
if (!Algorithms.isEmpty(unknownSearchPhrase)) {
|
||||
phraseMatcher = new NameStringMatcher(unknownSearchPhrase, StringMatcherMode.CHECK_EQUALS);
|
||||
} else {
|
||||
phraseMatcher = null;
|
||||
}
|
||||
QuadRect bbox = phrase.getRadiusBBoxToSearch(BBOX_RADIUS_INSIDE);
|
||||
final Set<String> ids = new HashSet<String>();
|
||||
SearchRequest<Amenity> req = BinaryMapIndexReader.buildSearchPoiRequest(
|
||||
|
@ -563,6 +586,9 @@ public class SearchCoreFactory {
|
|||
sr.priorityDistance = 1;
|
||||
}
|
||||
sr.priority = SEARCH_AMENITY_BY_NAME_PRIORITY;
|
||||
if (phraseMatcher != null) {
|
||||
sr.unknownPhraseMatches = phraseMatcher.matches(sr.localeName) || phraseMatcher.matches(sr.otherNames);
|
||||
}
|
||||
phrase.countUnknownWordsMatch(sr);
|
||||
sr.objectType = ObjectType.POI;
|
||||
resultMatcher.publish(sr);
|
||||
|
@ -865,6 +891,13 @@ public class SearchCoreFactory {
|
|||
private ResultMatcher<Amenity> getResultMatcher(final SearchPhrase phrase, final SearchResultMatcher resultMatcher,
|
||||
final String customName, final BinaryMapIndexReader selected,
|
||||
final Set<String> searchedPois) {
|
||||
String unknownSearchPhrase = phrase.getUnknownSearchPhrase().trim();
|
||||
final NameStringMatcher phraseMatcher;
|
||||
if (!Algorithms.isEmpty(unknownSearchPhrase)) {
|
||||
phraseMatcher = new NameStringMatcher(unknownSearchPhrase, StringMatcherMode.CHECK_EQUALS);
|
||||
} else {
|
||||
phraseMatcher = null;
|
||||
}
|
||||
final NameStringMatcher ns;
|
||||
final boolean hasCustomName = !Algorithms.isEmpty(customName);
|
||||
if (hasCustomName) {
|
||||
|
@ -905,6 +938,9 @@ public class SearchCoreFactory {
|
|||
res.location = object.getLocation();
|
||||
res.priority = SEARCH_AMENITY_BY_TYPE_PRIORITY;
|
||||
res.priorityDistance = 1;
|
||||
if (phraseMatcher != null) {
|
||||
res.unknownPhraseMatches = phraseMatcher.matches(res.localeName) || phraseMatcher.matches(res.otherNames);
|
||||
}
|
||||
res.objectType = ObjectType.POI;
|
||||
resultMatcher.publish(res);
|
||||
return false;
|
||||
|
@ -999,6 +1035,11 @@ public class SearchCoreFactory {
|
|||
String wordToSearch = phrase.getUnknownWordToSearch();
|
||||
boolean firstUnknownWordMatches = wordToSearch.equals(phrase.getUnknownSearchWord());
|
||||
NameStringMatcher nm = phrase.getNameStringMatcher(wordToSearch, phrase.isUnknownSearchWordComplete());
|
||||
String unknownSearchPhrase = phrase.getUnknownSearchPhrase().trim();
|
||||
NameStringMatcher phraseMatcher = null;
|
||||
if (!Algorithms.isEmpty(unknownSearchPhrase)) {
|
||||
phraseMatcher = new NameStringMatcher(unknownSearchPhrase, StringMatcherMode.CHECK_EQUALS);
|
||||
}
|
||||
for (Street object : c.getStreets()) {
|
||||
|
||||
SearchResult res = new SearchResult(phrase);
|
||||
|
@ -1016,6 +1057,9 @@ public class SearchCoreFactory {
|
|||
res.firstUnknownWordMatches = firstUnknownWordMatches ||
|
||||
phrase.getNameStringMatcher().matches(res.localeName) ||
|
||||
phrase.getNameStringMatcher().matches(res.otherNames);
|
||||
if (phraseMatcher != null) {
|
||||
res.unknownPhraseMatches = phraseMatcher.matches(res.localeName) || phraseMatcher.matches(res.otherNames);
|
||||
}
|
||||
res.localeRelatedObjectName = c.getName(phrase.getSettings().getLang(), phrase.getSettings().isTransliterate());
|
||||
res.object = object;
|
||||
res.preferredZoom = 17;
|
||||
|
|
|
@ -20,7 +20,7 @@ public class SearchResult {
|
|||
public SearchResult parentSearchResult;
|
||||
public Collection<String> otherWordsMatch = null;
|
||||
public boolean firstUnknownWordMatches = true;
|
||||
|
||||
public boolean unknownPhraseMatches = false;
|
||||
|
||||
|
||||
public SearchResult(SearchPhrase sp) {
|
||||
|
@ -32,6 +32,9 @@ public class SearchResult {
|
|||
if(firstUnknownWordMatches) {
|
||||
inc = 1;
|
||||
}
|
||||
if (unknownPhraseMatches) {
|
||||
inc += 1000;
|
||||
}
|
||||
if(otherWordsMatch != null) {
|
||||
inc += otherWordsMatch.size();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue