From b4588b780bd0d1db24819e83252dab2c57138036 Mon Sep 17 00:00:00 2001 From: tatiana-yan Date: Thu, 13 Aug 2020 12:37:05 +0300 Subject: [PATCH] [search] RankerResultMaker minor refactoring. --- search/ranker.cpp | 65 ++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/search/ranker.cpp b/search/ranker.cpp index c6381e6195..7464b7e452 100644 --- a/search/ranker.cpp +++ b/search/ranker.cpp @@ -305,13 +305,36 @@ private: class RankerResultMaker { - Ranker & m_ranker; - DataSource const & m_dataSource; - Geocoder::Params const & m_params; - storage::CountryInfoGetter const & m_infoGetter; +public: + RankerResultMaker(Ranker & ranker, DataSource const & dataSource, + storage::CountryInfoGetter const & infoGetter, Geocoder::Params const & params) + : m_ranker(ranker), m_dataSource(dataSource), m_infoGetter(infoGetter), m_params(params) + { + } - unique_ptr m_loader; + optional operator()(PreRankerResult const & preRankerResult) + { + m2::PointD center; + string name; + string country; + auto ft = LoadFeature(preRankerResult.GetId(), center, name, country); + if (!ft) + return {}; + + RankerResult r(*ft, center, m_ranker.m_params.m_pivot, name, country); + + search::RankingInfo info; + InitRankingInfo(*ft, center, preRankerResult, info); + 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()); + + return r; + } + +private: unique_ptr LoadFeature(FeatureID const & id) { if (!m_loader || m_loader->GetId() != id.m_mwmId) @@ -512,34 +535,12 @@ class RankerResultMaker } } -public: - RankerResultMaker(Ranker & ranker, DataSource const & dataSource, - storage::CountryInfoGetter const & infoGetter, Geocoder::Params const & params) - : m_ranker(ranker), m_dataSource(dataSource), m_params(params), m_infoGetter(infoGetter) - { - } + Ranker & m_ranker; + DataSource const & m_dataSource; + storage::CountryInfoGetter const & m_infoGetter; + Geocoder::Params const & m_params; - optional operator()(PreRankerResult const & preRankerResult) - { - m2::PointD center; - string name; - string country; - - auto ft = LoadFeature(preRankerResult.GetId(), center, name, country); - if (!ft) - return {}; - - RankerResult r(*ft, center, m_ranker.m_params.m_pivot, name, country); - - search::RankingInfo info; - InitRankingInfo(*ft, center, preRankerResult, info); - 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()); - - return r; - } + unique_ptr m_loader; }; Ranker::Ranker(DataSource const & dataSource, CitiesBoundariesTable const & boundariesTable,