forked from organicmaps/organicmaps
[search] Fixed locality ordering.
This commit is contained in:
parent
d74f4f83a2
commit
9e534beb97
2 changed files with 14 additions and 14 deletions
|
@ -37,21 +37,19 @@ void LocalityScorer::LeaveTopLocalities(size_t limit, vector<Geocoder::Locality>
|
|||
localities.end());
|
||||
|
||||
// Leave the most popular localities.
|
||||
/// @todo Calculate match costs according to the exact locality name
|
||||
/// (for 'york' query "york city" is better than "new york").
|
||||
sort(localities.begin(), localities.end(),
|
||||
[&](Geocoder::Locality const & lhs, Geocoder::Locality const & rhs)
|
||||
{
|
||||
auto const ls = GetTokensScore(lhs);
|
||||
auto const rs = GetTokensScore(rhs);
|
||||
if (ls != rs)
|
||||
return ls > rs;
|
||||
return m_rankTable.Get(lhs.m_featureId) > m_rankTable.Get(rhs.m_featureId);
|
||||
});
|
||||
if (localities.size() > limit)
|
||||
{
|
||||
/// @todo Calculate match costs according to the exact locality name
|
||||
/// (for 'york' query "york city" is better than "new york").
|
||||
sort(localities.begin(), localities.end(),
|
||||
[&](Geocoder::Locality const & lhs, Geocoder::Locality const & rhs)
|
||||
{
|
||||
auto const ls = GetTokensScore(lhs);
|
||||
auto const rs = GetTokensScore(rhs);
|
||||
if (ls != rs)
|
||||
return ls > rs;
|
||||
return m_rankTable.Get(lhs.m_featureId) > m_rankTable.Get(rhs.m_featureId);
|
||||
});
|
||||
localities.resize(limit);
|
||||
}
|
||||
}
|
||||
|
||||
size_t LocalityScorer::GetTokensScore(Geocoder::Locality const & locality) const
|
||||
|
|
|
@ -16,7 +16,9 @@ class LocalityScorer
|
|||
public:
|
||||
LocalityScorer(RankTable const & rankTable, SearchQueryParams const & params);
|
||||
|
||||
// *NOTE* after call, elements of |localities| may be in any order.
|
||||
// After the call there will be no more than |limit| unique elements
|
||||
// in |localities|, in descending order by number of matched tokens
|
||||
// and ranks.
|
||||
void LeaveTopLocalities(size_t limit, vector<Geocoder::Locality> & localities) const;
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Reference in a new issue