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