From c52054dadcf129b867e4604f12e2b9eb6168c614 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 2 Jun 2020 00:34:41 +0200 Subject: [PATCH] Fix compilation problems --- .../net/osmand/CollatorStringMatcher.java | 8 --- .../java/net/osmand/search/SearchUICore.java | 2 +- .../osmand/search/core/SearchCoreFactory.java | 62 +++++++++---------- .../net/osmand/search/core/SearchPhrase.java | 11 +--- .../net/osmand/search/core/SearchResult.java | 7 ++- 5 files changed, 37 insertions(+), 53 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/CollatorStringMatcher.java b/OsmAnd-java/src/main/java/net/osmand/CollatorStringMatcher.java index f44ea9855d..bd1a208cfc 100644 --- a/OsmAnd-java/src/main/java/net/osmand/CollatorStringMatcher.java +++ b/OsmAnd-java/src/main/java/net/osmand/CollatorStringMatcher.java @@ -25,9 +25,6 @@ public class CollatorStringMatcher implements StringMatcher { CHECK_STARTS_FROM_SPACE_NOT_BEGINNING, // tests all words (split by space) and one of word should be equal to part CHECK_EQUALS_FROM_SPACE, - // TO DO: make a separate method - // trims part to make shorter then full text and tests only first word as base starts with part - TRIM_AND_CHECK_ONLY_STARTS_WITH, // simple collator contains in any part of the base CHECK_CONTAINS, // simple collator equals @@ -62,11 +59,6 @@ public class CollatorStringMatcher implements StringMatcher { return cstartsWith(collator, fullName, part, false, true, false); case CHECK_ONLY_STARTS_WITH: return cstartsWith(collator, fullName, part, true, false, false); - case TRIM_AND_CHECK_ONLY_STARTS_WITH: - if (part.length() > fullName.length()) { - part = part.substring(0, fullName.length()); - } - return cstartsWith(collator, fullName, part, true, false, false); case CHECK_EQUALS: return cstartsWith(collator, fullName, part, false, false, true); } diff --git a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java index 5e7ed1d9d7..fde107912d 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java @@ -71,7 +71,7 @@ public class SearchUICore { taskQueue = new LinkedBlockingQueue(); searchSettings = new SearchSettings(new ArrayList()); searchSettings = searchSettings.setLang(locale, transliterate); - phrase = SearchPhrase.emptyPhrase(); + phrase = SearchPhrase.emptyPhrase(searchSettings); currentSearchResult = new SearchResultCollection(phrase); singleThreadedExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, taskQueue); } 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 d88578c6ed..d5d039ef16 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 @@ -48,8 +48,6 @@ import java.util.Map.Entry; import java.util.Set; import java.util.TreeSet; -import gnu.trove.list.array.TIntArrayList; - public class SearchCoreFactory { @@ -678,7 +676,7 @@ public class SearchCoreFactory { @Override public boolean search(SearchPhrase phrase, SearchResultMatcher resultMatcher) throws IOException { boolean showTopFiltersOnly = !phrase.isUnknownSearchWordPresent(); - NameStringMatcher nm = phrase.getFullUnknownNameMatcher(); + NameStringMatcher nm = phrase.getFirstUnknownNameStringMatcher(); initPoiTypes(); List poiTypes = topVisibleFilters; if (!showTopFiltersOnly) { @@ -818,18 +816,18 @@ public class SearchCoreFactory { throw new UnsupportedOperationException(); } } else if (searchAmenityTypesAPI != null) { - NameStringMatcher nm = phrase.getFullUnknownNameMatcher(); + NameStringMatcher nm = phrase.getFirstUnknownNameStringMatcher(); searchAmenityTypesAPI.initPoiTypes(); List presentPoiTypes = searchAmenityTypesAPI.getPoiTypeResults(nm, false); - // TODO get first ? - AbstractPoiType poiType = phrase.getUnknownSearchWordPoiType(); - if (poiType != null) { - poiTypeFilter = getPoiTypeFilter(poiType); - nameFilter = phrase.getPoiNameFilter(poiType); - if (nameFilter != null) { - phrase.setUnknownSearchWordPoiType(poiType); - } - } + // TODO get first ? !!! +// AbstractPoiType poiType = phrase.getUnknownSearchWordPoiType(); +// if (poiType != null) { +// poiTypeFilter = getPoiTypeFilter(poiType); +// nameFilter = phrase.getPoiNameFilter(poiType); +// if (nameFilter != null) { +// phrase.setUnknownSearchWordPoiType(poiType); +// } +// } } if (poiTypeFilter != null) { QuadRect bbox = phrase.getRadiusBBoxToSearch(BBOX_RADIUS); @@ -853,7 +851,7 @@ public class SearchCoreFactory { private ResultMatcher getResultMatcher(final SearchPhrase phrase, final SearchResultMatcher resultMatcher, final String nameFilter, final BinaryMapIndexReader selected, final Set searchedPois) { - // TODO + // TODO !!! // String unknownSearchPhrase = phrase.getUnknownSearchPhrase().trim(); // final NameStringMatcher phraseMatcher; // if (!Algorithms.isEmpty(unknownSearchPhrase)) { @@ -861,13 +859,14 @@ public class SearchCoreFactory { // } else { // phraseMatcher = null; // } - final NameStringMatcher ns; - final boolean hasCustomName = !Algorithms.isEmpty(nameFilter); - if (hasCustomName) { - ns = phrase.getNameStringMatcher(nameFilter, phrase.isLastUnknownSearchWordComplete()); - } else { - ns = phrase.getFirstUnknownNameStringMatcher(); - } +// final NameStringMatcher ns; +// final boolean hasCustomName = !Algorithms.isEmpty(nameFilter); +// if (hasCustomName) { +// ns = phrase.getNameStringMatcher(nameFilter, phrase.isLastUnknownSearchWordComplete()); +// } else { +// ns = phrase.getFirstUnknownNameStringMatcher(); +// } + NameStringMatcher ns = phrase.getFirstUnknownNameStringMatcher(); return new ResultMatcher() { @Override @@ -914,16 +913,17 @@ public class SearchCoreFactory { res.priority = SEARCH_AMENITY_BY_TYPE_PRIORITY; res.priorityDistance = 1; - if (phraseMatcher != null) { - boolean unknownPhraseMatches = phraseMatcher.matches(res.localeName); - AbstractPoiType unknownSearchWordPoiType = phrase.getUnknownSearchWordPoiType(); - if (unknownPhraseMatches && unknownSearchWordPoiType != null) { - unknownPhraseMatches = !phraseMatcher.matches(unknownSearchWordPoiType.getTranslation()) - && !phraseMatcher.matches(unknownSearchWordPoiType.getEnTranslation()) - && !phraseMatcher.matches(unknownSearchWordPoiType.getSynonyms()); - } - res.unknownPhraseMatches = unknownPhraseMatches; - } + // TODO !!! +// if (phraseMatcher != null) { +// boolean unknownPhraseMatches = phraseMatcher.matches(res.localeName); +// AbstractPoiType unknownSearchWordPoiType = phrase.getUnknownSearchWordPoiType(); +// if (unknownPhraseMatches && unknownSearchWordPoiType != null) { +// unknownPhraseMatches = !phraseMatcher.matches(unknownSearchWordPoiType.getTranslation()) +// && !phraseMatcher.matches(unknownSearchWordPoiType.getEnTranslation()) +// && !phraseMatcher.matches(unknownSearchWordPoiType.getSynonyms()); +// } +// res.unknownPhraseMatches = unknownPhraseMatches; +// } res.objectType = ObjectType.POI; resultMatcher.publish(res); return false; diff --git a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchPhrase.java b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchPhrase.java index d07ac45042..cc36617798 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchPhrase.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchPhrase.java @@ -293,15 +293,6 @@ public class SearchPhrase { return lastUnknownSearchWordComplete; } - public NameStringMatcher getFullUnknownNameMatcher() { - // TODO investigate diesel 95 - if (isLastUnknownSearchWordComplete() || hasMoreThanOneUnknownSearchWord()) { - return new NameStringMatcher(unknownSearchPhrase, StringMatcherMode.TRIM_AND_CHECK_ONLY_STARTS_WITH); - } else { - return new NameStringMatcher(unknownSearchPhrase, StringMatcherMode.CHECK_STARTS_FROM_SPACE); - } - } - public boolean hasMoreThanOneUnknownSearchWord() { return otherUnknownWords.size() > 0; } @@ -534,7 +525,7 @@ public class SearchPhrase { public NameStringMatcher getUnknownNameStringMatcher(int i) { while (unknownWordsMatcher.size() <= i) { - int ind = unknownWordsMatcher.size() - 1; + int ind = unknownWordsMatcher.size(); boolean completeMatch = ind < otherUnknownWords.size() - 1 || isLastUnknownSearchWordComplete(); unknownWordsMatcher.add(getNameStringMatcher(otherUnknownWords.get(ind), completeMatch)); } diff --git a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java index 957190d67d..7186f90fa3 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java @@ -55,14 +55,15 @@ public class SearchResult { res = ObjectType.getTypeWeight(objectType); } if (parentSearchResult != null) { - // TODO - // 10 > maximum type // double x = parentSearchResult.getUnknownPhraseMatchWeight(); // if (x == 0) { // return 0; // } // res = Math.max(res, parentSearchResult.getUnknownPhraseMatchWeight()); - res += parentSearchResult.getUnknownPhraseMatchWeight() / 10; + // res += parentSearchResult.getUnknownPhraseMatchWeight() / 10; + // 20 > maximum type + // TODO explain comment + res = res / 20 + parentSearchResult.getUnknownPhraseMatchWeight() / 20; } return res; }