diff --git a/indexer/categories_holder.cpp b/indexer/categories_holder.cpp index 4c222c9931..7c84017b3d 100644 --- a/indexer/categories_holder.cpp +++ b/indexer/categories_holder.cpp @@ -199,6 +199,27 @@ bool CategoriesHolder::GetNameByType(uint32_t type, int8_t locale, string & name return false; } +string CategoriesHolder::GetReadableFeatureType(uint32_t type, int8_t locale) const +{ + ASSERT_NOT_EQUAL(type, 0, ()); + uint8_t level = ftype::GetLevel(type); + ASSERT_GREATER(level, 0, ()); + + string name; + while (true) + { + if (GetNameByType(type, locale, name)) + return name; + + if (--level == 0) + break; + + ftype::TruncValue(type, level); + } + + return classif().GetReadableObjectName(type); +} + bool CategoriesHolder::IsTypeExist(uint32_t type) const { pair const range = m_type2cat.equal_range(type); diff --git a/indexer/categories_holder.hpp b/indexer/categories_holder.hpp index 0af32fb181..95e38c7750 100644 --- a/indexer/categories_holder.hpp +++ b/indexer/categories_holder.hpp @@ -80,6 +80,9 @@ public: /// @return false if no categories for type. bool GetNameByType(uint32_t type, int8_t locale, string & name) const; + /// @returns raw classificator type if it's not localized in categories.txt. + string GetReadableFeatureType(uint32_t type, int8_t locale) const; + bool IsTypeExist(uint32_t type) const; inline void Swap(CategoriesHolder & r) diff --git a/map/address_finder.cpp b/map/address_finder.cpp index 681ba372b3..9d9081b3c9 100644 --- a/map/address_finder.cpp +++ b/map/address_finder.cpp @@ -505,19 +505,9 @@ vector Framework::GetPrintableFeatureTypes(FeatureType const & ft) const feature::TypesHolder types(ft); types.SortBySpec(); // Try to add types from categories. + CategoriesHolder const & cats = GetDefaultCategories(); for (uint32_t type : types) - { - string s; - if (m_searchEngine->GetNameByType(type, locale, s)) - results.push_back(s); - } - // If nothing added - return raw classificator types. - if (results.empty()) - { - Classificator const & c = classif(); - for (uint32_t type : types) - results.push_back(c.GetReadableObjectName(type)); - } + results.push_back(cats.GetReadableFeatureType(type, locale)); return results; } diff --git a/search/intermediate_result.cpp b/search/intermediate_result.cpp index 5e22f6010b..70dbe51058 100644 --- a/search/intermediate_result.cpp +++ b/search/intermediate_result.cpp @@ -179,14 +179,14 @@ Result PreResult2::GenerateFinalResult(storage::CountryInfoGetter const & infoGe switch (m_resultType) { case RESULT_FEATURE: - return Result(m_id, GetCenter(), m_str, regionName, ReadableFeatureType(pCat, type, locale) + return Result(m_id, GetCenter(), m_str, regionName, pCat->GetReadableFeatureType(type, locale) #ifdef DEBUG + ' ' + strings::to_string(int(m_rank)) #endif , type, m_metadata); case RESULT_BUILDING: - return Result(GetCenter(), m_str, regionName, ReadableFeatureType(pCat, type, locale)); + return Result(GetCenter(), m_str, regionName, pCat->GetReadableFeatureType(type, locale)); default: ASSERT_EQUAL(m_resultType, RESULT_LATLON, ()); @@ -200,7 +200,7 @@ Result PreResult2::GeneratePointResult(storage::CountryInfoGetter const & infoGe { uint32_t const type = GetBestType(pTypes); return Result(m_id, GetCenter(), m_str, GetRegionName(infoGetter, type), - ReadableFeatureType(pCat, type, locale)); + pCat->GetReadableFeatureType(type, locale)); } // static @@ -298,20 +298,6 @@ uint32_t PreResult2::GetBestType(set const * pPrefferedTypes) const return type; } -string PreResult2::ReadableFeatureType(CategoriesHolder const * pCat, - uint32_t type, int8_t locale) const -{ - ASSERT_NOT_EQUAL(type, 0, ()); - if (pCat) - { - string name; - if (pCat->GetNameByType(type, locale, name)) - return name; - } - - return classif().GetReadableObjectName(type); -} - void PreResult2::RegionInfo::GetRegion(storage::CountryInfoGetter const & infoGetter, storage::CountryInfo & info) const { diff --git a/search/intermediate_result.hpp b/search/intermediate_result.hpp index 001c394925..00105836b6 100644 --- a/search/intermediate_result.hpp +++ b/search/intermediate_result.hpp @@ -115,9 +115,6 @@ public: private: bool IsEqualCommon(PreResult2 const & r) const; - string ReadableFeatureType(CategoriesHolder const * pCat, - uint32_t type, int8_t locale) const; - FeatureID m_id; feature::TypesHolder m_types; diff --git a/search/search_engine.cpp b/search/search_engine.cpp index 2f36a6d8a6..f441e7a8da 100644 --- a/search/search_engine.cpp +++ b/search/search_engine.cpp @@ -150,25 +150,6 @@ void Engine::SetSupportOldFormat(bool support) void Engine::ClearCaches() { PostTask(bind(&Engine::DoClearCaches, this)); } -bool Engine::GetNameByType(uint32_t type, int8_t locale, string & name) const -{ - uint8_t level = ftype::GetLevel(type); - ASSERT_GREATER(level, 0, ()); - - while (true) - { - if (m_categories.GetNameByType(type, locale, name)) - return true; - - if (--level == 0) - break; - - ftype::TruncValue(type, level); - } - - return false; -} - void Engine::SetRankPivot(SearchParams const & params, m2::RectD const & viewport, bool viewportSearch) { diff --git a/search/search_engine.hpp b/search/search_engine.hpp index d505204fec..cd464d09df 100644 --- a/search/search_engine.hpp +++ b/search/search_engine.hpp @@ -91,8 +91,6 @@ public: // Posts request to clear caches to the queue. void ClearCaches(); - bool GetNameByType(uint32_t type, int8_t lang, string & name) const; - private: // *ALL* following methods are executed on the m_loop thread.