From a2bd1d4e3f06c8302ccabc24f6b5c28a4f6acebc Mon Sep 17 00:00:00 2001 From: crimean Date: Wed, 3 Oct 2018 14:56:18 +0300 Subject: [PATCH] Fix #5990 --- .../net/osmand/CollatorStringMatcher.java | 23 ++++++++++++------- .../osmand/search/core/SearchCoreFactory.java | 5 ++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/CollatorStringMatcher.java b/OsmAnd-java/src/main/java/net/osmand/CollatorStringMatcher.java index eac6e598c9..27390f3760 100644 --- a/OsmAnd-java/src/main/java/net/osmand/CollatorStringMatcher.java +++ b/OsmAnd-java/src/main/java/net/osmand/CollatorStringMatcher.java @@ -21,7 +21,8 @@ public class CollatorStringMatcher implements StringMatcher { CHECK_STARTS_FROM_SPACE, CHECK_STARTS_FROM_SPACE_NOT_BEGINNING, CHECK_EQUALS_FROM_SPACE, - CHECK_CONTAINS + CHECK_CONTAINS, + CHECK_ONLY_STARTS_WITH_TRIM } public CollatorStringMatcher(String part, StringMatcherMode mode) { @@ -45,13 +46,15 @@ public class CollatorStringMatcher implements StringMatcher { case CHECK_CONTAINS: return ccontains(collator, base, part); case CHECK_EQUALS_FROM_SPACE: - return cstartsWith(collator, base, part, true, true, true); + return cstartsWith(collator, base, part, true, true, true, false); case CHECK_STARTS_FROM_SPACE: - return cstartsWith(collator, base, part, true, true, false); + return cstartsWith(collator, base, part, true, true, false, false); case CHECK_STARTS_FROM_SPACE_NOT_BEGINNING: - return cstartsWith(collator, base, part, false, true, false); + return cstartsWith(collator, base, part, false, true, false, false); case CHECK_ONLY_STARTS_WITH: - return cstartsWith(collator, base, part, true, false, false); + return cstartsWith(collator, base, part, true, false, false, false); + case CHECK_ONLY_STARTS_WITH_TRIM: + return cstartsWith(collator, base, part, true, false, false, true); } return false; } @@ -110,15 +113,19 @@ public class CollatorStringMatcher implements StringMatcher { * Special check try to find as well in the middle of name * * @param collator - * @param searchIn + * @param searchInParam * @param theStart + * @param trim - trim theStart to searchInParam length if searchInParam non empty * @return true if searchIn starts with token */ public static boolean cstartsWith(Collator collator, String searchInParam, String theStart, - boolean checkBeginning, boolean checkSpaces, boolean equals) { + boolean checkBeginning, boolean checkSpaces, boolean equals, boolean trim) { String searchIn = searchInParam.toLowerCase(Locale.getDefault()); - int startLength = theStart.length(); int searchInLength = searchIn.length(); + if (trim && searchInLength > 0 && theStart.length() > searchInLength) { + theStart = theStart.substring(0, searchInLength); + } + int startLength = theStart.length(); if (startLength == 0) { return true; } 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 e328c83965..0d483b6f58 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 @@ -667,7 +667,8 @@ public class SearchCoreFactory { categories = types.getCategories(false); } List results = new ArrayList(); - NameStringMatcher nm = phrase.getNameStringMatcher(); + NameStringMatcher nm = + new NameStringMatcher(phrase.getUnknownSearchPhrase(), StringMatcherMode.CHECK_ONLY_STARTS_WITH_TRIM); for (PoiFilter pf : topVisibleFilters) { if (!phrase.isUnknownSearchWordPresent() || nm.matches(pf.getTranslation()) @@ -900,7 +901,7 @@ public class SearchCoreFactory { res.preferredZoom = 17; res.file = selected; res.location = object.getLocation(); - res.priority = hasCustomName ? SEARCH_AMENITY_TYPE_PRIORITY - 1 : SEARCH_AMENITY_BY_TYPE_PRIORITY; + res.priority = SEARCH_AMENITY_BY_TYPE_PRIORITY; res.priorityDistance = 1; res.objectType = ObjectType.POI; resultMatcher.publish(res);