diff --git a/search/intermediate_result.cpp b/search/intermediate_result.cpp index e76848da35..35ee098be8 100644 --- a/search/intermediate_result.cpp +++ b/search/intermediate_result.cpp @@ -27,10 +27,10 @@ #include "3party/opening_hours/opening_hours.hpp" -using namespace std; - namespace search { +using namespace std; + namespace { class SkipRegionInfo @@ -67,7 +67,11 @@ public: // PreRankerResult --------------------------------------------------------------------------------- PreRankerResult::PreRankerResult(FeatureID const & id, PreRankingInfo const & info, vector const & provenance) - : m_id(id), m_info(info), m_provenance(provenance) +: m_id(id), m_info(info) +, m_isRelaxed(base::IsExist(provenance, ResultTracer::Branch::Relaxed)) +#ifdef SEARCH_USE_PROVENANCE +, m_provenance(provenance) +#endif { ASSERT(m_id.IsValid(), ()); @@ -77,8 +81,7 @@ PreRankerResult::PreRankerResult(FeatureID const & id, PreRankingInfo const & in } // static -bool PreRankerResult::LessRankAndPopularity(PreRankerResult const & lhs, - PreRankerResult const & rhs) +bool PreRankerResult::LessRankAndPopularity(PreRankerResult const & lhs, PreRankerResult const & rhs) { if (lhs.m_info.m_rank != rhs.m_info.m_rank) return lhs.m_info.m_rank > rhs.m_info.m_rank; @@ -271,8 +274,10 @@ string DebugPrint(RankerResult const & r) << "Name: " << r.GetName() << "; Type: " << classif().GetReadableObjectName(r.GetBestType()); - if (!r.GetProvenance().empty()) - ss << "; Provenance: " << ::DebugPrint(r.GetProvenance()); +#ifdef SEARCH_USE_PROVENANCE + if (!r.m_provenance.empty()) + ss << "; Provenance: " << ::DebugPrint(r.m_provenance); +#endif ss << "; " << DebugPrint(r.GetRankingInfo()) << "; Linear model rank: " << r.GetLinearModelRank() diff --git a/search/intermediate_result.hpp b/search/intermediate_result.hpp index 5dbbf0ab70..8bfe78e8a6 100644 --- a/search/intermediate_result.hpp +++ b/search/intermediate_result.hpp @@ -54,9 +54,14 @@ public: uint8_t GetRank() const { return m_info.m_rank; } uint8_t GetPopularity() const { return m_info.m_popularity; } PreRankingInfo const & GetInfo() const { return m_info; } + +#ifdef SEARCH_USE_PROVENANCE std::vector const & GetProvenance() const { return m_provenance; } +#endif + size_t GetInnermostTokensNumber() const { return m_info.InnermostTokenRange().Size(); } size_t GetMatchedTokensNumber() const { return m_matchedTokensNumber; } + bool IsNotRelaxed() const { return !m_isRelaxed; } void SetRank(uint8_t rank) { m_info.m_rank = rank; } void SetPopularity(uint8_t popularity) { m_info.m_popularity = popularity; } @@ -68,15 +73,16 @@ public: } private: - friend class RankerResult; - FeatureID m_id; PreRankingInfo m_info; - size_t m_matchedTokensNumber = 0; + size_t m_matchedTokensNumber; + bool m_isRelaxed; +#ifdef SEARCH_USE_PROVENANCE // The call path in the Geocoder that leads to this result. std::vector m_provenance; +#endif }; // Second result class. Objects are created during reading of features. @@ -132,7 +138,11 @@ public: uint32_t GetBestType(std::vector const & preferredTypes = {}) const; +#ifdef SEARCH_USE_PROVENANCE std::vector const & GetProvenance() const { return m_provenance; } +#endif + + friend std::string DebugPrint(RankerResult const & r); private: friend class RankerResultMaker; @@ -162,11 +172,11 @@ private: feature::GeomType m_geomType = feature::GeomType::Undefined; Result::Details m_details; +#ifdef SEARCH_USE_PROVENANCE // The call path in the Geocoder that leads to this result. std::vector m_provenance; +#endif }; void FillDetails(FeatureType & ft, Result::Details & meta); - -std::string DebugPrint(RankerResult const & r); } // namespace search diff --git a/search/pre_ranker.cpp b/search/pre_ranker.cpp index 01959b20ca..f3ea892f8f 100644 --- a/search/pre_ranker.cpp +++ b/search/pre_ranker.cpp @@ -22,10 +22,10 @@ #include #include -using namespace std; - namespace search { +using namespace std; + namespace { void SweepNearbyResults(double xEps, double yEps, set const & prevEmit, @@ -154,8 +154,8 @@ void PreRanker::Filter(bool viewportSearch) } }; - auto comparePreRankerResults = [](PreRankerResult const & lhs, - PreRankerResult const & rhs) -> bool { + auto comparePreRankerResults = [](PreRankerResult const & lhs, PreRankerResult const & rhs) + { if (lhs.GetId() != rhs.GetId()) return lhs.GetId() < rhs.GetId(); @@ -276,7 +276,8 @@ void PreRanker::FilterForViewportSearch() { auto const & viewport = m_params.m_viewport; - base::EraseIf(m_results, [&](PreRankerResult const & result) { + base::EraseIf(m_results, [&](PreRankerResult const & result) + { auto const & info = result.GetInfo(); if (!viewport.IsPointInside(info.m_center)) return true; @@ -299,11 +300,10 @@ void PreRanker::FilterRelaxedResults(bool lastUpdate) } else { - auto const isNotRelaxed = [](PreRankerResult const & res) { - auto const & prov = res.GetProvenance(); - return find(prov.begin(), prov.end(), ResultTracer::Branch::Relaxed) == prov.end(); - }; - auto const it = partition(m_results.begin(), m_results.end(), isNotRelaxed); + auto const it = partition(m_results.begin(), m_results.end(), [](PreRankerResult const & res) + { + return res.IsNotRelaxed(); + }); m_relaxedResults.insert(m_relaxedResults.end(), it, m_results.end()); m_results.erase(it, m_results.end()); } diff --git a/search/ranker.cpp b/search/ranker.cpp index fb4d652ae4..55e9871980 100644 --- a/search/ranker.cpp +++ b/search/ranker.cpp @@ -28,10 +28,10 @@ #include #include -using namespace std; - namespace search { +using namespace std; + namespace { template @@ -348,7 +348,10 @@ public: info.m_rank = NormalizeRank(info.m_rank, info.m_type, center, country, ftypes::IsCapitalChecker::Instance()(*ft), !info.m_allTokensUsed); r.SetRankingInfo(move(info)); - r.m_provenance = move(preRankerResult.GetProvenance()); + +#ifdef SEARCH_USE_PROVENANCE + r.m_provenance = preRankerResult.GetProvenance(); +#endif return r; } @@ -648,7 +651,8 @@ Result Ranker::MakeResult(RankerResult const & rankerResult, bool needAddress, } // todo(@m) Used because Result does not have a default constructor. Factor out? - auto mk = [&](RankerResult const & r) -> Result { + auto mk = [&](RankerResult const & r) -> Result + { switch (r.GetResultType()) { case RankerResult::Type::Feature: @@ -681,7 +685,11 @@ Result Ranker::MakeResult(RankerResult const & rankerResult, bool needAddress, HighlightResult(m_params.m_tokens, m_params.m_prefix, res); res.SetRankingInfo(rankerResult.GetRankingInfo()); + +#ifdef SEARCH_USE_PROVENANCE res.SetProvenance(rankerResult.GetProvenance()); +#endif + return res; } diff --git a/search/result.cpp b/search/result.cpp index 723ed69e20..cf3584c572 100644 --- a/search/result.cpp +++ b/search/result.cpp @@ -177,8 +177,12 @@ string DebugPrint(Result const & result) os << "name: " << result.GetString(); os << ", type: " << readableType; os << ", info: " << DebugPrint(result.GetRankingInfo()); - if (!result.GetProvenance().empty()) - os << ", provenance: " << ::DebugPrint(result.GetProvenance()); + +#ifdef SEARCH_USE_PROVENANCE + if (!result.m_provenance.empty()) + os << ", provenance: " << ::DebugPrint(result.m_provenance); +#endif + os << "]"; return os.str(); } diff --git a/search/result.hpp b/search/result.hpp index a5375963b0..cad1c88098 100644 --- a/search/result.hpp +++ b/search/result.hpp @@ -22,6 +22,11 @@ #include #include +// Define this option to DebugPrint provenance. +#ifdef DEBUG +//#define SEARCH_USE_PROVENANCE +#endif + namespace search { // Search result. Search returns a list of them, ordered by score. @@ -129,25 +134,27 @@ public: RankingInfo const & GetRankingInfo() const { return m_info; } - std::vector const & GetProvenance() const { return m_provenance; } - template void SetRankingInfo(Info && info) { m_info = std::forward(info); } +#ifdef SEARCH_USE_PROVENANCE template void SetProvenance(Prov && prov) { m_provenance = std::forward(prov); } +#endif // Returns a representation of this result that is sent to the // statistics servers and later used to measure the quality of our // search engine. std::string ToStringForStats() const; + friend std::string DebugPrint(search::Result const & result); + private: Type m_resultType; @@ -165,7 +172,9 @@ private: // a search query. -1 if undefined. int32_t m_positionInResults = -1; +#ifdef SEARCH_USE_PROVENANCE std::vector m_provenance; +#endif public: // Careful when moving: the order of destructors is important. @@ -173,7 +182,6 @@ public: }; std::string DebugPrint(search::Result::Type type); -std::string DebugPrint(search::Result const & result); class Results {