diff --git a/search/intermediate_result.cpp b/search/intermediate_result.cpp index 1dcfd4a1ff..edad9ac580 100644 --- a/search/intermediate_result.cpp +++ b/search/intermediate_result.cpp @@ -71,6 +71,10 @@ PreRankerResult::PreRankerResult(FeatureID const & id, PreRankingInfo const & in : m_id(id), m_info(info), m_provenance(provenance) { ASSERT(m_id.IsValid(), ()); + + m_matchedTokensNumber = 0; + for (auto const & r : m_info.m_tokenRange) + m_matchedTokensNumber += r.Size(); } // static @@ -100,6 +104,12 @@ bool PreRankerResult::LessByExactMatch(PreRankerResult const & lhs, PreRankerRes if (lhsScore != rhsScore) return lhsScore; + if (lhs.GetInnermostTokensNumber() != rhs.GetInnermostTokensNumber()) + return lhs.GetInnermostTokensNumber() > rhs.GetInnermostTokensNumber(); + + if (lhs.GetMatchedTokensNumber() != rhs.GetMatchedTokensNumber()) + return lhs.GetMatchedTokensNumber() > rhs.GetMatchedTokensNumber(); + return LessDistance(lhs, rhs); } diff --git a/search/intermediate_result.hpp b/search/intermediate_result.hpp index bff743d275..674763a911 100644 --- a/search/intermediate_result.hpp +++ b/search/intermediate_result.hpp @@ -55,6 +55,8 @@ public: PreRankingInfo & GetInfo() { return m_info; } PreRankingInfo const & GetInfo() const { return m_info; } std::vector const & GetProvenance() const { return m_provenance; } + size_t GetInnermostTokensNumber() const { return m_info.InnermostTokenRange().Size(); } + size_t GetMatchedTokensNumber() const { return m_matchedTokensNumber; } private: friend class RankerResult; @@ -62,6 +64,8 @@ private: FeatureID m_id; PreRankingInfo m_info; + size_t m_matchedTokensNumber = 0; + // The call path in the Geocoder that leads to this result. std::vector m_provenance; }; diff --git a/search/pre_ranker.cpp b/search/pre_ranker.cpp index 39880b3354..d46c3d1b6c 100644 --- a/search/pre_ranker.cpp +++ b/search/pre_ranker.cpp @@ -148,11 +148,13 @@ void PreRanker::Filter(bool viewportSearch) if (lhs.GetId() != rhs.GetId()) return lhs.GetId() < rhs.GetId(); - auto const & linfo = lhs.GetInfo(); - auto const & rinfo = rhs.GetInfo(); - if (linfo.GetNumTokens() != rinfo.GetNumTokens()) - return linfo.GetNumTokens() > rinfo.GetNumTokens(); - return linfo.InnermostTokenRange().Begin() < rinfo.InnermostTokenRange().Begin(); + if (lhs.GetInnermostTokensNumber() != rhs.GetInnermostTokensNumber()) + return lhs.GetInnermostTokensNumber() > rhs.GetInnermostTokensNumber(); + + if (lhs.GetMatchedTokensNumber() != rhs.GetMatchedTokensNumber()) + return lhs.GetMatchedTokensNumber() > rhs.GetMatchedTokensNumber(); + + return lhs.GetInfo().InnermostTokenRange().Begin() < rhs.GetInfo().InnermostTokenRange().Begin(); }; sort(m_results.begin(), m_results.end(), comparePreRankerResults); diff --git a/search/pre_ranking_info.hpp b/search/pre_ranking_info.hpp index 18a57553d5..e472ce449c 100644 --- a/search/pre_ranking_info.hpp +++ b/search/pre_ranking_info.hpp @@ -31,8 +31,6 @@ struct PreRankingInfo return m_tokenRange[m_type]; } - size_t GetNumTokens() const { return InnermostTokenRange().Size(); } - // An abstract distance from the feature to the pivot. Measurement // units do not matter here. double m_distanceToPivot = 0; diff --git a/search/ranker.cpp b/search/ranker.cpp index ccba47588f..2cf95ee10f 100644 --- a/search/ranker.cpp +++ b/search/ranker.cpp @@ -183,7 +183,7 @@ void RemoveDuplicatingLinear(vector & results) return t1 < t2; // After unique, the better feature should be kept. - return r1.GetDistance() < r2.GetDistance(); + return r1.GetLinearModelRank() > r2.GetLinearModelRank(); }; auto equalCmp = [](RankerResult const & r1, RankerResult const & r2) -> bool {