[search] Added debug SEARCH_USE_PROVENANCE option for search::Result.

Signed-off-by: Viktor Govako <viktor.govako@gmail.com>
This commit is contained in:
Viktor Govako 2022-04-24 00:04:38 +03:00
parent faf8683d4c
commit 6ed16d6351
6 changed files with 66 additions and 31 deletions

View file

@ -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<ResultTracer::Branch> 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()

View file

@ -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<ResultTracer::Branch> 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<ResultTracer::Branch> m_provenance;
#endif
};
// Second result class. Objects are created during reading of features.
@ -132,7 +138,11 @@ public:
uint32_t GetBestType(std::vector<uint32_t> const & preferredTypes = {}) const;
#ifdef SEARCH_USE_PROVENANCE
std::vector<ResultTracer::Branch> 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<ResultTracer::Branch> m_provenance;
#endif
};
void FillDetails(FeatureType & ft, Result::Details & meta);
std::string DebugPrint(RankerResult const & r);
} // namespace search

View file

@ -22,10 +22,10 @@
#include <iterator>
#include <set>
using namespace std;
namespace search
{
using namespace std;
namespace
{
void SweepNearbyResults(double xEps, double yEps, set<FeatureID> 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());
}

View file

@ -28,10 +28,10 @@
#include <memory>
#include <optional>
using namespace std;
namespace search
{
using namespace std;
namespace
{
template <typename Slice>
@ -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;
}

View file

@ -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();
}

View file

@ -22,6 +22,11 @@
#include <utility>
#include <vector>
// 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<ResultTracer::Branch> const & GetProvenance() const { return m_provenance; }
template <typename Info>
void SetRankingInfo(Info && info)
{
m_info = std::forward<Info>(info);
}
#ifdef SEARCH_USE_PROVENANCE
template <typename Prov>
void SetProvenance(Prov && prov)
{
m_provenance = std::forward<Prov>(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<ResultTracer::Branch> 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
{