[search] Fixed street's ranking - skip possible synonyms in name's rank.

Signed-off-by: Viktor Govako <viktor.govako@gmail.com>
This commit is contained in:
Viktor Govako 2023-09-23 00:05:20 -03:00
parent 1d6224d134
commit ab21f252dd
2 changed files with 59 additions and 3 deletions

View file

@ -7,9 +7,6 @@
#include "search/pre_ranking_info.hpp"
#include "search/ranking_utils.hpp"
#include "search/token_slice.hpp"
#include "search/utils.hpp"
#include "editor/editable_data_source.hpp"
#include "indexer/brands_holder.hpp"
#include "indexer/data_source.hpp"
@ -95,6 +92,17 @@ vector<vector<strings::UniString>> ModifyStrasse(vector<strings::UniString> cons
return result;
}
vector<strings::UniString> RemoveStreetSynonyms(vector<strings::UniString> const & tokens)
{
vector<strings::UniString> res;
for (auto const & e : tokens)
{
if (!IsStreetSynonym(e))
res.push_back(e);
}
return res;
}
NameScores GetNameScores(FeatureType & ft, Geocoder::Params const & params,
TokenRange const & range, Model::Type type)
{
@ -115,8 +123,20 @@ NameScores GetNameScores(FeatureType & ft, Geocoder::Params const & params,
UpdateNameScores(vec, lang, slice, bestScores);
UpdateNameScores(vec, lang, sliceNoCategories, bestScores);
/// @todo
/// 1. Make sure that this conversion also happens for Address and POI results,
/// where street is only one component.
/// 2. Make an optimization: If there are no synonyms or "strasse", skip this step.
if (type == Model::TYPE_STREET)
{
// Searching for "Santa Fe" should rank "Avenida Satna Fe" like FULL_MATCH or FULL_PREFIX, but not SUBSTRING.
{
TokensVector cleaned(RemoveStreetSynonyms(vec.GetTokens()));
UpdateNameScores(cleaned, lang, slice, bestScores);
UpdateNameScores(cleaned, lang, sliceNoCategories, bestScores);
}
/// @todo Should definitely add "platz"-"pl". And maybe "gasse"-"g", "allee"-"al"?
for (auto & variant : ModifyStrasse(vec.GetTokens()))
{
TokensVector vec(std::move(variant));

View file

@ -922,4 +922,40 @@ UNIT_CLASS_TEST(MwmTestsFixture, BA_RelaxedStreets)
TEST_GREATER(count, 5, ());
}
}
UNIT_CLASS_TEST(MwmTestsFixture, Streets_Rank)
{
// Buenos Aires (Palermo)
ms::LatLon const center(-34.5802699, -58.4124979);
SetViewportAndLoadMaps(center);
auto const & streetChecker = ftypes::IsStreetOrSquareChecker::Instance();
auto const processRequest = [&](std::string const & query, size_t idx)
{
auto request = MakeRequest(query);
auto const & results = request->Results();
TEST_GREATER(results.size(), idx, ());
bool found = false;
for (size_t i = 0; i < idx && !found; ++i)
{
auto const & r = results[i];
if (streetChecker(r.GetFeatureType()))
{
TEST_EQUAL(r.GetString(), "Avenida Santa Fe", ());
TEST_LESS(GetDistanceM(r, center), 1000, ());
found = true;
}
}
TEST(found, ());
};
/// @todo Street should be highwer than 11.
processRequest("Santa Fe ", 11);
/// @todo Prefix search" gives POIs (Starbucks) near "Avenida Santa Fe".
processRequest("Santa Fe st ", 2);
}
} // namespace real_mwm_tests