diff --git a/map/framework.cpp b/map/framework.cpp index a5802e27cb..b292ea5d19 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -1071,14 +1071,25 @@ bool Framework::Search(search::SearchParams const & params) return true; } +bool Framework::GetGroupCountryIdFromFeature(FeatureType const & ft, string & name) const +{ + static vector const langIndices = {StringUtf8Multilang::GetLangIndex("en"), + FeatureType::DEFAULT_LANG, + StringUtf8Multilang::kInternationalCode}; + + for (auto const langIndex : langIndices) + { + if (!ft.GetName(langIndex, name)) + continue; + if (Storage().IsCoutryIdCountryTreeInnerNode(name)) + return true; + } + return false; +} + bool Framework::SearchInDownloader(DownloaderSearchParams const & params) { - // @TODO(bykoianko) It's necessary to implement searching in Storage - // for group and leaf mwms based on country tree. - - // Searching based on World.mwm. search::SearchParams searchParam; - searchParam.m_query = params.m_query; searchParam.m_inputLocale = params.m_inputLocale; searchParam.SetMode(search::Mode::World); @@ -1091,6 +1102,27 @@ bool Framework::SearchInDownloader(DownloaderSearchParams const & params) { if (!it->HasPoint()) continue; + + if (it->GetResultType() != search::Result::RESULT_LATLON) + { + FeatureID const & fid = it->GetFeatureID(); + Index::FeaturesLoaderGuard loader(m_model.GetIndex(), fid.m_mwmId); + FeatureType ft; + loader.GetFeatureByIndex(fid.m_index, ft); + ftypes::Type const type = ftypes::IsLocalityChecker::Instance().GetType(ft); + + if (type == ftypes::COUNTRY || type == ftypes::STATE) + { + string groupFeatureName; + if (GetGroupCountryIdFromFeature(ft, groupFeatureName)) + { + downloaderSearchResults.m_results.emplace_back(groupFeatureName, + it->GetString() /* m_matchedName */); + continue; + } + } + } + auto const & mercator = it->GetFeatureCenter(); TCountryId const & countryId = CountryInfoGetter().GetRegionCountryId(mercator); if (countryId == kInvalidCountryId) diff --git a/map/framework.hpp b/map/framework.hpp index 23d873ebe8..956c7d1e21 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -214,6 +214,7 @@ public: //@} storage::Storage & Storage() { return m_storage; } + storage::Storage const & Storage() const { return m_storage; } storage::CountryInfoGetter & CountryInfoGetter() { return *m_infoGetter; } /// @name Bookmarks, Tracks and other UserMarks @@ -389,6 +390,7 @@ private: void OnUpdateGpsTrackPointsCallback(vector> && toAdd, pair const & toRemove); + bool GetGroupCountryIdFromFeature(FeatureType const & ft, string & name) const; public: using TSearchRequest = search::QuerySaver::TSearchRequest; diff --git a/storage/storage.cpp b/storage/storage.cpp index beb7683b85..04f52d3a6a 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -308,6 +308,14 @@ bool Storage::IsCoutryIdCountryTreeLeaf(TCountryId const & countryId) const return node != nullptr && node->ChildrenCount() == 0 /* countryId is a leaf. */; } +bool Storage::IsCoutryIdCountryTreeInnerNode(TCountryId const & countryId) const +{ + if (!IsCountryIdValid(countryId)) + return false; + TCountryTreeNode const * const node = m_countries.FindFirst(countryId); + return node != nullptr && node->ChildrenCount() != 0 /* countryId is an inner node. */; +} + TLocalAndRemoteSize Storage::CountrySizeInBytes(TCountryId const & countryId, MapOptions opt) const { QueuedCountry const * queuedCountry = FindCountryInQueue(countryId); diff --git a/storage/storage.hpp b/storage/storage.hpp index 3360acbca3..4bc45d25a4 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -434,6 +434,7 @@ public: TCountryId FindCountryIdByFile(string const & name) const; bool IsCoutryIdCountryTreeLeaf(TCountryId const & countryId) const; + bool IsCoutryIdCountryTreeInnerNode(TCountryId const & countryId) const; TLocalAndRemoteSize CountrySizeInBytes(TCountryId const & countryId, MapOptions opt) const; platform::CountryFile const & GetCountryFile(TCountryId const & countryId) const;