diff options
author | Maxim Pimenov <m@maps.me> | 2016-07-01 14:09:31 +0300 |
---|---|---|
committer | Maxim Pimenov <m@maps.me> | 2016-07-07 12:08:32 +0300 |
commit | ad44499b38ba56ae87e788f1da3c3b54e58718b1 (patch) | |
tree | bb8c634c6e4e214db369972daa2dab4eea0185fb /search/pre_ranker.cpp | |
parent | 092198b2f529ac96754c030c7e806998eddaabfa (diff) |
[search] Inverted a dependency: Ranker does not call PreRanker any longer.
Also, upgraded clang-format from 3.7.0 to 3.9.0 which resulted in a new
way of formatiing lambdas.
Diffstat (limited to 'search/pre_ranker.cpp')
-rw-r--r-- | search/pre_ranker.cpp | 65 |
1 files changed, 59 insertions, 6 deletions
diff --git a/search/pre_ranker.cpp b/search/pre_ranker.cpp index f333b5efcd..3e298062e6 100644 --- a/search/pre_ranker.cpp +++ b/search/pre_ranker.cpp @@ -1,7 +1,11 @@ #include "search/pre_ranker.hpp" +#include "search/dummy_rank_table.hpp" #include "search/pre_ranking_info.hpp" +#include "indexer/mwm_set.hpp" +#include "indexer/rank_table.hpp" + #include "base/stl_helpers.hpp" #include "std/iterator.hpp" @@ -42,12 +46,52 @@ struct ComparePreResult1 }; } // namespace -PreRanker::PreRanker(size_t limit) : m_limit(limit) {} +PreRanker::PreRanker(Index const & index, Ranker & ranker, size_t limit) + : m_index(index), m_ranker(ranker), m_limit(limit), m_pivotFeatures(index) +{ +} + +void PreRanker::FillMissingFieldsInResults() +{ + MwmSet::MwmId mwmId; + MwmSet::MwmHandle mwmHandle; + unique_ptr<RankTable> rankTable = make_unique<DummyRankTable>(); + + ForEach([&](PreResult1 & r) { + FeatureID const & id = r.GetId(); + PreRankingInfo & info = r.GetInfo(); + if (id.m_mwmId != mwmId) + { + mwmId = id.m_mwmId; + mwmHandle = m_index.GetMwmHandleById(mwmId); + rankTable.reset(); + if (mwmHandle.IsAlive()) + { + rankTable = RankTable::Load(mwmHandle.GetValue<MwmValue>()->m_cont); + } + if (!rankTable) + rankTable = make_unique<DummyRankTable>(); + } + + info.m_rank = rankTable->Get(id.m_index); + }); + + if (Size() <= Limit()) + return; + + m_pivotFeatures.SetPosition(m_params.m_accuratePivotCenter, m_params.m_scale); + ForEach([&](PreResult1 & r) { + FeatureID const & id = r.GetId(); + PreRankingInfo & info = r.GetInfo(); + + info.m_distanceToPivot = m_pivotFeatures.GetDistanceToFeatureMeters(id); + }); +} void PreRanker::Filter(bool viewportSearch) { using TSet = set<PreResult1, LessFeatureID>; - TSet theSet; + TSet filtered; sort(m_results.begin(), m_results.end(), ComparePreResult1()); m_results.erase(unique(m_results.begin(), m_results.end(), my::EqualsBy(&PreResult1::GetId)), @@ -88,17 +132,26 @@ void PreRanker::Filter(bool viewportSearch) minstd_rand engine; shuffle(b, e, engine); } - theSet.insert(m_results.begin(), m_results.begin() + min(m_results.size(), m_limit)); + filtered.insert(m_results.begin(), m_results.begin() + min(m_results.size(), m_limit)); if (!viewportSearch) { size_t n = min(m_results.size(), m_limit); nth_element(m_results.begin(), m_results.begin() + n, m_results.end(), &PreResult1::LessRank); - theSet.insert(m_results.begin(), m_results.begin() + n); + filtered.insert(m_results.begin(), m_results.begin() + n); } - m_results.reserve(theSet.size()); + m_results.reserve(filtered.size()); m_results.clear(); - copy(theSet.begin(), theSet.end(), back_inserter(m_results)); + copy(filtered.begin(), filtered.end(), back_inserter(m_results)); } + +void PreRanker::FinalizeResults() +{ + FillMissingFieldsInResults(); + Filter(m_params.m_viewportSearch); + m_ranker.SetPreResults1(&m_results); +} + +void PreRanker::ClearCaches() { m_pivotFeatures.Clear(); } } // namespace search |