Review fixes.

This commit is contained in:
Yuri Gorshenin 2016-03-04 12:29:41 +03:00 committed by Sergey Yershov
parent 5564b23098
commit 57736b3fb4
9 changed files with 20 additions and 34 deletions

View file

@ -180,7 +180,7 @@ Result PreResult2::GenerateFinalResult(storage::CountryInfoGetter const & infoGe
case RESULT_FEATURE:
return Result(m_id, GetCenter(), m_str, regionName, pCat->GetReadableFeatureType(type, locale)
#ifdef DEBUG
+ ' ' + strings::to_string(int(m_info.m_rank))
+ ' ' + strings::to_string(static_cast<int>(m_info.m_rank))
#endif
, type, m_metadata);

View file

@ -443,16 +443,13 @@ int main(int argc, char * argv[])
}
ofstream csv;
bool dumpCSV = false;
if (!FLAGS_ranking_csv_file.empty())
{
ofstream os(FLAGS_ranking_csv_file);
csv.swap(os);
if (csv.is_open())
dumpCSV = true;
}
if (dumpCSV)
if (csv.is_open())
{
search::v2::RankingInfo::PrintCSVHeader(csv);
csv << endl;
@ -467,7 +464,7 @@ int main(int argc, char * argv[])
PrintTopResults(MakePrefixFree(queries[i]), requests[i]->Results(), FLAGS_top,
responseTimes[i]);
if (dumpCSV)
if (csv.is_open())
{
for (auto const & result : requests[i]->Results())
{

View file

@ -609,9 +609,7 @@ namespace impl
class PreResult2Maker
{
Query & m_query;
storage::CountryInfoGetter const & m_infoGetter;
v2::Geocoder::Params const & m_params;
string m_positionCountry;
unique_ptr<Index::FeaturesLoaderGuard> m_pFV;
@ -641,10 +639,10 @@ class PreResult2Maker
country = m_pFV->GetCountryFileName();
}
void InitRankingInfo(FeatureType const & ft, impl::PreResult1 const & result,
void InitRankingInfo(FeatureType const & ft, impl::PreResult1 const & res,
search::v2::RankingInfo & info)
{
auto const & preInfo = result.GetInfo();
auto const & preInfo = res.GetInfo();
auto const & viewport = m_params.m_viewport;
auto const & position = m_params.m_position;
@ -676,35 +674,26 @@ class PreResult2Maker
info.m_nameScore = score;
}
auto const featureCountry = m_infoGetter.GetRegionCountryId(feature::GetCenter(ft));
// TODO (@y, @m, @vng): exact check is too restrictive, as we
// switched to small mwms. Probably it's worth here to find a
// Least-Common-Ancestor for feature center and user position in
// the country tree, and use level (distance to root) of the
// result here.
info.m_sameCountry = (featureCountry == m_positionCountry);
info.m_positionInViewport = viewport.IsPointInside(position);
}
public:
explicit PreResult2Maker(Query & q, v2::Geocoder::Params const & params)
: m_query(q), m_infoGetter(m_query.GetCountryInfoGetter()), m_params(params)
: m_query(q), m_params(params)
{
m_positionCountry = m_infoGetter.GetRegionCountryId(m_params.m_position);
}
unique_ptr<impl::PreResult2> operator()(impl::PreResult1 const & res)
unique_ptr<impl::PreResult2> operator()(impl::PreResult1 const & res1)
{
FeatureType feature;
string name, country;
LoadFeature(res.GetID(), feature, name, country);
LoadFeature(res1.GetID(), feature, name, country);
Query::ViewportID const viewportID = static_cast<Query::ViewportID>(res.GetViewportID());
auto res2 = make_unique<impl::PreResult2>(feature, &res, m_query.GetPosition(viewportID), name,
Query::ViewportID const viewportID = static_cast<Query::ViewportID>(res1.GetViewportID());
auto res2 = make_unique<impl::PreResult2>(feature, &res1, m_query.GetPosition(viewportID), name,
country);
search::v2::RankingInfo info;
InitRankingInfo(feature, res, info);
InitRankingInfo(feature, res1, info);
res2->SetRankingInfo(move(info));
/// @todo: add exluding of states (without USA states), continents

View file

@ -103,8 +103,6 @@ public:
void SetQuery(string const & query);
inline bool IsEmptyQuery() const { return (m_prefix.empty() && m_tokens.empty()); }
inline storage::CountryInfoGetter const & GetCountryInfoGetter() const { return m_infoGetter; }
/// @name Different search functions.
//@{
virtual void Search(Results & res, size_t resCount);

View file

@ -1271,7 +1271,7 @@ void Geocoder::EmitResult(MwmSet::MwmId const & mwmId, uint32_t ftId, size_t sta
MercatorBounds::DistanceOnEarth(center, m_params.m_viewport.Center());
info.m_mwmDistanceToPosition = MercatorBounds::DistanceOnEarth(center, m_params.m_position);
}
// info.m_ranks will be filled at the end, at once.
// info.m_ranks will be filled at the end, for all results at once.
m_results->emplace_back(move(id), move(info));
}

View file

@ -128,13 +128,13 @@ public:
};
using TResult = pair<FeatureID, PreRankingInfo>;
using TResultList = vector<pair<FeatureID, PreRankingInfo>>;
using TResultList = vector<TResult>;
Geocoder(Index & index, storage::CountryInfoGetter const & infoGetter);
~Geocoder() override;
// Sets/Gets search query params.
// Sets search query params.
void SetParams(Params const & params);
// Starts geocoding, retrieved features will be appended to
@ -222,8 +222,10 @@ private:
// the lowest layer.
void FindPaths();
// Forms result and appends it to |m_results|.
void EmitResult(MwmSet::MwmId const & mwmId, uint32_t ftId, size_t startToken, size_t endToken);
// Computes rank for all results in |m_results|.
void FillResultRanks();
// Tries to match unclassified objects from lower layers, like

View file

@ -5,6 +5,6 @@ namespace search
namespace v2
{
// static
double const PreRankingInfo::kMaxDistMeters = 1000000000;
double const PreRankingInfo::kMaxDistMeters = 1e9;
} // namespace v2
} // namespace search

View file

@ -16,7 +16,8 @@ struct PreRankingInfo
// Distance from the feature to the current user's position.
double m_mwmDistanceToPosition = kMaxDistMeters;
// Tokens [m_startToken, m_endToken) match to the query.
// Tokens [m_startToken, m_endToken) match to the feature name or
// house number.
size_t m_startToken = 0;
size_t m_endToken = 0;

View file

@ -24,8 +24,7 @@ public:
protected:
// Adds a bunch of features as PreResult1.
void AddPreResults1(Geocoder::TResultList & results,
bool viewportSearch);
void AddPreResults1(Geocoder::TResultList & results, bool viewportSearch);
Geocoder m_geocoder;
};