From 4727143bbe58049ffc9ed85128ea0f19be7467f4 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 18 Jun 2020 14:48:32 +0200 Subject: [PATCH] Slightly limit additional poi categoreis --- .../osmand/search/core/SearchCoreFactory.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java index 26d16e2c54..fa600cee80 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java @@ -710,7 +710,7 @@ public class SearchCoreFactory { } } - public Map getPoiTypeResults(NameStringMatcher nm, boolean includeAdditionals) { + public Map getPoiTypeResults(NameStringMatcher nm, NameStringMatcher nmAdditional) { Map results = new LinkedHashMap<>(); for (AbstractPoiType pf : topVisibleFilters) { PoiTypeResult res = checkPoiType(nm, pf); @@ -718,16 +718,16 @@ public class SearchCoreFactory { results.put(res.pt.getKeyName(), res); } } - if (includeAdditionals) { - addAditonals(nm, results, types.getOtherMapCategory()); + if (nmAdditional != null) { + addAditonals(nmAdditional, results, types.getOtherMapCategory()); } for (PoiCategory c : categories) { PoiTypeResult res = checkPoiType(nm, c); if(res != null) { results.put(res.pt.getKeyName(), res); } - if (includeAdditionals) { - addAditonals(nm, results, c); + if (nmAdditional != null) { + addAditonals(nmAdditional, results, c); } } Iterator> it = translatedNames.entrySet().iterator(); @@ -739,8 +739,8 @@ public class SearchCoreFactory { if(res != null) { results.put(res.pt.getKeyName(), res); } - if (includeAdditionals) { - addAditonals(nm, results, pt); + if (nmAdditional != null) { + addAditonals(nmAdditional, results, pt); } } } @@ -821,6 +821,7 @@ public class SearchCoreFactory { public boolean search(SearchPhrase phrase, SearchResultMatcher resultMatcher) throws IOException { boolean showTopFiltersOnly = !phrase.isUnknownSearchWordPresent(); NameStringMatcher nm = phrase.getFirstUnknownNameStringMatcher(); + initPoiTypes(); if (showTopFiltersOnly) { for (AbstractPoiType pt : topVisibleFilters) { @@ -832,7 +833,9 @@ public class SearchCoreFactory { } else { boolean includeAdditional = !phrase.hasMoreThanOneUnknownSearchWord(); - Map poiTypes = getPoiTypeResults(nm, includeAdditional); + NameStringMatcher nmAdditional = includeAdditional ? + new NameStringMatcher(phrase.getFirstUnknownSearchWord(), StringMatcherMode.CHECK_EQUALS_FROM_SPACE) : null; + Map poiTypes = getPoiTypeResults(nm, nmAdditional); for (PoiTypeResult ptr : poiTypes.values()) { boolean match = !phrase.isFirstUnknownSearchWordComplete(); if (!match) { @@ -972,8 +975,10 @@ public class SearchCoreFactory { nameFilter = phrase.getUnknownSearchPhrase(); } else if (searchAmenityTypesAPI != null && phrase.isFirstUnknownSearchWordComplete()) { NameStringMatcher nm = phrase.getFirstUnknownNameStringMatcher(); + NameStringMatcher nmAdditional = new NameStringMatcher(phrase.getFirstUnknownSearchWord(), + StringMatcherMode.CHECK_EQUALS_FROM_SPACE) ; searchAmenityTypesAPI.initPoiTypes(); - Map poiTypeResults = searchAmenityTypesAPI.getPoiTypeResults(nm, true); + Map poiTypeResults = searchAmenityTypesAPI.getPoiTypeResults(nm, nmAdditional); // find first full match only for (PoiTypeResult poiTypeResult : poiTypeResults.values()) { for (String foundName : poiTypeResult.foundWords) {