From d1c2064bba78e984bc3221f816414ee004cacb70 Mon Sep 17 00:00:00 2001 From: crimean Date: Tue, 4 Dec 2018 16:42:38 +0300 Subject: [PATCH] Fix poi types search --- .../java/net/osmand/search/SearchUICore.java | 6 +++-- .../osmand/search/core/SearchCoreFactory.java | 25 +++++++++++-------- .../net/osmand/search/SearchCoreUITest.java | 2 +- .../test/resources/search/double_parking.json | 7 +++--- 4 files changed, 22 insertions(+), 18 deletions(-) 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 eab62ef210..27a07b66b6 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java @@ -319,7 +319,7 @@ public class SearchUICore { SearchAmenityTypesAPI searchAmenityTypesAPI = new SearchAmenityTypesAPI(poiTypes); apis.add(searchAmenityTypesAPI); apis.add(new SearchCoreFactory.SearchAmenityByTypeAPI(poiTypes, searchAmenityTypesAPI)); - apis.add(new SearchCoreFactory.SearchAmenityByNameAPI(searchAmenityTypesAPI)); + apis.add(new SearchCoreFactory.SearchAmenityByNameAPI()); SearchBuildingAndIntersectionsByStreetAPI streetsApi = new SearchCoreFactory.SearchBuildingAndIntersectionsByStreetAPI(); apis.add(streetsApi); @@ -841,7 +841,9 @@ public class SearchUICore { @Override public int compare(SearchResult o1, SearchResult o2) { - if (!ObjectType.isTopVisible(o1.objectType) && !ObjectType.isTopVisible(o2.objectType)) { + boolean topVisible1 = ObjectType.isTopVisible(o1.objectType); + boolean topVisible2 = ObjectType.isTopVisible(o2.objectType); + if ((!topVisible1 && !topVisible2) || (topVisible1 && topVisible2)) { if (o1.isUnknownPhraseMatches() != o2.isUnknownPhraseMatches()) { return o1.isUnknownPhraseMatches() ? -1 : 1; } else if (o1.getFoundWordCount() != o2.getFoundWordCount()) { 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 33754b834d..2d2e2cdff1 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 @@ -316,6 +316,7 @@ public class SearchCoreFactory { String word = phrase.getUnknownWordToSearch(); NameStringMatcher nm = phrase.getNameStringMatcher(word, phrase.isUnknownSearchWordComplete()); NameStringMatcher wordEqualsMatcher = phrase.getNameStringMatcher(word, true); + boolean firstUnknownWordMatches = word.equals(phrase.getUnknownSearchWord()); resArray.clear(); resArray = townCitiesQR.queryInBox(bbox, resArray); int limit = 0; @@ -337,8 +338,8 @@ public class SearchCoreFactory { if (phrase.isEmptyQueryAllowed() && phrase.isEmpty()) { resultMatcher.publish(res); } else if (nm.matches(res.localeName) || nm.matches(res.otherNames)) { - res.firstUnknownWordMatches = word.equals(phrase.getUnknownSearchWord()); - res.unknownPhraseMatches = wordEqualsMatcher.matches(res.localeName) || wordEqualsMatcher.matches(res.otherNames); + res.firstUnknownWordMatches = firstUnknownWordMatches; + res.unknownPhraseMatches = wordEqualsMatcher.matches(res.localeName); subSearchApiOrPublish(phrase, resultMatcher, res, cityApi); } if (limit++ > LIMIT * phrase.getRadiusLevel()) { @@ -465,6 +466,7 @@ public class SearchCoreFactory { String wordToSearch = phrase.getUnknownWordToSearch(); NameStringMatcher wordEqualsMatcher = phrase.getNameStringMatcher(wordToSearch, true); + boolean firstUnknownWordMatches = wordToSearch.equals(phrase.getUnknownSearchWord()); while (offlineIterator.hasNext() && wordToSearch.length() > 0) { BinaryMapIndexReader r = offlineIterator.next(); currentFile[0] = r; @@ -478,8 +480,8 @@ public class SearchCoreFactory { } r.searchAddressDataByName(req); for (SearchResult res : immediateResults) { - res.firstUnknownWordMatches = wordToSearch.equals(phrase.getUnknownSearchWord()); - res.unknownPhraseMatches = wordEqualsMatcher.matches(res.localeName) || wordEqualsMatcher.matches(res.otherNames); + res.firstUnknownWordMatches = firstUnknownWordMatches; + res.unknownPhraseMatches = wordEqualsMatcher.matches(res.localeName); if (res.objectType == ObjectType.STREET) { City ct = ((Street) res.object).getCity(); phrase.countUnknownWordsMatch(res, @@ -501,11 +503,9 @@ public class SearchCoreFactory { private static final int BBOX_RADIUS = 500 * 1000; private static final int BBOX_RADIUS_INSIDE = 10000 * 1000; // to support city search for basemap private static final int FIRST_WORD_MIN_LENGTH = 3; - private SearchAmenityTypesAPI searchAmenityTypesAPI; - public SearchAmenityByNameAPI(SearchAmenityTypesAPI searchAmenityTypesAPI) { + public SearchAmenityByNameAPI() { super(ObjectType.POI); - this.searchAmenityTypesAPI = searchAmenityTypesAPI; } @Override @@ -574,7 +574,7 @@ public class SearchCoreFactory { } sr.priority = SEARCH_AMENITY_BY_NAME_PRIORITY; if (phraseMatcher != null) { - sr.unknownPhraseMatches = phraseMatcher.matches(sr.localeName) || phraseMatcher.matches(sr.otherNames); + sr.unknownPhraseMatches = phraseMatcher.matches(sr.localeName); } phrase.countUnknownWordsMatch(sr); sr.objectType = ObjectType.POI; @@ -663,7 +663,7 @@ public class SearchCoreFactory { } List results = new ArrayList(); NameStringMatcher nm = - new NameStringMatcher(phrase.getUnknownSearchPhrase(), StringMatcherMode.CHECK_ONLY_STARTS_WITH_TRIM); + new NameStringMatcher(phrase.getUnknownSearchPhrase(), StringMatcherMode.CHECK_STARTS_FROM_SPACE); for (AbstractPoiType pf : topVisibleFilters) { if (!phrase.isUnknownSearchWordPresent() || nm.matches(pf.getTranslation()) @@ -710,6 +710,8 @@ public class SearchCoreFactory { phrase.setUnknownSearchWordPoiTypes(new ArrayList<>(results)); if (resultMatcher != null) { + String word = phrase.getUnknownSearchWord(); + NameStringMatcher startMatch = new NameStringMatcher(word, StringMatcherMode.CHECK_ONLY_STARTS_WITH); for (AbstractPoiType pt : results) { SearchResult res = new SearchResult(phrase); res.localeName = pt.getTranslation(); @@ -717,6 +719,7 @@ public class SearchCoreFactory { res.priority = SEARCH_AMENITY_TYPE_PRIORITY; res.priorityDistance = 0; res.objectType = ObjectType.POI_TYPE; + res.firstUnknownWordMatches = startMatch.matches(res.localeName); resultMatcher.publish(res); } for (int i = 0; i < customPoiFilters.size(); i++) { @@ -909,7 +912,7 @@ public class SearchCoreFactory { res.priority = SEARCH_AMENITY_BY_TYPE_PRIORITY; res.priorityDistance = 1; if (phraseMatcher != null) { - boolean unknownPhraseMatches = phraseMatcher.matches(res.localeName) || phraseMatcher.matches(res.otherNames); + boolean unknownPhraseMatches = phraseMatcher.matches(res.localeName); AbstractPoiType unknownSearchWordPoiType = phrase.getUnknownSearchWordPoiType(); if (unknownPhraseMatches && unknownSearchWordPoiType != null) { unknownPhraseMatches = !phraseMatcher.matches(unknownSearchWordPoiType.getTranslation()) @@ -1033,7 +1036,7 @@ public class SearchCoreFactory { phrase.getNameStringMatcher().matches(res.localeName) || phrase.getNameStringMatcher().matches(res.otherNames); if (phraseMatcher != null) { - res.unknownPhraseMatches = phraseMatcher.matches(res.localeName) || phraseMatcher.matches(res.otherNames); + res.unknownPhraseMatches = phraseMatcher.matches(res.localeName); } res.localeRelatedObjectName = c.getName(phrase.getSettings().getLang(), phrase.getSettings().isTransliterate()); res.object = object; diff --git a/OsmAnd-java/src/test/java/net/osmand/search/SearchCoreUITest.java b/OsmAnd-java/src/test/java/net/osmand/search/SearchCoreUITest.java index a130e8b65c..80d92b7bf1 100644 --- a/OsmAnd-java/src/test/java/net/osmand/search/SearchCoreUITest.java +++ b/OsmAnd-java/src/test/java/net/osmand/search/SearchCoreUITest.java @@ -222,7 +222,7 @@ public class SearchCoreUITest { }); if (files != null) { for (File f : files) { - //testSearchImpl(f); + testSearchImpl(f); } } } diff --git a/OsmAnd-java/src/test/resources/search/double_parking.json b/OsmAnd-java/src/test/resources/search/double_parking.json index 8aa7ec748f..0c23cebe3d 100644 --- a/OsmAnd-java/src/test/resources/search/double_parking.json +++ b/OsmAnd-java/src/test/resources/search/double_parking.json @@ -11,8 +11,7 @@ }, "phrase": "parking", "results": [ - "Park (Leisure)", - "Parking (Filter)", + "Parking (Personal transport)", "Parking entrance (Personal transport)", "Parking fee (Charging station / Transportation)", "Parking fee: no (Charging station / Transportation)", @@ -21,8 +20,8 @@ "Parking tickets (Vending machine / Store)", "Parking tickets (Vending machine / Store)", "Parking time limit (Parking / Personal transport)", - "Parking", - "Parking", + "Bicycle parking (Bicycle transport)", + "Motorcycle parking (Personal transport)", "Parking", "Parking", "Parking",