[search] Don't use alt or old names in street matching.

Signed-off-by: Viktor Govako <viktor.govako@gmail.com>
This commit is contained in:
Viktor Govako 2023-05-03 15:57:48 -03:00
parent 9ef26bec1d
commit a88ecc82f2
4 changed files with 17 additions and 11 deletions

View file

@ -92,6 +92,12 @@ public:
static Languages const & GetSupportedLanguages();
// These names require separate search/street processing.
static bool IsAltOrOldName(int8_t langCode)
{
return langCode == kAltNameCode || langCode == kOldNameCode;
}
/// @returns kUnsupportedLanguageCode if language is not recognized.
static int8_t GetLangIndex(std::string_view lang);
/// @returns empty string if langCode is invalid.

View file

@ -37,7 +37,7 @@ namespace
template <typename Slice>
void UpdateNameScores(string_view name, uint8_t lang, Slice const & slice, NameScores & bestScores)
{
if (lang == StringUtf8Multilang::kAltNameCode || lang == StringUtf8Multilang::kOldNameCode)
if (StringUtf8Multilang::IsAltOrOldName(lang))
{
strings::Tokenize(name, ";", [&](string_view n)
{
@ -129,7 +129,7 @@ NameScores GetNameScores(FeatureType & ft, Geocoder::Params const & params,
}
};
if (lang == StringUtf8Multilang::kAltNameCode || lang == StringUtf8Multilang::kOldNameCode)
if (StringUtf8Multilang::IsAltOrOldName(lang))
{
strings::Tokenize(name, ";", [&updateScore](string_view n)
{
@ -875,7 +875,7 @@ void Ranker::GetBestMatchName(FeatureType & f, string & name) const
auto bestNameFinder = [&](int8_t lang, string_view s)
{
if (lang == StringUtf8Multilang::kAltNameCode || lang == StringUtf8Multilang::kOldNameCode)
if (StringUtf8Multilang::IsAltOrOldName(lang))
{
strings::Tokenize(s, ";", [lang, &updateScore](std::string_view n)
{
@ -899,8 +899,7 @@ void Ranker::GetBestMatchName(FeatureType & f, string & name) const
};
UNUSED_VALUE(f.ForEachName(bestNameFinder));
if (bestLang == StringUtf8Multilang::kAltNameCode ||
bestLang == StringUtf8Multilang::kOldNameCode)
if (StringUtf8Multilang::IsAltOrOldName(bestLang))
{
string_view const readableName = f.GetReadableName();
// Do nothing if alt/old name is the only name we have.

View file

@ -273,8 +273,7 @@ NameScores GetNameScores(std::vector<strings::UniString> const & tokens, uint8_t
// Update the match quality
totalErrorsMade += errorsMade;
matchedLength += slice.Get(i).GetOriginal().size();
isAltOrOldName =
lang == StringUtf8Multilang::kAltNameCode || lang == StringUtf8Multilang::kOldNameCode;
isAltOrOldName = StringUtf8Multilang::IsAltOrOldName(lang);
}
else
{

View file

@ -109,15 +109,17 @@ optional<uint32_t> ReverseGeocoder::GetMatchedStreetIndex(string_view keyName,
for (auto const & street : streets)
{
bool fullMatchFound = false;
street.m_multilangName.ForEach([&](int8_t /* langCode */, string_view name)
street.m_multilangName.ForEach([&](int8_t lang, string_view name)
{
if (fullMatchFound)
return;
strings::UniString const actual = GetStreetNameAsKey(name, ignoreStreetSynonyms);
// Skip _non-language_ names for street<->address matching.
if (StringUtf8Multilang::IsAltOrOldName(lang))
return;
size_t const editDistance =
strings::EditDistance(key.begin(), key.end(), actual.begin(), actual.end());
strings::UniString const actual = GetStreetNameAsKey(name, ignoreStreetSynonyms);
size_t const editDistance = strings::EditDistance(key.begin(), key.end(), actual.begin(), actual.end());
if (editDistance == 0)
{