From 2cdc3ef945f066c62ad9ea82058da83e1c3226c5 Mon Sep 17 00:00:00 2001 From: Viktor Govako Date: Thu, 9 May 2024 23:38:33 -0300 Subject: [PATCH] [search] Fixed cities ranking Country/State query. Signed-off-by: Viktor Govako --- search/ranker.cpp | 17 +++++++++-- .../search_quality_tests/real_mwm_tests.cpp | 30 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/search/ranker.cpp b/search/ranker.cpp index 394155af61..3d155a87ba 100644 --- a/search/ranker.cpp +++ b/search/ranker.cpp @@ -573,7 +573,7 @@ private: updateDependScore(Model::TYPE_SUBURB, preInfo.m_geoParts.m_suburb); updateDependScore(Model::TYPE_COMPLEX_POI, preInfo.m_geoParts.m_complexPoi); - if (!Model::IsLocalityType(info.m_type) && preInfo.m_cityId.IsValid()) + if (preInfo.m_cityId.IsValid()) { if (auto city = LoadFeature(preInfo.m_cityId)) { @@ -586,7 +586,20 @@ private: ASSERT(preInfo.m_tokenRanges[Model::TYPE_VILLAGE].Empty(), ()); } - auto const cityNameScore = updateScoreForFeature(*city, type); + NameScore cityNameScore = NameScore::ZERO; + if (Model::IsLocalityType(info.m_type)) + { + // Hack to promote results like "Nice France". + // Otherwise, POIs with "France" token in name around the "Nice" city will be always on top. + if (preInfo.m_allTokensUsed && preInfo.m_cityId == res.GetId() && + !(preInfo.m_tokenRanges[Model::TYPE_STATE].Empty() && + preInfo.m_tokenRanges[Model::TYPE_COUNTRY].Empty())) + { + cityNameScore = GetNameScores(ft, m_params, preInfo.m_tokenRanges[type], type).m_nameScore; + } + } + else + cityNameScore = updateScoreForFeature(*city, type); // Update distance with matched city pivot if we have a _good_ city name score. // A bit controversial distance score reset, but lets try. diff --git a/search/search_quality/search_quality_tests/real_mwm_tests.cpp b/search/search_quality/search_quality_tests/real_mwm_tests.cpp index a8a89c5733..829d84a50c 100644 --- a/search/search_quality/search_quality_tests/real_mwm_tests.cpp +++ b/search/search_quality/search_quality_tests/real_mwm_tests.cpp @@ -1286,4 +1286,34 @@ UNIT_CLASS_TEST(MwmTestsFixture, NotAllTokens) } } +UNIT_CLASS_TEST(MwmTestsFixture, CityWithCountry) +{ + auto const & cl = classif(); + + // "France_Provence-Alpes-Cote dAzur_Maritime Alps" should present! + RegisterLocalMapsByPrefix("France_Provence-Alpes-Cote dAzur"); + + // Buenos Aires (Palermo) + ms::LatLon const center(-34.58524, -58.42516); + SetViewportAndLoadMaps(center); + + { + auto request = MakeRequest("Nice "); + auto const & results = request->Results(); + TEST_GREATER(results.size(), kTopPoiResultsCount, ()); + + // Usually on 3rd place, because "Nice" is a commmon token for POI's name. + TEST_EQUAL(CountClassifType(Range(results, 0, kTopPoiResultsCount), cl.GetTypeByPath({"place", "city"})), 1, ()); + } + + { + auto request = MakeRequest("Nice France"); + auto const & results = request->Results(); + TEST_GREATER(results.size(), kTopPoiResultsCount, ()); + + // Should be on 1st place. + EqualClassifType(Range(results, 0, 1), GetClassifTypes({{"place", "city"}})); + } +} + } // namespace real_mwm_tests