diff options
-rw-r--r-- | search/pre_ranker.hpp | 5 | ||||
-rw-r--r-- | search/processor.cpp | 45 | ||||
-rw-r--r-- | search/processor.hpp | 8 | ||||
-rw-r--r-- | search/ranker.hpp | 5 |
4 files changed, 33 insertions, 30 deletions
diff --git a/search/pre_ranker.hpp b/search/pre_ranker.hpp index 85b3d9ff5d..7c55c9e269 100644 --- a/search/pre_ranker.hpp +++ b/search/pre_ranker.hpp @@ -38,6 +38,11 @@ public: inline void Init(Params const & params) { m_params = params; } inline void SetViewportSearch(bool viewportSearch) { m_viewportSearch = viewportSearch; } + inline void SetAccuratePivotCenter(m2::PointD const & center) + { + m_params.m_accuratePivotCenter = center; + } + template <typename... TArgs> void Emplace(TArgs &&... args) { diff --git a/search/processor.cpp b/search/processor.cpp index 2d0dadd79d..7ea9df0b23 100644 --- a/search/processor.cpp +++ b/search/processor.cpp @@ -259,13 +259,12 @@ int8_t Processor::GetLanguage(int id) const { return m_ranker.GetLanguage(GetLangIndex(id)); } - -m2::PointD Processor::GetPivotPoint() const +m2::PointD Processor::GetPivotPoint(bool viewportSearch) const { m2::RectD const & viewport = m_viewport[CURRENT_V]; - if (viewport.IsPointInside(GetPosition())) - return GetPosition(); - return viewport.Center(); + if (viewportSearch || !viewport.IsPointInside(GetPosition())) + return viewport.Center(); + return GetPosition(); } m2::RectD Processor::GetPivotRect() const @@ -343,10 +342,10 @@ void Processor::ForEachCategoryType(StringSliceBase const & slice, ToDo && todo) void Processor::Search(Results & results, size_t limit) { Geocoder::Params geocoderParams; - InitGeocoderParams(geocoderParams); + InitGeocoderParams(geocoderParams, false /* viewportSearch */); - InitPreRanker(); - InitRanker(); + InitPreRanker(false /* viewportSearch */); + InitRanker(false /* viewportSearch */); if (m_tokens.empty()) m_ranker.SuggestStrings(results); @@ -358,19 +357,10 @@ void Processor::Search(Results & results, size_t limit) void Processor::SearchViewportPoints(Results & results) { Geocoder::Params geocoderParams; - InitParams(geocoderParams); - geocoderParams.m_mode = m_mode; - geocoderParams.m_pivot = m_viewport[CURRENT_V]; - - m_geocoder.SetParams(geocoderParams); + InitGeocoderParams(geocoderParams, true /* viewportSearch */); - PreRanker::Params preRankerParams; - preRankerParams.m_accuratePivotCenter = geocoderParams.m_pivot.Center(); - m_preRanker.Init(preRankerParams); - - Ranker::Params rankerParams; - rankerParams.m_accuratePivotCenter = geocoderParams.m_pivot.Center(); - m_ranker.Init(rankerParams); + InitPreRanker(true /* viewportSearch */); + InitRanker(true /* viewportSearch */); m_geocoder.GoInViewport(); m_ranker.FlushViewportResults(geocoderParams, results); @@ -590,23 +580,26 @@ void Processor::InitParams(QueryParams & params) params.m_langs.insert(GetLanguage(i)); } -void Processor::InitGeocoderParams(Geocoder::Params & params) +void Processor::InitGeocoderParams(Geocoder::Params & params, bool viewportSearch) { InitParams(params); params.m_mode = m_mode; - params.m_pivot = GetPivotRect(); + if (viewportSearch) + params.m_pivot = m_viewport[CURRENT_V]; + else + params.m_pivot = GetPivotRect(); m_geocoder.SetParams(params); } -void Processor::InitPreRanker() +void Processor::InitPreRanker(bool viewportSearch) { PreRanker::Params params; - params.m_accuratePivotCenter = GetPivotPoint(); + params.m_accuratePivotCenter = GetPivotPoint(viewportSearch); m_preRanker.Init(params); } -void Processor::InitRanker() +void Processor::InitRanker(bool viewportSearch) { Ranker::Params params; @@ -621,7 +614,7 @@ void Processor::InitRanker() params.m_tokens = m_tokens; params.m_prefix = m_prefix; params.m_categoryLocales = GetCategoryLocales(); - params.m_accuratePivotCenter = GetPivotPoint(); + params.m_accuratePivotCenter = GetPivotPoint(viewportSearch); m_ranker.Init(params); } diff --git a/search/processor.hpp b/search/processor.hpp index 696164d024..7369941a1f 100644 --- a/search/processor.hpp +++ b/search/processor.hpp @@ -103,9 +103,9 @@ public: //@} void InitParams(QueryParams & params); - void InitGeocoderParams(Geocoder::Params & params); - void InitPreRanker(); - void InitRanker(); + void InitGeocoderParams(Geocoder::Params & params, bool viewportSearch); + void InitPreRanker(bool viewportSearch); + void InitRanker(bool viewportSearch); void ClearCaches(); @@ -137,7 +137,7 @@ protected: template <typename ToDo> void ForEachCategoryType(StringSliceBase const & slice, ToDo && todo) const; - m2::PointD GetPivotPoint() const; + m2::PointD GetPivotPoint(bool viewportSearch) const; m2::RectD GetPivotRect() const; void SetViewportByIndex(m2::RectD const & viewport, size_t idx, bool forceUpdate); diff --git a/search/ranker.hpp b/search/ranker.hpp index c97b1c72c3..96037582bc 100644 --- a/search/ranker.hpp +++ b/search/ranker.hpp @@ -70,6 +70,11 @@ public: void Init(Params const & params); + inline void SetAccuratePivotCenter(m2::PointD const & center) + { + m_params.m_accuratePivotCenter = center; + } + bool IsResultExists(PreResult2 const & p, vector<IndexedValue> const & values); void MakePreResult2(Geocoder::Params const & params, vector<IndexedValue> & cont, |