diff --git a/OsmAnd-java/src/net/osmand/osm/AbstractPoiType.java b/OsmAnd-java/src/net/osmand/osm/AbstractPoiType.java index 77988f04ae..5a8d801d25 100644 --- a/OsmAnd-java/src/net/osmand/osm/AbstractPoiType.java +++ b/OsmAnd-java/src/net/osmand/osm/AbstractPoiType.java @@ -17,7 +17,10 @@ public abstract class AbstractPoiType { private AbstractPoiType baseLangType; private boolean notEditableOsm; private String poiAdditionalCategory; - private List excludedPoiAdditionalCategoies; + private List excludedPoiAdditionalCategories; + private String synonyms; + private String enTranslation; + private String translation; public AbstractPoiType(String keyName, MapPoiTypes registry) { this.keyName = keyName; @@ -66,12 +69,24 @@ public abstract class AbstractPoiType { public String getTranslation() { - return registry.getTranslation(this); + if(translation == null) { + translation = registry.getTranslation(this); + } + return translation; } + public String getSynonyms() { + if(synonyms == null) { + synonyms = registry.getSynonyms(this); + } + return synonyms; + } public String getEnTranslation() { - return registry.getEnTranslation(this); + if(enTranslation == null) { + enTranslation = registry.getEnTranslation(this); + } + return enTranslation; } public String getPoiAdditionalCategoryTranslation() { @@ -137,14 +152,14 @@ public abstract class AbstractPoiType { } public List getExcludedPoiAdditionalCategories() { - return excludedPoiAdditionalCategoies; + return excludedPoiAdditionalCategories; } public void addExcludedPoiAdditionalCategories(String[] excludedPoiAdditionalCategories) { - if (excludedPoiAdditionalCategoies == null) { - excludedPoiAdditionalCategoies = new ArrayList<>(); + if (this.excludedPoiAdditionalCategories == null) { + this.excludedPoiAdditionalCategories = new ArrayList<>(); } - Collections.addAll(excludedPoiAdditionalCategoies, excludedPoiAdditionalCategories); + Collections.addAll(this.excludedPoiAdditionalCategories, excludedPoiAdditionalCategories); } public abstract Map> putTypes(Map> acceptedTypes); diff --git a/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java index d82b6ae350..2ad32c681f 100644 --- a/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java @@ -55,8 +55,11 @@ public class MapPoiTypes { String getTranslation(String keyName); String getEnTranslation(AbstractPoiType type); - String getEnTranslation(String keyName); + + String getSynonyms(AbstractPoiType type); + String getSynonyms(String keyName); + } public static MapPoiTypes getDefaultNoInit() { @@ -699,6 +702,16 @@ public class MapPoiTypes { } + public String getSynonyms(AbstractPoiType abstractPoiType) { + if (poiTranslator != null) { + String translation = poiTranslator.getSynonyms(abstractPoiType); + if (!Algorithms.isEmpty(translation)) { + return translation; + } + } + return ""; + } + public String getEnTranslation(AbstractPoiType abstractPoiType) { if (poiTranslator != null) { String translation = poiTranslator.getEnTranslation(abstractPoiType); diff --git a/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java b/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java index 6d8d227193..45fa55f09c 100644 --- a/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java +++ b/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java @@ -1,6 +1,5 @@ package net.osmand.search.core; -import com.google.openlocationcode.OpenLocationCode; import com.jwetherell.openmap.common.LatLonPoint; import com.jwetherell.openmap.common.UTMPoint; @@ -50,7 +49,6 @@ import java.util.Set; import java.util.TreeSet; import gnu.trove.list.array.TIntArrayList; -import gnu.trove.set.hash.TLongHashSet; public class SearchCoreFactory { @@ -613,16 +611,22 @@ public class SearchCoreFactory { categories = types.getCategories(false); } // results.clear(); - List results = new ArrayList() ; + List results = new ArrayList(); NameStringMatcher nm = phrase.getNameStringMatcher(); for (PoiFilter pf : topVisibleFilters) { - if (!phrase.isUnknownSearchWordPresent() || nm.matches(pf.getTranslation()) || nm.matches(pf.getEnTranslation())) { + 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()) ) ) { + if (!results.contains(c) + && (nm.matches(c.getTranslation()) + || nm.matches(c.getEnTranslation()) + || nm.matches(c.getSynonyms()))) { results.add(c); } } @@ -631,14 +635,19 @@ public class SearchCoreFactory { Entry e = it.next(); PoiType pt = e.getValue(); if (pt.getCategory() != types.getOtherMapCategory()) { - if (!results.contains(pt) && ( nm.matches(pt.getEnTranslation()) || nm.matches(pt.getTranslation()) )) { + if (!results.contains(pt) + && (nm.matches(pt.getEnTranslation()) + || nm.matches(pt.getTranslation()) + || nm.matches(pt.getSynonyms()))) { results.add(pt); } List additionals = pt.getPoiAdditionals(); if (additionals != null) { for (PoiType a : additionals) { - if (!a.isReference() && !results.contains(a) && - ( nm.matches(a.getEnTranslation()) || nm.matches(a.getTranslation()) )) { + if (!a.isReference() && !results.contains(a) + && (nm.matches(a.getEnTranslation()) + || nm.matches(a.getTranslation()) + || nm.matches(a.getSynonyms()))) { results.add(a); } } diff --git a/OsmAnd/res/values-ru/phrases.xml b/OsmAnd/res/values-ru/phrases.xml index dc6b8b4978..5ec2e8ed12 100644 --- a/OsmAnd/res/values-ru/phrases.xml +++ b/OsmAnd/res/values-ru/phrases.xml @@ -549,6 +549,7 @@ Цирк Танцплощадка Ночной клуб + Диско Стрипклуб Пляжный комплекс Площадка для выгула собак diff --git a/OsmAnd/res/values/phrases.xml b/OsmAnd/res/values/phrases.xml index aec47feef4..5d57032a39 100644 --- a/OsmAnd/res/values/phrases.xml +++ b/OsmAnd/res/values/phrases.xml @@ -919,6 +919,7 @@ Art gallery Dance floor Nightclub + Disco;Disko Stripclub Ski resort Beach resort diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index 3cfba9db6f..d591287c2f 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -334,11 +334,11 @@ public class AppInitializer implements IProgress { app.poiTypes.setPoiTranslator(new MapPoiTypes.PoiTranslator() { - @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()); } @@ -352,23 +352,45 @@ public class AppInitializer implements IProgress { return app.getString(in); } } catch (Exception e) { - LOG.debug("No translation for "+ keyName + " " + e.getMessage()); } return null; } @Override - public String getEnTranslation(AbstractPoiType type) { - if(type.getBaseLangType() != null) { - return getEnTranslation(type.getBaseLangType()) + " (" + app.getLangTranslation(type.getLang()).toLowerCase() +")"; + public String getSynonyms(AbstractPoiType type) { + AbstractPoiType baseLangType = type.getBaseLangType(); + if (baseLangType != null) { + return getSynonyms(baseLangType); } - return getEnTranslation(type.getIconKeyName()); + return getSynonyms(type.getIconKeyName()); } + @Override + public String getSynonyms(String keyName) { + try { + Field f = R.string.class.getField("synonyms_poi_" + keyName); + if (f != null) { + Integer in = (Integer) f.get(null); + return app.getString(in); + } + } catch (Exception e) { + } + return ""; + } + + @Override + public String getEnTranslation(AbstractPoiType type) { + AbstractPoiType baseLangType = type.getBaseLangType(); + if (baseLangType != null) { + return getEnTranslation(baseLangType) + " (" + app.getLangTranslation(type.getLang()).toLowerCase() + ")"; + } + return getEnTranslation(type.getIconKeyName()); + } + @Override public String getEnTranslation(String keyName) { - if(en == null) { + if (en == null) { return Algorithms.capitalizeFirstLetter( keyName.replace('_', ' ')); } @@ -379,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; } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java index 4b211dbde1..d45bd85081 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java @@ -15,10 +15,12 @@ import android.widget.LinearLayout; import android.widget.TextView; import net.osmand.AndroidUtils; +import net.osmand.CollatorStringMatcher; import net.osmand.Location; import net.osmand.access.AccessibilityAssistant; import net.osmand.data.Amenity; import net.osmand.data.LatLon; +import net.osmand.osm.AbstractPoiType; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.dashboard.DashLocationFragment; @@ -27,6 +29,7 @@ import net.osmand.plus.search.listitems.QuickSearchListItem; import net.osmand.plus.search.listitems.QuickSearchListItemType; import net.osmand.plus.search.listitems.QuickSearchMoreListItem; import net.osmand.plus.search.listitems.QuickSearchSelectAllListItem; +import net.osmand.search.SearchUICore; import net.osmand.search.core.SearchPhrase; import net.osmand.util.Algorithms; import net.osmand.util.OpeningHoursParser; @@ -360,6 +363,30 @@ public class QuickSearchListAdapter extends ArrayAdapter { } String desc = listItem.getTypeName(); + Object searchResultObject = listItem.getSearchResult().object; + if (searchResultObject instanceof AbstractPoiType) { + AbstractPoiType abstractPoiType = (AbstractPoiType) searchResultObject; + String synonyms[] = abstractPoiType.getSynonyms().split(";"); + QuickSearchHelper searchHelper = app.getSearchUICore(); + SearchUICore searchUICore = searchHelper.getCore(); + String searchPhrase = searchUICore.getPhrase().getText(true); + SearchPhrase.NameStringMatcher nm = new SearchPhrase.NameStringMatcher(searchPhrase, + CollatorStringMatcher.StringMatcherMode.CHECK_STARTS_FROM_SPACE); + + if (!searchPhrase.isEmpty() && !nm.matches(abstractPoiType.getTranslation())) { + if (nm.matches(abstractPoiType.getEnTranslation())) { + desc = listItem.getTypeName() + " (" + abstractPoiType.getEnTranslation() + ")"; + } else { + for (String syn : synonyms) { + if (nm.matches(syn)) { + desc = listItem.getTypeName() + " (" + syn + ")"; + break; + } + } + } + } + } + boolean hasDesc = false; if (!Algorithms.isEmpty(desc) && !desc.equals(name)) { subtitle.setText(desc);