Update search core phrase
This commit is contained in:
parent
183b4bc98f
commit
d85405b98f
2 changed files with 30 additions and 21 deletions
|
@ -96,9 +96,6 @@ public class SearchCoreFactory {
|
|||
return p.isLastWord(ObjectType.POI);
|
||||
}
|
||||
|
||||
public boolean isLastWordRegion(SearchPhrase p) {
|
||||
return p.isLastWord(ObjectType.REGION);
|
||||
}
|
||||
|
||||
public boolean isNoSelectedType(SearchPhrase p) {
|
||||
return p.isNoSelectedType();
|
||||
|
@ -113,8 +110,9 @@ public class SearchCoreFactory {
|
|||
return false;
|
||||
}
|
||||
// (search streets in neighboor cities for radiusLevel > 2)
|
||||
if (isLastWordPoi(phrase) || isNoSelectedType(phrase) ||
|
||||
isLastWordRegion(phrase) || phrase.getRadiusLevel() >= 2) {
|
||||
if (isLastWordPoi(phrase) || isNoSelectedType(phrase) ||
|
||||
phrase.isLastWord(ObjectType.CITY, ObjectType.VILLAGE, ObjectType.POSTCODE) ||
|
||||
phrase.isLastWord(ObjectType.REGION) || phrase.getRadiusLevel() >= 2) {
|
||||
int letters = phrase.getLastWord().length() / 3 + 1;
|
||||
final boolean locSpecified = false; // phrase.getLastTokenLocation() != null;
|
||||
LatLon loc = phrase.getLastTokenLocation();
|
||||
|
|
|
@ -13,7 +13,6 @@ import net.osmand.data.LatLon;
|
|||
public class SearchPhrase {
|
||||
|
||||
private List<SearchWord> words = new ArrayList<>();
|
||||
private String text = "";
|
||||
private String lastWord = "";
|
||||
private CollatorStringMatcher sm;
|
||||
private SearchSettings settings;
|
||||
|
@ -50,7 +49,7 @@ public class SearchPhrase {
|
|||
sp.words.add(sw);
|
||||
// sp.text = this.text + sw.getWord() + ", ";
|
||||
// TODO FIX
|
||||
sp.text = this.text + " " + sw.getWord() + ", ";
|
||||
// sp.text = this.text + " " + sw.getWord() + ", ";
|
||||
return sp;
|
||||
}
|
||||
|
||||
|
@ -66,18 +65,25 @@ public class SearchPhrase {
|
|||
return w;
|
||||
}
|
||||
|
||||
public boolean isLastWord(ObjectType p) {
|
||||
|
||||
|
||||
public boolean isLastWord(ObjectType... p) {
|
||||
for (int i = words.size() - 1; i >= 0; i--) {
|
||||
SearchWord sw = words.get(i);
|
||||
if (sw.getType() == p) {
|
||||
return true;
|
||||
} else if (sw.getType() != ObjectType.UNKNOWN_NAME_FILTER) {
|
||||
for(ObjectType o : p) {
|
||||
if (sw.getType() == o) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (sw.getType() != ObjectType.UNKNOWN_NAME_FILTER) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public StringMatcher getNameStringMatcher() {
|
||||
if(sm != null) {
|
||||
return sm;
|
||||
|
@ -99,8 +105,15 @@ public class SearchPhrase {
|
|||
return false;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
public String getText(boolean includeLastWord) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(SearchWord s : words) {
|
||||
sb.append(s.getWord()).append(", ");
|
||||
}
|
||||
if(includeLastWord) {
|
||||
sb.append(lastWord);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getStringRerpresentation() {
|
||||
|
@ -146,14 +159,12 @@ public class SearchPhrase {
|
|||
SearchPhrase sp = new SearchPhrase(settings);
|
||||
String atext = text;
|
||||
List<SearchWord> leftWords = this.words;
|
||||
if (text.startsWith((this.text + this.lastWord).trim())) {
|
||||
String thisTxt = getText(true);
|
||||
if (text.startsWith(thisTxt)) {
|
||||
// string is longer
|
||||
atext = text.substring(this.text.length());
|
||||
sp.text = this.text;
|
||||
atext = text.substring(getText(false).length());
|
||||
sp.words = new ArrayList<>(this.words);
|
||||
leftWords = leftWords.subList(leftWords.size(), leftWords.size());
|
||||
} else {
|
||||
sp.text = "";
|
||||
}
|
||||
if (!atext.contains(",")) {
|
||||
sp.lastWord = atext;
|
||||
|
@ -172,12 +183,12 @@ public class SearchPhrase {
|
|||
if(unknown) {
|
||||
sp.words.add(new SearchWord(ws[i].trim()));
|
||||
}
|
||||
sp.text += ws[i] + ", ";
|
||||
// sp.text += ws[i] + ", ";
|
||||
}
|
||||
|
||||
}
|
||||
sp.lastWord = ws[ws.length - 1];
|
||||
}
|
||||
sp.text = sp.text.trim();
|
||||
//sp.text = sp.text.trim();
|
||||
return sp;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue