diff --git a/qt/search_panel.cpp b/qt/search_panel.cpp index 26657edf7d..96d4cc7b41 100644 --- a/qt/search_panel.cpp +++ b/qt/search_panel.cpp @@ -129,7 +129,7 @@ void SearchPanel::OnSearchResult(ResultsT * res, int queryId) if (e.GetResultType() == ResultT::RESULT_FEATURE) { m_pTable->setItem(rowCount, 0, - create_item(QString::fromUtf8(e.GetFetureTypeAsString().c_str()))); + create_item(QString::fromUtf8(e.GetFeatureType()))); string strDist; bool const drawDir = MeasurementUtils::FormatDistance(e.GetDistanceFromCenter(), strDist); diff --git a/search/intermediate_result.cpp b/search/intermediate_result.cpp index 5244fd0317..57e3ed6524 100644 --- a/search/intermediate_result.cpp +++ b/search/intermediate_result.cpp @@ -117,7 +117,9 @@ bool IntermediateResult::LessViewportDistance(IntermediateResult const & r1, Int */ } -Result IntermediateResult::GenerateFinalResult(storage::CountryInfoGetter const * pInfo) const +Result IntermediateResult::GenerateFinalResult( + storage::CountryInfoGetter const * pInfo, + CategoriesT const * pCat) const { storage::CountryInfo info; m_region.GetRegion(pInfo, info); @@ -129,10 +131,12 @@ Result IntermediateResult::GenerateFinalResult(storage::CountryInfoGetter const #ifdef DEBUG + ' ' + strings::to_string(static_cast(m_searchRank)) #endif - , info.m_name, info.m_flag, m_type, m_rect, m_distance, m_direction); + , info.m_name, info.m_flag, GetFeatureType(pCat), + m_type, m_rect, m_distance, m_direction); case RESULT_LATLON: - return Result(m_str, info.m_name, info.m_flag, 0, m_rect, m_distance, m_direction); + return Result(m_str, info.m_name, info.m_flag, GetFeatureType(pCat), + 0, m_rect, m_distance, m_direction); default: ASSERT_EQUAL ( m_resultType, RESULT_CATEGORY, () ); @@ -262,6 +266,28 @@ string IntermediateResult::DebugPrint() const return res; } +string IntermediateResult::GetFeatureType(CategoriesT const * pCat) const +{ + if (pCat) + { + for (CategoriesT::const_iterator i = pCat->begin(); i != pCat->end(); ++i) + { + if (i->second == m_type) + return strings::ToUtf8(i->first); + } + } + + string s = classif().GetFullObjectName(m_type); + + // remove ending dummy symbol + ASSERT ( !s.empty(), () ); + s.resize(s.size()-1); + + // replace separator + replace(s.begin(), s.end(), '|', '-'); + return s; +} + void IntermediateResult::RegionInfo::GetRegion( storage::CountryInfoGetter const * pInfo, storage::CountryInfo & info) const { diff --git a/search/intermediate_result.hpp b/search/intermediate_result.hpp index 123d1f5943..a51d1b87b3 100644 --- a/search/intermediate_result.hpp +++ b/search/intermediate_result.hpp @@ -1,7 +1,10 @@ #pragma once #include "result.hpp" +#include "../base/string_utils.hpp" + #include "../std/shared_ptr.hpp" +#include "../std/map.hpp" class FeatureType; @@ -40,7 +43,9 @@ public: // For RESULT_CATEGORY. IntermediateResult(string const & name, int penalty); - Result GenerateFinalResult(storage::CountryInfoGetter const * pInfo) const; + typedef multimap CategoriesT; + Result GenerateFinalResult(storage::CountryInfoGetter const * pInfo, + CategoriesT const * pCat) const; /// Results order functor. /* @@ -85,6 +90,8 @@ private: m2::PointD const & featureCenter); static int ViewportDistance(m2::RectD const & viewport, m2::PointD const & p); + string GetFeatureType(CategoriesT const * pCat) const; + string m_str, m_completionString; class RegionInfo diff --git a/search/result.cpp b/search/result.cpp index 99110f7394..b3889bd9b3 100644 --- a/search/result.cpp +++ b/search/result.cpp @@ -1,16 +1,15 @@ #include "result.hpp" -#include "../indexer/classificator.hpp" - namespace search { -Result::Result(string const & str, string const & region, string const & flag, +Result::Result(string const & str, string const & region, + string const & flag, string const & type, uint32_t featureType, m2::RectD const & featureRect, double distanceFromCenter, double directionFromCenter) - : m_str(str), m_region(region), m_flag(flag), m_featureRect(featureRect), - m_featureType(featureType), + : m_str(str), m_region(region), m_flag(flag), m_type(type), + m_featureRect(featureRect), m_featureType(featureType), m_distanceFromCenter(distanceFromCenter), m_directionFromCenter(directionFromCenter) { } @@ -39,29 +38,6 @@ m2::PointD Result::GetFeatureCenter() const return m_featureRect.Center(); } -uint32_t Result::GetFetureType() const -{ - ASSERT_EQUAL(GetResultType(), RESULT_FEATURE, ()); - return m_featureType; -} - -string Result::GetFetureTypeAsString() const -{ - ASSERT_EQUAL(GetResultType(), RESULT_FEATURE, ()); - - ClassifObject const * p = classif().GetRoot(); - - uint8_t i = 0; - uint8_t v; - while (ftype::GetValue(m_featureType, i, v) && i < 2) - { - p = p->GetObject(v); - ++i; - } - - return p->GetName(); -} - double Result::GetDistanceFromCenter() const { ASSERT_EQUAL(GetResultType(), RESULT_FEATURE, ()); diff --git a/search/result.hpp b/search/result.hpp index bcd8d3149b..dbf7db24f0 100644 --- a/search/result.hpp +++ b/search/result.hpp @@ -16,7 +16,8 @@ public: RESULT_SUGGESTION }; - Result(string const & str, string const & region, string const & flag, + Result(string const & str, string const & region, + string const & flag, string const & type, uint32_t featureType, m2::RectD const & featureRect, double distanceFromCenter, double directionFromCenter); Result(string const & str, string const & suggestionStr); @@ -25,6 +26,7 @@ public: char const * GetString() const { return m_str.c_str(); } char const * GetRegionString() const { return m_region.c_str(); } char const * GetRegionFlag() const { return m_flag.c_str(); } + char const * GetFeatureType() const { return m_type.c_str(); } // Type of the result. ResultType GetResultType() const; @@ -35,10 +37,6 @@ public: // Center point of a feature, if GetResultType() == RESULT_FEATURE. m2::PointD GetFeatureCenter() const; - // Type of a feature, if GetResultType() == RESULT_FEATURE. - uint32_t GetFetureType() const; - string GetFetureTypeAsString() const; - // Distance from the center of the screen, if GetResultType() == RESULT_FEATURE. double GetDistanceFromCenter() const; @@ -49,7 +47,7 @@ public: char const * GetSuggestionString() const; private: - string m_str, m_region, m_flag; + string m_str, m_region, m_flag, m_type; m2::RectD m_featureRect; uint32_t m_featureType; double m_distanceFromCenter; diff --git a/search/search_query.cpp b/search/search_query.cpp index 4d69173105..72d35d6607 100644 --- a/search/search_query.cpp +++ b/search/search_query.cpp @@ -348,7 +348,7 @@ void Query::FlushResults(Results & res) for (size_t i = 0; i < indV.size(); ++i) { LOG(LDEBUG, (indV[i])); - res.AddResult(indV[i].get()->GenerateFinalResult(m_pInfoGetter)); + res.AddResult(indV[i].get()->GenerateFinalResult(m_pInfoGetter, m_pCategories)); } }