[search] Prefer explicit language for mwms with device/input region

This commit is contained in:
tatiana-kondakova 2018-04-16 20:12:04 +03:00 committed by mpimenov
parent 8ab3fd325b
commit 15b65d5fb2
3 changed files with 9 additions and 4 deletions

View file

@ -35,6 +35,10 @@ bool KeywordLangMatcher::Score::operator<(KeywordLangMatcher::Score const & scor
return m_parentScore.LessInTokensLength(score.m_parentScore);
}
bool KeywordLangMatcher::Score::operator<=(KeywordLangMatcher::Score const & score) const
{
return !(score < *this);
}
// KeywordLangMatcher ------------------------------------------------------------------------------
KeywordLangMatcher::KeywordLangMatcher(size_t maxLanguageTiers)
: m_languagePriorities(maxLanguageTiers)

View file

@ -18,6 +18,7 @@ public:
public:
Score();
bool operator<(Score const & s) const;
bool operator<=(Score const & s) const;
private:
friend class KeywordLangMatcher;

View file

@ -560,9 +560,9 @@ void Ranker::MakeRankerResults(Geocoder::Params const & geocoderParams,
void Ranker::GetBestMatchName(FeatureType const & f, string & name) const
{
KeywordLangMatcher::Score bestScore;
auto updateScore = [&](int8_t lang, string const & s) {
auto updateScore = [&](int8_t lang, string const & s, bool force) {
auto const score = m_keywordsScorer.CalcScore(lang, s);
if (bestScore < score)
if (force ? bestScore <= score : bestScore < score)
{
bestScore = score;
name = s;
@ -570,7 +570,7 @@ void Ranker::GetBestMatchName(FeatureType const & f, string & name) const
};
auto bestNameFinder = [&](int8_t lang, string const & s) {
updateScore(lang, s);
updateScore(lang, s, true /* force */);
// Default name should be written in the regional language.
if (lang == StringUtf8Multilang::kDefaultCode)
{
@ -578,7 +578,7 @@ void Ranker::GetBestMatchName(FeatureType const & f, string & name) const
vector<int8_t> mwmLangCodes;
mwmInfo->GetRegionData().GetLanguages(mwmLangCodes);
for (auto const l : mwmLangCodes)
updateScore(l, s);
updateScore(l, s, false /* force */);
}
};
UNUSED_VALUE(f.ForEachName(bestNameFinder));