diff --git a/search/engine.cpp b/search/engine.cpp index e7a7809e6c..a761e3e556 100644 --- a/search/engine.cpp +++ b/search/engine.cpp @@ -284,6 +284,7 @@ void Engine::DoSearch(SearchParams const & params, m2::RectD const & viewport, bool const viewportSearch = params.GetMode() == Mode::Viewport; // Initialize query processor. + processor.Reset(); processor.Init(viewportSearch); handle->Attach(processor); MY_SCOPE_GUARD(detach, [&handle] diff --git a/search/geocoder.cpp b/search/geocoder.cpp index f8e3b7c9e6..5157445e91 100644 --- a/search/geocoder.cpp +++ b/search/geocoder.cpp @@ -404,19 +404,20 @@ void UniteCBVs(vector> & cbvs) Geocoder::Params::Params() : m_mode(Mode::Everywhere), m_accuratePivotCenter(0, 0) {} // Geocoder::Geocoder ------------------------------------------------------------------------------ -Geocoder::Geocoder(Index & index, storage::CountryInfoGetter const & infoGetter) +Geocoder::Geocoder(Index & index, storage::CountryInfoGetter const & infoGetter, + my::Cancellable const & cancellable) : m_index(index) , m_infoGetter(infoGetter) + , m_cancellable(cancellable) , m_numTokens(0) , m_model(SearchModel::Instance()) - , m_pivotRectsCache(kPivotRectsCacheSize, static_cast(*this), - Processor::kMaxViewportRadiusM) - , m_localityRectsCache(kLocalityRectsCacheSize, static_cast(*this)) + , m_pivotRectsCache(kPivotRectsCacheSize, m_cancellable, Processor::kMaxViewportRadiusM) + , m_localityRectsCache(kLocalityRectsCacheSize, m_cancellable) , m_pivotFeatures(index) , m_villages(nullptr) , m_filter(nullptr) , m_matcher(nullptr) - , m_finder(static_cast(*this)) + , m_finder(m_cancellable) , m_lastMatchedRegion(nullptr) , m_preRanker(nullptr) { @@ -552,7 +553,6 @@ void Geocoder::GoImpl(PreRanker & preRanker, vector> & infos // MatchAroundPivot() should always be matched in mwms // intersecting with position and viewport. - auto const & cancellable = static_cast(*this); auto processCountry = [&](size_t index, unique_ptr context) { ASSERT(context, ()); @@ -572,7 +572,7 @@ void Geocoder::GoImpl(PreRanker & preRanker, vector> & infos if (it == m_matchersCache.end()) { it = m_matchersCache.insert(make_pair(m_context->GetId(), make_unique( - m_index, cancellable))) + m_index, m_cancellable))) .first; } m_matcher = it->second.get(); @@ -665,9 +665,8 @@ void Geocoder::PrepareAddressFeatures() for (size_t i = 0; i < m_numTokens; ++i) { PrepareRetrievalParams(i, i + 1); - m_addressFeatures[i] = - RetrieveAddressFeatures(m_context->GetId(), m_context->m_value, - static_cast(*this), m_retrievalParams); + m_addressFeatures[i] = RetrieveAddressFeatures(m_context->GetId(), m_context->m_value, + m_cancellable, m_retrievalParams); ASSERT(m_addressFeatures[i], ()); } } @@ -1504,8 +1503,7 @@ unique_ptr Geocoder::LoadCategories( for_each(categories.begin(), categories.end(), [&](strings::UniString const & category) { m_retrievalParams.m_tokens[0][0] = category; - auto cbv = RetrieveAddressFeatures(context.GetId(), context.m_value, - static_cast(*this), + auto cbv = RetrieveAddressFeatures(context.GetId(), context.m_value, m_cancellable, m_retrievalParams); if (!coding::CompressedBitVector::IsEmpty(cbv)) cbvs.push_back(move(cbv)); @@ -1546,8 +1544,7 @@ unique_ptr Geocoder::LoadVillages(MwmContext & cont unique_ptr Geocoder::RetrievePostcodeFeatures( MwmContext const & context, TokenSlice const & slice) { - return ::search::RetrievePostcodeFeatures(context.GetId(), context.m_value, - static_cast(*this), slice); + return ::search::RetrievePostcodeFeatures(context.GetId(), context.m_value, m_cancellable, slice); } coding::CompressedBitVector const * Geocoder::RetrieveGeometryFeatures(MwmContext const & context, diff --git a/search/geocoder.hpp b/search/geocoder.hpp index c4c703d8d7..439784a742 100644 --- a/search/geocoder.hpp +++ b/search/geocoder.hpp @@ -70,7 +70,7 @@ class TokenSlice; // part is to find all paths through this layered graph and report all // features from the lowest layer, that are reachable from the // highest layer. -class Geocoder : public my::Cancellable +class Geocoder { public: struct Params : public QueryParams @@ -146,9 +146,10 @@ public: #endif }; - Geocoder(Index & index, storage::CountryInfoGetter const & infoGetter); + Geocoder(Index & index, storage::CountryInfoGetter const & infoGetter, + my::Cancellable const & cancellable); - ~Geocoder() override; + ~Geocoder(); // Sets search query params. void SetParams(Params const & params); @@ -215,7 +216,7 @@ private: // Throws CancelException if cancelled. inline void BailIfCancelled() { - ::search::BailIfCancelled(static_cast(*this)); + ::search::BailIfCancelled(m_cancellable); } // Tries to find all countries and states in a search query and then @@ -312,6 +313,8 @@ private: storage::CountryInfoGetter const & m_infoGetter; + my::Cancellable const & m_cancellable; + // Geocoder params. Params m_params; diff --git a/search/processor.cpp b/search/processor.cpp index 7acd509445..d51bc74261 100644 --- a/search/processor.cpp +++ b/search/processor.cpp @@ -95,14 +95,10 @@ ftypes::Type GetLocalityIndex(feature::TypesHolder const & types) case NONE: case COUNTRY: case STATE: - case CITY: - return type; - case TOWN: - return CITY; - case VILLAGE: - return NONE; - case LOCALITY_COUNT: - return type; + case CITY: return type; + case TOWN: return CITY; + case VILLAGE: return NONE; + case LOCALITY_COUNT: return type; } } @@ -231,7 +227,7 @@ Processor::Processor(Index & index, CategoriesHolder const & categories, , m_viewportSearch(false) , m_keepHouseNumberInQuery(true) , m_preRanker(kPreResultsCount) - , m_geocoder(index, infoGetter) + , m_geocoder(index, infoGetter, static_cast(*this)) , m_reverseGeocoder(index) { // Initialize keywords scorer. @@ -249,8 +245,6 @@ Processor::Processor(Index & index, CategoriesHolder const & categories, void Processor::Init(bool viewportSearch) { - Reset(); - m_tokens.clear(); m_prefix.clear(); m_preRanker.Clear(); @@ -259,12 +253,7 @@ void Processor::Init(bool viewportSearch) void Processor::SetViewport(m2::RectD const & viewport, bool forceUpdate) { - Reset(); - - TMWMVector mwmsInfo; - m_index.GetMwmsInfo(mwmsInfo); - - SetViewportByIndex(mwmsInfo, viewport, CURRENT_V, forceUpdate); + SetViewportByIndex(viewport, CURRENT_V, forceUpdate); } void Processor::SetPreferredLocale(string const & locale) @@ -403,8 +392,7 @@ m2::RectD Processor::GetPivotRect() const return NormalizeViewport(viewport); } -void Processor::SetViewportByIndex(TMWMVector const & mwmsInfo, m2::RectD const & viewport, - size_t idx, bool forceUpdate) +void Processor::SetViewportByIndex(m2::RectD const & viewport, size_t idx, bool forceUpdate) { ASSERT(idx < COUNT_V, (idx)); @@ -1136,7 +1124,8 @@ void Processor::InitParams(QueryParams & params) // Add names of categories (and synonyms). Classificator const & c = classif(); - auto addSyms = [&](size_t i, uint32_t t) { + auto addSyms = [&](size_t i, uint32_t t) + { QueryParams::TSynonymsVector & v = params.GetTokens(i); uint32_t const index = c.GetIndexForType(t); @@ -1178,10 +1167,6 @@ void Processor::ClearCaches() m_geocoder.ClearCaches(); } -void Processor::Reset() { m_geocoder.Reset(); } - -void Processor::Cancel() { m_geocoder.Cancel(); } - void Processor::SuggestStrings(Results & res) { if (m_prefix.empty() || !m_suggestsEnabled) diff --git a/search/processor.hpp b/search/processor.hpp index c91a574e4d..a568e43991 100644 --- a/search/processor.hpp +++ b/search/processor.hpp @@ -117,10 +117,6 @@ public: void ClearCaches(); - // my::Cancellable overrides: - void Reset() override; - void Cancel() override; - protected: enum ViewportID { @@ -151,8 +147,7 @@ protected: m2::PointD GetPivotPoint() const; m2::RectD GetPivotRect() const; - void SetViewportByIndex(TMWMVector const & mwmsInfo, m2::RectD const & viewport, size_t idx, - bool forceUpdate); + void SetViewportByIndex(m2::RectD const & viewport, size_t idx, bool forceUpdate); void ClearCache(size_t ind); template