[search] review fixes

This commit is contained in:
Arsentiy Milchakov 2019-01-31 17:53:53 +03:00 committed by mpimenov
parent c0709dce3f
commit e8f225900a
2 changed files with 48 additions and 48 deletions

View file

@ -520,6 +520,9 @@ void DrawWidget::ShowInfoPopup(QMouseEvent * e, m2::PointD const & pt)
QMenu menu;
auto const addStringFn = [&menu](string const & s)
{
if (s.empty())
return;
menu.addAction(QString::fromUtf8(s.c_str()));
};
@ -534,13 +537,10 @@ void DrawWidget::ShowInfoPopup(QMouseEvent * e, m2::PointD const & pt)
std::string name;
ft.GetReadableName(name);
if (!name.empty())
addStringFn(name);
addStringFn(name);
search::ReverseGeocoder::Address const info = GetFeatureAddressInfo(m_framework, ft);
string const addr = info.FormatAddress();
if (!addr.empty())
addStringFn(addr);
auto const info = GetFeatureAddressInfo(m_framework, ft);
addStringFn(info.FormatAddress());
menu.addSeparator();
}, m_framework.PtoG(pt));

View file

@ -78,6 +78,48 @@ string Join(string const & s, Args &&... args)
ReverseGeocoder::ReverseGeocoder(DataSource const & dataSource) : m_dataSource(dataSource) {}
// static
boost::optional<uint32_t> ReverseGeocoder::GetMatchedStreetIndex(std::string const & keyName,
vector<Street> const & streets)
{
auto matchStreet = [&](bool ignoreStreetSynonyms) -> boost::optional<uint32_t> {
// Find the exact match or the best match in kSimilarityTresholdPercent limit.
uint32_t result;
size_t minPercent = kSimilarityThresholdPercent + 1;
auto const key = GetStreetNameAsKey(keyName, ignoreStreetSynonyms);
for (auto const & street : streets)
{
strings::UniString const actual = GetStreetNameAsKey(street.m_name, ignoreStreetSynonyms);
size_t const editDistance =
strings::EditDistance(key.begin(), key.end(), actual.begin(), actual.end());
if (editDistance == 0)
return street.m_id.m_index;
if (actual.empty())
continue;
size_t const percent = editDistance * 100 / actual.size();
if (percent < minPercent)
{
result = street.m_id.m_index;
minPercent = percent;
}
}
if (minPercent <= kSimilarityThresholdPercent)
return result;
return {};
};
auto result = matchStreet(false /* ignoreStreetSynonyms */);
if (result)
return result;
return matchStreet(true /* ignoreStreetSynonyms */);
}
// static
void ReverseGeocoder::GetNearbyStreets(search::MwmContext & context, m2::PointD const & center,
bool includeSquaresAndSuburbs, vector<Street> & streets)
@ -120,48 +162,6 @@ void ReverseGeocoder::GetNearbyStreetsWaysOnly(MwmSet::MwmId const & id, m2::Poi
}
}
// static
boost::optional<uint32_t> ReverseGeocoder::GetMatchedStreetIndex(std::string const & keyName,
vector<Street> const & streets)
{
auto matchStreet = [&](bool ignoreStreetSynonyms) -> boost::optional<uint32_t> {
// Find the exact match or the best match in kSimilarityTresholdPercent limit.
uint32_t result;
size_t minPercent = kSimilarityThresholdPercent + 1;
auto const key = GetStreetNameAsKey(keyName, ignoreStreetSynonyms);
for (auto const & street : streets)
{
strings::UniString const actual = GetStreetNameAsKey(street.m_name, ignoreStreetSynonyms);
size_t const editDistance =
strings::EditDistance(key.begin(), key.end(), actual.begin(), actual.end());
if (editDistance == 0)
return street.m_id.m_index;
if (actual.empty())
continue;
size_t const percent = editDistance * 100 / actual.size();
if (percent < minPercent)
{
result = street.m_id.m_index;
minPercent = percent;
}
}
if (minPercent <= kSimilarityThresholdPercent)
return result;
return {};
};
auto result = matchStreet(false /* ignoreStreetSynonyms */);
if (result)
return result;
return matchStreet(true /* ignoreStreetSynonyms */);
}
string ReverseGeocoder::GetFeatureStreetName(FeatureType & ft) const
{
Address addr;