forked from organicmaps/organicmaps
Review fixes.
This commit is contained in:
parent
cf12dca348
commit
106e144157
4 changed files with 67 additions and 31 deletions
|
@ -732,13 +732,8 @@ void Query::MakePreResult2(v2::Geocoder::Params const & params, vector<T> & cont
|
|||
using TPreResultSet = set<impl::PreResult1, LessFeatureID>;
|
||||
TPreResultSet theSet;
|
||||
|
||||
vector<impl::PreResult1> results;
|
||||
results.reserve(m_results.size());
|
||||
for (auto const & p : m_results)
|
||||
results.emplace_back(p.second);
|
||||
|
||||
sort(results.begin(), results.end(), &impl::PreResult1::LessPriority);
|
||||
if (kPreResultsCount != 0 && results.size() > kPreResultsCount)
|
||||
sort(m_results.begin(), m_results.end(), &impl::PreResult1::LessPriority);
|
||||
if (kPreResultsCount != 0 && m_results.size() > kPreResultsCount)
|
||||
{
|
||||
// Priority is some kind of distance from the viewport or
|
||||
// position, therefore if we have a bunch of results with the same
|
||||
|
@ -747,29 +742,30 @@ void Query::MakePreResult2(v2::Geocoder::Params const & params, vector<T> & cont
|
|||
// feature id) this code randomly selects tail of the
|
||||
// sorted-by-priority list of pre-results.
|
||||
|
||||
double const lastPriority = results[kPreResultsCount - 1].GetPriority();
|
||||
double const lastPriority = m_results[kPreResultsCount - 1].GetPriority();
|
||||
|
||||
auto b = results.begin() + kPreResultsCount - 1;
|
||||
for (; b != results.begin() && b->GetPriority() == lastPriority; --b)
|
||||
auto b = m_results.begin() + kPreResultsCount - 1;
|
||||
for (; b != m_results.begin() && b->GetPriority() == lastPriority; --b)
|
||||
;
|
||||
if (b->GetPriority() != lastPriority)
|
||||
++b;
|
||||
|
||||
auto e = results.begin() + kPreResultsCount;
|
||||
for (; e != results.end() && e->GetPriority() == lastPriority; ++e)
|
||||
auto e = m_results.begin() + kPreResultsCount;
|
||||
for (; e != m_results.end() && e->GetPriority() == lastPriority; ++e)
|
||||
;
|
||||
|
||||
// TODO (@y, @m, @vng): this method is deprecated, need to rewrite
|
||||
// it.
|
||||
random_shuffle(b, e);
|
||||
}
|
||||
theSet.insert(results.begin(), results.begin() + min(results.size(), kPreResultsCount));
|
||||
theSet.insert(m_results.begin(), m_results.begin() + min(m_results.size(), kPreResultsCount));
|
||||
|
||||
if (!m_viewportSearch)
|
||||
{
|
||||
size_t n = min(results.size(), kPreResultsCount);
|
||||
nth_element(results.begin(), results.begin() + n, results.end(), &impl::PreResult1::LessRank);
|
||||
theSet.insert(results.begin(), results.begin() + n);
|
||||
size_t n = min(m_results.size(), kPreResultsCount);
|
||||
nth_element(m_results.begin(), m_results.begin() + n, m_results.end(),
|
||||
&impl::PreResult1::LessRank);
|
||||
theSet.insert(m_results.begin(), m_results.begin() + n);
|
||||
}
|
||||
|
||||
ClearResults();
|
||||
|
@ -958,8 +954,7 @@ void Query::AddPreResult1(MwmSet::MwmId const & mwmId, uint32_t featureId, doubl
|
|||
v2::PreRankingInfo const & info, ViewportID viewportId /* = DEFAULT_V */)
|
||||
{
|
||||
FeatureID id(mwmId, featureId);
|
||||
impl::PreResult1 res(id, priority, viewportId, info);
|
||||
m_results.emplace(make_pair(id, res));
|
||||
m_results.emplace_back(id, priority, viewportId, info);
|
||||
}
|
||||
|
||||
namespace impl
|
||||
|
|
|
@ -281,7 +281,8 @@ protected:
|
|||
DISTANCE_TO_PIVOT, // LessDistance
|
||||
FEATURE_RANK // LessRank
|
||||
};
|
||||
map<FeatureID, impl::PreResult1> m_results;
|
||||
|
||||
vector<impl::PreResult1> m_results;
|
||||
bool m_viewportSearch;
|
||||
bool m_keepHouseNumberInQuery;
|
||||
//@}
|
||||
|
|
|
@ -350,13 +350,29 @@ double GetSimilarity(vector<m2::RectD> const & pivots, m2::RectD const & rect)
|
|||
for (auto const & pivot : pivots)
|
||||
{
|
||||
double const area = min(Area(pivot), Area(rect));
|
||||
if (area == 0.0)
|
||||
continue;
|
||||
|
||||
m2::RectD p = pivot;
|
||||
p.Intersect(rect);
|
||||
distance += area == 0.0 ? 0.0 : Area(p) / area;
|
||||
if (!p.Intersect(rect))
|
||||
continue;
|
||||
|
||||
distance += Area(p) / area;
|
||||
}
|
||||
return distance;
|
||||
}
|
||||
|
||||
// Returns shortest squared distance from the centers of |pivots| to
|
||||
// the |rect|.
|
||||
double GetSquaredDistance(vector<m2::RectD> const & pivots, m2::RectD const & rect)
|
||||
{
|
||||
double distance = numeric_limits<double>::max();
|
||||
auto const center = rect.Center();
|
||||
for (auto const & pivot : pivots)
|
||||
distance = min(distance, center.SquareLength(pivot.Center()));
|
||||
return distance;
|
||||
}
|
||||
|
||||
// Reorders maps in a way that prefix consists of maps intersecting
|
||||
// with viewport and position, suffix consists of all other maps
|
||||
// ordered by minimum distance from viewport and position. Returns an
|
||||
|
@ -368,8 +384,22 @@ TIt OrderCountries(Geocoder::Params const & params, TIt begin, TIt end)
|
|||
GetRectAroundPoistion(params.m_position)};
|
||||
auto compareBySimilarity = [&](shared_ptr<MwmInfo> const & lhs, shared_ptr<MwmInfo> const & rhs)
|
||||
{
|
||||
return GetSimilarity(pivots, lhs->m_limitRect) > GetSimilarity(pivots, rhs->m_limitRect);
|
||||
auto const & lhsRect = lhs->m_limitRect;
|
||||
auto const & rhsRect = rhs->m_limitRect;
|
||||
|
||||
auto const lhsSimilarity = GetSimilarity(pivots, lhsRect);
|
||||
auto const rhsSimilarity = GetSimilarity(pivots, rhsRect);
|
||||
|
||||
if (lhsSimilarity == 0.0 && rhsSimilarity == 0.0)
|
||||
{
|
||||
auto const lhsDistance = GetSquaredDistance(pivots, lhsRect);
|
||||
auto const rhsDistance = GetSquaredDistance(pivots, rhsRect);
|
||||
return lhsDistance < rhsDistance;
|
||||
}
|
||||
|
||||
return lhsSimilarity > rhsSimilarity;
|
||||
};
|
||||
|
||||
auto intersects = [&](shared_ptr<MwmInfo> const & info) -> bool
|
||||
{
|
||||
for (auto const & pivot : pivots)
|
||||
|
@ -379,6 +409,7 @@ TIt OrderCountries(Geocoder::Params const & params, TIt begin, TIt end)
|
|||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
sort(begin, end, compareBySimilarity);
|
||||
return stable_partition(begin, end, intersects);
|
||||
}
|
||||
|
@ -1305,9 +1336,6 @@ void Geocoder::EmitResult(City const & city, size_t startToken, size_t endToken)
|
|||
|
||||
void Geocoder::FillMissingFieldsInResults()
|
||||
{
|
||||
m_viewportFeatures.SetPosition(m_params.m_viewport.Center(), m_params.m_scale);
|
||||
m_positionFeatures.SetPosition(m_params.m_position, m_params.m_scale);
|
||||
|
||||
sort(m_results->begin(), m_results->end(), my::CompareBy(&TResult::first));
|
||||
|
||||
auto ib = m_results->begin();
|
||||
|
@ -1331,12 +1359,23 @@ void Geocoder::FillMissingFieldsInResults()
|
|||
auto & info = ii->second;
|
||||
|
||||
info.m_rank = rankTable->Get(id.m_index);
|
||||
info.m_distanceToViewport = m_viewportFeatures.GetDistanceToFeatureMeters(id);
|
||||
info.m_distanceToPosition = m_positionFeatures.GetDistanceToFeatureMeters(id);
|
||||
}
|
||||
}
|
||||
ib = ie;
|
||||
}
|
||||
|
||||
if (m_results->size() > m_params.m_maxNumResults)
|
||||
{
|
||||
m_viewportFeatures.SetPosition(m_params.m_viewport.Center(), m_params.m_scale);
|
||||
m_positionFeatures.SetPosition(m_params.m_position, m_params.m_scale);
|
||||
for (auto & result : *m_results)
|
||||
{
|
||||
auto const & id = result.first;
|
||||
auto & info = result.second;
|
||||
info.m_distanceToViewport = m_viewportFeatures.GetDistanceToFeatureMeters(id);
|
||||
info.m_distanceToPosition = m_positionFeatures.GetDistanceToFeatureMeters(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Geocoder::MatchUnclassified(size_t curToken)
|
||||
|
|
|
@ -9,12 +9,15 @@ namespace v2
|
|||
{
|
||||
namespace
|
||||
{
|
||||
// See search/search_quality/scoring_model.py for details. In short,
|
||||
// these coeffs correspond to coeffs in a linear model.
|
||||
double const kDistanceToViewport = 1.850;
|
||||
double const kDistanceToPosition = 85.898;
|
||||
double const kMinDistance = 6.908;
|
||||
double const kRank = 78.441;
|
||||
double const kNameScore = 1.0;
|
||||
double const kNameCoverage = 0.0;
|
||||
double const kSearchType = 1.0;
|
||||
double const kPositionInViewport = 0.0;
|
||||
|
||||
double TransformDistance(double distance)
|
||||
|
@ -63,9 +66,6 @@ void RankingInfo::ToCSV(ostream & os) const
|
|||
|
||||
double RankingInfo::GetLinearModelRank() const
|
||||
{
|
||||
// See search/search_quality/scoring_model.py for details. In
|
||||
// short, these coeffs correspond to coeffs in a linear model.
|
||||
|
||||
// NOTE: this code must be consistent with scoring_model.py. Keep
|
||||
// this in mind when you're going to change scoring_model.py or this
|
||||
// code. We're working on automatic rank calculation code generator
|
||||
|
@ -93,7 +93,8 @@ double RankingInfo::GetLinearModelRank() const
|
|||
|
||||
return kDistanceToViewport * distanceToViewport + kDistanceToPosition * distanceToPosition +
|
||||
kMinDistance * minDistance + kRank * rank + kNameScore * nameScore +
|
||||
kNameCoverage * nameCoverage + kPositionInViewport * positionInViewport;
|
||||
kNameCoverage * nameCoverage + kSearchType * searchType +
|
||||
kPositionInViewport * positionInViewport;
|
||||
}
|
||||
} // namespace v2
|
||||
} // namespace search
|
||||
|
|
Loading…
Add table
Reference in a new issue