diff --git a/map/framework.cpp b/map/framework.cpp index 4e747f8ff1..84075c7549 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -1519,7 +1519,7 @@ size_t Framework::ShowSearchResults(search::Results const & results) return count; } - FillSearchResultsMarks(results); + FillSearchResultsMarks(true /* clear */, results); // Setup viewport according to results. m2::AnyRectD viewport = m_currentModelView.GlobalRect(); @@ -1565,17 +1565,21 @@ size_t Framework::ShowSearchResults(search::Results const & results) return count; } -void Framework::FillSearchResultsMarks(search::Results const & results) +void Framework::FillSearchResultsMarks(bool clear, search::Results const & results) { - FillSearchResultsMarks(results.begin(), results.end()); + FillSearchResultsMarks(clear, results.begin(), results.end()); } -void Framework::FillSearchResultsMarks(search::Results::ConstIter begin, +void Framework::FillSearchResultsMarks(bool clear, search::Results::ConstIter begin, search::Results::ConstIter end) { UserMarkNotificationGuard guard(m_bmManager, UserMark::Type::SEARCH); - guard.m_controller.SetIsVisible(true); - guard.m_controller.SetIsDrawable(true); + + auto & controller = guard.m_controller; + if (clear) + controller.Clear(); + controller.SetIsVisible(true); + controller.SetIsDrawable(true); for (auto it = begin; it != end; ++it) { @@ -1583,7 +1587,7 @@ void Framework::FillSearchResultsMarks(search::Results::ConstIter begin, if (!r.HasPoint()) continue; - auto mark = static_cast(guard.m_controller.CreateUserMark(r.GetFeatureCenter())); + auto mark = static_cast(controller.CreateUserMark(r.GetFeatureCenter())); ASSERT_EQUAL(mark->GetMarkType(), UserMark::Type::SEARCH, ()); auto const isFeature = r.GetResultType() == search::Result::RESULT_FEATURE; if (isFeature) @@ -3138,9 +3142,10 @@ void Framework::SetSearchDisplacementModeEnabled(bool enabled) SetDisplacementMode(DisplacementModeManager::SLOT_INTERACTIVE_SEARCH, enabled /* show */); } -void Framework::ShowViewportSearchResults(search::Results const & results) +void Framework::ShowViewportSearchResults(bool clear, search::Results::ConstIter begin, + search::Results::ConstIter end) { - FillSearchResultsMarks(results); + FillSearchResultsMarks(clear, begin, end); } void Framework::ClearViewportSearchResults() diff --git a/map/framework.hpp b/map/framework.hpp index 31a3c8ac95..8243bf6d4b 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -349,7 +349,8 @@ public: // SearchAPI::Delegate overrides: void RunUITask(function fn) override; void SetSearchDisplacementModeEnabled(bool enabled) override; - void ShowViewportSearchResults(search::Results const & results) override; + void ShowViewportSearchResults(bool clear, search::Results::ConstIter begin, + search::Results::ConstIter end) override; void ClearViewportSearchResults() override; boost::optional GetCurrentPosition() const override; bool ParseSearchQueryCommand(search::SearchParams const & params) override; @@ -548,8 +549,9 @@ public: size_t ShowSearchResults(search::Results const & results); - void FillSearchResultsMarks(search::Results const & results); - void FillSearchResultsMarks(search::Results::ConstIter begin, search::Results::ConstIter end); + void FillSearchResultsMarks(bool clear, search::Results const & results); + void FillSearchResultsMarks(bool clear, search::Results::ConstIter begin, + search::Results::ConstIter end); void ClearSearchResultsMarks(); list const & GetLastSearchQueries() const { return m_searchQuerySaver.Get(); } diff --git a/map/search_api.cpp b/map/search_api.cpp index ac18a44337..6938c6ba4c 100644 --- a/map/search_api.cpp +++ b/map/search_api.cpp @@ -213,13 +213,12 @@ bool SearchAPI::IsViewportSearchActive() const return !m_searchIntents[static_cast(Mode::Viewport)].m_params.m_query.empty(); } -void SearchAPI::ShowViewportSearchResults(Results const & results) +void SearchAPI::ShowViewportSearchResults(bool clear, search::Results::ConstIter begin, + search::Results::ConstIter end) { - return m_delegate.ShowViewportSearchResults(results); + return m_delegate.ShowViewportSearchResults(clear, begin, end); } -void SearchAPI::ClearViewportSearchResults() { return m_delegate.ClearViewportSearchResults(); } - bool SearchAPI::IsLocalAdsCustomer(Result const & result) const { return m_delegate.IsLocalAdsCustomer(result); diff --git a/map/search_api.hpp b/map/search_api.hpp index c41ab8e55a..e44d1b203d 100644 --- a/map/search_api.hpp +++ b/map/search_api.hpp @@ -63,7 +63,10 @@ public: virtual void SetSearchDisplacementModeEnabled(bool /* enabled */) {} - virtual void ShowViewportSearchResults(search::Results const & /* results */) {} + virtual void ShowViewportSearchResults(bool clear, search::Results::ConstIter begin, + search::Results::ConstIter end) + { + } virtual void ClearViewportSearchResults() {} @@ -120,8 +123,8 @@ public: void RunUITask(std::function fn) override; void SetHotelDisplacementMode() override; bool IsViewportSearchActive() const override; - void ShowViewportSearchResults(search::Results const & results) override; - void ClearViewportSearchResults() override; + void ShowViewportSearchResults(bool clear, search::Results::ConstIter begin, + search::Results::ConstIter end) override; bool IsLocalAdsCustomer(search::Result const & result) const override; private: diff --git a/search/search_integration_tests/interactive_search_test.cpp b/search/search_integration_tests/interactive_search_test.cpp index 472c94b7c0..4df1daea98 100644 --- a/search/search_integration_tests/interactive_search_test.cpp +++ b/search/search_integration_tests/interactive_search_test.cpp @@ -8,8 +8,13 @@ #include "base/macros.hpp" +#include +#include +#include + using namespace generator::tests_support; using namespace search::tests_support; +using namespace std; namespace search { @@ -35,13 +40,14 @@ public: bool IsViewportSearchActive() const override { return true; } - void ShowViewportSearchResults(Results const & results) override + void ShowViewportSearchResults(bool clear, Results::ConstIter begin, + Results::ConstIter end) override { - m_stats.m_numShownResults = results.GetCount(); + if (clear) + m_stats.m_numShownResults = 0; + m_stats.m_numShownResults += distance(begin, end); } - void ClearViewportSearchResults() override { m_stats.m_numShownResults = 0; } - private: Stats & m_stats; }; diff --git a/search/search_quality/assessment_tool/sample_view.cpp b/search/search_quality/assessment_tool/sample_view.cpp index 01d1f0a94d..aab4b4af3a 100644 --- a/search/search_quality/assessment_tool/sample_view.cpp +++ b/search/search_quality/assessment_tool/sample_view.cpp @@ -242,7 +242,7 @@ void SampleView::ShowNonFoundResults(std::vector const & void SampleView::ShowFoundResultsMarks(search::Results::ConstIter begin, search::Results::ConstIter end) { - m_framework.FillSearchResultsMarks(begin, end); + m_framework.FillSearchResultsMarks(false /* clear */, begin, end); } void SampleView::ShowNonFoundResultsMarks(std::vector const & results, diff --git a/search/viewport_search_callback.cpp b/search/viewport_search_callback.cpp index 08ce4e7c3c..249fbad687 100644 --- a/search/viewport_search_callback.cpp +++ b/search/viewport_search_callback.cpp @@ -19,7 +19,6 @@ void ViewportSearchCallback::operator()(Results const & results) { ASSERT_LESS_OR_EQUAL(m_lastResultsSize, results.GetCount(), ()); m_hotelsClassif.Add(results.begin() + m_lastResultsSize, results.end()); - m_lastResultsSize = results.GetCount(); if (!m_hotelsModeSet && m_hotelsClassif.IsHotelResults()) { @@ -49,20 +48,19 @@ void ViewportSearchCallback::operator()(Results const & results) auto & delegate = m_delegate; bool const firstCall = m_firstCall; - m_delegate.RunUITask([&delegate, firstCall, results]() { + auto const lastResultsSize = m_lastResultsSize; + m_delegate.RunUITask([&delegate, firstCall, results, lastResultsSize]() { if (!delegate.IsViewportSearchActive()) return; - - if (firstCall) - delegate.ClearViewportSearchResults(); - - delegate.ShowViewportSearchResults(results); + delegate.ShowViewportSearchResults(firstCall, results.begin() + lastResultsSize, + results.end()); }); } + m_lastResultsSize = results.GetCount(); + m_firstCall = false; + if (m_onResults) m_onResults(results); - - m_firstCall = false; } } // namespace search diff --git a/search/viewport_search_callback.hpp b/search/viewport_search_callback.hpp index 09a5332c2f..100a624a47 100644 --- a/search/viewport_search_callback.hpp +++ b/search/viewport_search_callback.hpp @@ -23,8 +23,8 @@ public: virtual void RunUITask(std::function fn) = 0; virtual void SetHotelDisplacementMode() = 0; virtual bool IsViewportSearchActive() const = 0; - virtual void ShowViewportSearchResults(Results const & results) = 0; - virtual void ClearViewportSearchResults() = 0; + virtual void ShowViewportSearchResults(bool clear, Results::ConstIter begin, + Results::ConstIter end) = 0; }; using OnResults = SearchParams::OnResults;