From 932eff69b970a2d079e16d50978210fe16e0ceca Mon Sep 17 00:00:00 2001 From: alisa911 Date: Thu, 12 Dec 2024 18:45:11 +0200 Subject: [PATCH 1/3] fix search brands --- OsmAnd-java/src/main/java/net/osmand/OsmAndCollator.java | 6 ++++++ .../main/java/net/osmand/search/core/SearchCoreFactory.java | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/OsmAndCollator.java b/OsmAnd-java/src/main/java/net/osmand/OsmAndCollator.java index 21d0a5d2318..f66a047e079 100644 --- a/OsmAnd-java/src/main/java/net/osmand/OsmAndCollator.java +++ b/OsmAnd-java/src/main/java/net/osmand/OsmAndCollator.java @@ -13,6 +13,12 @@ public static net.osmand.Collator primaryCollator() { instance.setStrength(java.text.Collator.PRIMARY); return wrapCollator(instance); } + + public static net.osmand.Collator primaryCollator(Locale locale) { + final java.text.Collator instance = java.text.Collator.getInstance(locale); + instance.setStrength(java.text.Collator.PRIMARY); + return wrapCollator(instance); + } public static net.osmand.Collator wrapCollator(final java.text.Collator instance) { return new net.osmand.Collator() { 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 85923d74096..a2f28d37718 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 @@ -1125,7 +1125,7 @@ private TopIndexMatch matchTopIndex(BinaryMapIndexReader r, SearchPhrase phrase) List poiSubTypes = r.getTopIndexSubTypes(); String lang = phrase.getSettings().getLang(); List matches = new ArrayList<>(); - Collator collator = OsmAndCollator.primaryCollator(); + Collator collator = OsmAndCollator.primaryCollator(new Locale(phrase.getSettings().getLang())); NameStringMatcher nm = new NameStringMatcher(search, CHECK_ONLY_STARTS_WITH); for (PoiSubType subType : poiSubTypes) { String topIndexValue = null; From ba113f76fe71e99390dc54c0146121c62d9c89b2 Mon Sep 17 00:00:00 2001 From: alisa911 Date: Thu, 12 Dec 2024 18:53:59 +0200 Subject: [PATCH 2/3] fix search brands --- OsmAnd-java/src/main/java/net/osmand/OsmAndCollator.java | 6 ------ .../java/net/osmand/search/core/SearchCoreFactory.java | 7 ++++--- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/OsmAndCollator.java b/OsmAnd-java/src/main/java/net/osmand/OsmAndCollator.java index f66a047e079..21d0a5d2318 100644 --- a/OsmAnd-java/src/main/java/net/osmand/OsmAndCollator.java +++ b/OsmAnd-java/src/main/java/net/osmand/OsmAndCollator.java @@ -13,12 +13,6 @@ public static net.osmand.Collator primaryCollator() { instance.setStrength(java.text.Collator.PRIMARY); return wrapCollator(instance); } - - public static net.osmand.Collator primaryCollator(Locale locale) { - final java.text.Collator instance = java.text.Collator.getInstance(locale); - instance.setStrength(java.text.Collator.PRIMARY); - return wrapCollator(instance); - } public static net.osmand.Collator wrapCollator(final java.text.Collator instance) { return new net.osmand.Collator() { 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 a2f28d37718..1ca6ea04ad4 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 @@ -1125,7 +1125,6 @@ private TopIndexMatch matchTopIndex(BinaryMapIndexReader r, SearchPhrase phrase) List poiSubTypes = r.getTopIndexSubTypes(); String lang = phrase.getSettings().getLang(); List matches = new ArrayList<>(); - Collator collator = OsmAndCollator.primaryCollator(new Locale(phrase.getSettings().getLang())); NameStringMatcher nm = new NameStringMatcher(search, CHECK_ONLY_STARTS_WITH); for (PoiSubType subType : poiSubTypes) { String topIndexValue = null; @@ -1135,11 +1134,13 @@ private TopIndexMatch matchTopIndex(BinaryMapIndexReader r, SearchPhrase phrase) for (String s : possibleValues) { translate = getTopIndexTranslation(s); if (complete) { - if (CollatorStringMatcher.cmatches(collator, search, s, StringMatcherMode.CHECK_ONLY_STARTS_WITH)) { + CollatorStringMatcher csm = new CollatorStringMatcher(s, StringMatcherMode.CHECK_ONLY_STARTS_WITH); + if (csm.matches(search)) { topIndexValue = s; break; } else { - if (CollatorStringMatcher.cmatches(collator, search, translate, StringMatcherMode.CHECK_ONLY_STARTS_WITH)) { + csm = new CollatorStringMatcher(translate, StringMatcherMode.CHECK_ONLY_STARTS_WITH); + if (csm.matches(search)) { topIndexValue = s; break; } From 1e6e73a1b66fe883982fc70381ae54312d0bd28a Mon Sep 17 00:00:00 2001 From: alisa911 Date: Thu, 12 Dec 2024 22:30:45 +0200 Subject: [PATCH 3/3] fix search brands --- .../java/net/osmand/search/core/SearchCoreFactory.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 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 1ca6ea04ad4..478ba84e7bd 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 @@ -1125,6 +1125,7 @@ private TopIndexMatch matchTopIndex(BinaryMapIndexReader r, SearchPhrase phrase) List poiSubTypes = r.getTopIndexSubTypes(); String lang = phrase.getSettings().getLang(); List matches = new ArrayList<>(); + Collator collator = OsmAndCollator.primaryCollator(); NameStringMatcher nm = new NameStringMatcher(search, CHECK_ONLY_STARTS_WITH); for (PoiSubType subType : poiSubTypes) { String topIndexValue = null; @@ -1133,14 +1134,13 @@ private TopIndexMatch matchTopIndex(BinaryMapIndexReader r, SearchPhrase phrase) Collections.sort(possibleValues); for (String s : possibleValues) { translate = getTopIndexTranslation(s); + String normalizeBrand = s.toLowerCase(Locale.ROOT); if (complete) { - CollatorStringMatcher csm = new CollatorStringMatcher(s, StringMatcherMode.CHECK_ONLY_STARTS_WITH); - if (csm.matches(search)) { + if (CollatorStringMatcher.cmatches(collator, search, normalizeBrand, StringMatcherMode.CHECK_ONLY_STARTS_WITH)) { topIndexValue = s; break; } else { - csm = new CollatorStringMatcher(translate, StringMatcherMode.CHECK_ONLY_STARTS_WITH); - if (csm.matches(search)) { + if (CollatorStringMatcher.cmatches(collator, search, translate, StringMatcherMode.CHECK_ONLY_STARTS_WITH)) { topIndexValue = s; break; } @@ -1172,7 +1172,7 @@ private TopIndexMatch matchTopIndex(BinaryMapIndexReader r, SearchPhrase phrase) private String getTopIndexTranslation(String value) { String key = TopIndexFilter.getValueKey(value); String translate = types.getPoiTranslation(key); - if (translate.toLowerCase().equals(key)) { + if (translate.toLowerCase(Locale.ROOT).equals(key)) { translate = value; } return translate;