From 4db1e2478309177d9f76f85256cb788527f24820 Mon Sep 17 00:00:00 2001 From: vng Date: Thu, 21 Jun 2012 00:15:11 -0700 Subject: [PATCH] [search] Better logic in emitting results. --- search/search_engine.cpp | 15 ++++++++++----- search/search_query.cpp | 2 ++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/search/search_engine.cpp b/search/search_engine.cpp index 8f83d5392c..e92593c3d0 100644 --- a/search/search_engine.cpp +++ b/search/search_engine.cpp @@ -246,6 +246,7 @@ void Engine::SearchAsync() { if (params.m_query.empty()) { + // Search for empty query only around viewport. if (params.m_validPos) { double arrR[] = { 500, 1000, 2000 }; @@ -266,11 +267,13 @@ void Engine::SearchAsync() { } - // Emit results in any way, even if search was canceled. - params.m_callback(res); + // Emit results even if search was canceled and we have something. + size_t const count = res.GetCount(); + if (!m_pQuery->IsCanceled() || count > 0) + params.m_callback(res); - // Make additional search in whole mwm when not enough results. - if (!m_pQuery->IsCanceled() && res.GetCount() < RESULTS_COUNT) + // Make additional search in whole mwm when not enough results (only for non-empty query). + if (!params.m_query.empty() && !m_pQuery->IsCanceled() && count < RESULTS_COUNT) { try { @@ -280,7 +283,9 @@ void Engine::SearchAsync() { } - params.m_callback(res); + // Emit if we have more results. + if (res.GetCount() > count) + params.m_callback(res); } } diff --git a/search/search_query.cpp b/search/search_query.cpp index f9dacda532..b42362daca 100644 --- a/search/search_query.cpp +++ b/search/search_query.cpp @@ -96,6 +96,8 @@ void Query::SetViewport(m2::RectD viewport[], size_t count) { ASSERT_LESS_OR_EQUAL(count, static_cast(RECTSCOUNT), ()); + m_cancel = false; + MWMVectorT mwmInfo; m_pIndex->GetMwmInfo(mwmInfo);