added check for fearch phrase and refactored some code

This commit is contained in:
Chumva 2018-03-21 13:55:20 +02:00
parent c4bf936b60
commit 61cddf0316
3 changed files with 24 additions and 20 deletions

View file

@ -611,20 +611,21 @@ public class SearchCoreFactory {
categories = types.getCategories(false);
}
// results.clear();
List<AbstractPoiType> results = new ArrayList<AbstractPoiType>() ;
List<AbstractPoiType> results = new ArrayList<AbstractPoiType>();
NameStringMatcher nm = phrase.getNameStringMatcher();
for (PoiFilter pf : topVisibleFilters) {
if (!phrase.isUnknownSearchWordPresent() ||
nm.matches(pf.getTranslation()) || nm.matches(pf.getEnTranslation()) ||
nm.matches(pf.getSynonyms())) {
if (!phrase.isUnknownSearchWordPresent()
|| nm.matches(pf.getTranslation())
|| nm.matches(pf.getEnTranslation())
|| nm.matches(pf.getSynonyms())) {
results.add(pf);
}
}
if (phrase.isUnknownSearchWordPresent()) {
for (PoiCategory c : categories) {
if (!results.contains(c) &&
(nm.matches(c.getTranslation()) || nm.matches(c.getEnTranslation())
|| nm.matches(c.getSynonyms())) ) {
if (!results.contains(c) && (nm.matches(c.getTranslation())
|| nm.matches(c.getEnTranslation())
|| nm.matches(c.getSynonyms()))) {
results.add(c);
}
}
@ -634,16 +635,18 @@ public class SearchCoreFactory {
PoiType pt = e.getValue();
if (pt.getCategory() != types.getOtherMapCategory()) {
if (!results.contains(pt) && (
nm.matches(pt.getEnTranslation()) || nm.matches(pt.getTranslation())
|| nm.matches(pt.getSynonyms()) )) {
nm.matches(pt.getEnTranslation())
|| nm.matches(pt.getTranslation())
|| nm.matches(pt.getSynonyms()))) {
results.add(pt);
}
List<PoiType> additionals = pt.getPoiAdditionals();
if (additionals != null) {
for (PoiType a : additionals) {
if (!a.isReference() && !results.contains(a) &&
( nm.matches(a.getEnTranslation()) || nm.matches(a.getTranslation())
|| nm.matches(a.getSynonyms()) )) {
(nm.matches(a.getEnTranslation())
|| nm.matches(a.getTranslation())
|| nm.matches(a.getSynonyms()))) {
results.add(a);
}
}

View file

@ -336,8 +336,9 @@ public class AppInitializer implements IProgress {
@Override
public String getTranslation(AbstractPoiType type) {
if (type.getBaseLangType() != null) {
return getTranslation(type.getBaseLangType()) + " (" + app.getLangTranslation(type.getLang()).toLowerCase() + ")";
AbstractPoiType baseLangType = type.getBaseLangType();
if (baseLangType != null) {
return getTranslation(baseLangType) + " (" + app.getLangTranslation(type.getLang()).toLowerCase() + ")";
}
return getTranslation(type.getIconKeyName());
}
@ -358,8 +359,9 @@ public class AppInitializer implements IProgress {
@Override
public String getSynonyms(AbstractPoiType type) {
if (type.getBaseLangType() != null) {
return getSynonyms(type.getBaseLangType());
AbstractPoiType baseLangType = type.getBaseLangType();
if (baseLangType != null) {
return getSynonyms(baseLangType);
}
return getSynonyms(type.getIconKeyName());
}
@ -373,15 +375,15 @@ public class AppInitializer implements IProgress {
return app.getString(in);
}
} catch (Exception e) {
LOG.debug("No translation for " + keyName + " " + e.getMessage());
}
return "";
}
@Override
public String getEnTranslation(AbstractPoiType type) {
if (type.getBaseLangType() != null) {
return getEnTranslation(type.getBaseLangType()) + " (" + app.getLangTranslation(type.getLang()).toLowerCase() + ")";
AbstractPoiType baseLangType = type.getBaseLangType();
if (baseLangType != null) {
return getEnTranslation(baseLangType) + " (" + app.getLangTranslation(type.getLang()).toLowerCase() + ")";
}
return getEnTranslation(type.getIconKeyName());
}
@ -399,7 +401,6 @@ public class AppInitializer implements IProgress {
return en.getString(in);
}
} catch (Exception e) {
LOG.debug("No translation for " + keyName + " " + e.getMessage());
}
return null;
}

View file

@ -376,7 +376,7 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
SearchPhrase.NameStringMatcher nm = new SearchPhrase.NameStringMatcher(searchPhrase,
CollatorStringMatcher.StringMatcherMode.CHECK_STARTS_FROM_SPACE);
if (!nm.matches(abstractPoiType.getTranslation())) {
if (!searchPhrase.isEmpty() && !nm.matches(abstractPoiType.getTranslation())) {
if (nm.matches(abstractPoiType.getEnTranslation())) {
desc = listItem.getTypeName() + " (" + abstractPoiType.getEnTranslation() + ")";
} else {