diff options
author | vng <viktor.govako@gmail.com> | 2015-09-10 14:53:25 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 03:04:55 +0300 |
commit | d167c19e2b203f94e440dd179f7248f495e978ce (patch) | |
tree | 76dd5be55d7cfd85139c474b6880d8f0e120894c /search | |
parent | 6e1be81f7d23035b3e981d57459c929e6e93cf3f (diff) |
[search] Viewport search results now can be showed in the table. Need to pass region param.
Diffstat (limited to 'search')
-rw-r--r-- | search/intermediate_result.cpp | 61 | ||||
-rw-r--r-- | search/intermediate_result.hpp | 14 | ||||
-rw-r--r-- | search/result.cpp | 21 | ||||
-rw-r--r-- | search/result.hpp | 7 | ||||
-rw-r--r-- | search/search_query.cpp | 8 |
5 files changed, 65 insertions, 46 deletions
diff --git a/search/intermediate_result.cpp b/search/intermediate_result.cpp index cf59edef33..1d9a66a546 100644 --- a/search/intermediate_result.cpp +++ b/search/intermediate_result.cpp @@ -186,54 +186,59 @@ namespace m_types[i] = c.GetTypeByPath(vector<string>(arr[i], arr[i] + 2)); } - bool IsContinent(uint32_t t) const { return (m_types[0] == t); } - bool IsCountry(uint32_t t) const { return (m_types[1] == t); } + bool IsSkip(uint32_t type) const + { + for (uint8_t t : m_types) + if (t == type) + return true; + return false; + } }; } -Result PreResult2::GenerateFinalResult( - storage::CountryInfoGetter const * pInfo, - CategoriesHolder const * pCat, - set<uint32_t> const * pTypes, - int8_t locale) const +string PreResult2::GetRegionName(storage::CountryInfoGetter const * pInfo, uint32_t fType) const { - storage::CountryInfo info; - - uint32_t const type = GetBestType(); - static SkipRegionInfo const checker; - if (!checker.IsContinent(type)) - { - m_region.GetRegion(pInfo, info); + if (checker.IsSkip(fType)) + return string(); - if (checker.IsCountry(type)) - info.m_name.clear(); - } + storage::CountryInfo info; + m_region.GetRegion(pInfo, info); + return move(info.m_name); +} + +Result PreResult2::GenerateFinalResult(storage::CountryInfoGetter const * pInfo, + CategoriesHolder const * pCat, + set<uint32_t> const * pTypes, int8_t locale) const +{ + uint32_t const type = GetBestType(pTypes); + string const regionName = GetRegionName(pInfo, type); switch (m_resultType) { case RESULT_FEATURE: - return Result(m_id, GetCenter(), m_str, info.m_name, ReadableFeatureType(pCat, pTypes, locale) + return Result(m_id, GetCenter(), m_str, regionName, ReadableFeatureType(pCat, type, locale) #ifdef DEBUG + ' ' + strings::to_string(int(m_rank)) #endif , type, m_metadata); case RESULT_BUILDING: - return Result(GetCenter(), m_str, info.m_name, ReadableFeatureType(pCat, pTypes, locale)); + return Result(GetCenter(), m_str, regionName, ReadableFeatureType(pCat, type, locale)); default: ASSERT_EQUAL(m_resultType, RESULT_LATLON, ()); - return Result(GetCenter(), m_str, info.m_name, string()); + return Result(GetCenter(), m_str, regionName, string()); } } -Result PreResult2::GeneratePointResult( - CategoriesHolder const * pCat, - set<uint32_t> const * pTypes, - int8_t locale) const +Result PreResult2::GeneratePointResult(storage::CountryInfoGetter const * pInfo, + CategoriesHolder const * pCat, + set<uint32_t> const * pTypes, int8_t locale) const { - return Result(GetCenter(), m_str, ReadableFeatureType(pCat, pTypes, locale)); + uint8_t const type = GetBestType(pTypes); + return Result(m_id, GetCenter(), m_str, GetRegionName(pInfo, type), + ReadableFeatureType(pCat, type, locale)); } bool PreResult2::LessRank(PreResult2 const & r1, PreResult2 const & r2) @@ -334,13 +339,9 @@ uint32_t PreResult2::GetBestType(set<uint32_t> const * pPrefferedTypes) const } string PreResult2::ReadableFeatureType(CategoriesHolder const * pCat, - set<uint32_t> const * pTypes, - int8_t locale) const + uint32_t type, int8_t locale) const { - // @TODO print all types, not just one - uint32_t const type = GetBestType(pTypes); ASSERT_NOT_EQUAL(type, 0, ()); - if (pCat) { string name; diff --git a/search/intermediate_result.hpp b/search/intermediate_result.hpp index 08a96988de..f395141e2a 100644 --- a/search/intermediate_result.hpp +++ b/search/intermediate_result.hpp @@ -85,12 +85,11 @@ public: /// @param[in] lang Current system language. Result GenerateFinalResult(storage::CountryInfoGetter const * pInfo, CategoriesHolder const * pCat, - set<uint32_t> const * pTypes, - int8_t lang) const; + set<uint32_t> const * pTypes, int8_t locale) const; - Result GeneratePointResult(CategoriesHolder const * pCat, - set<uint32_t> const * pTypes, - int8_t locale) const; + Result GeneratePointResult(storage::CountryInfoGetter const * pInfo, + CategoriesHolder const * pCat, + set<uint32_t> const * pTypes, int8_t locale) const; static bool LessRank(PreResult2 const & r1, PreResult2 const & r2); static bool LessDistance(PreResult2 const & r1, PreResult2 const & r2); @@ -132,8 +131,7 @@ private: bool IsEqualCommon(PreResult2 const & r) const; string ReadableFeatureType(CategoriesHolder const * pCat, - set<uint32_t> const * pTypes, - int8_t locale) const; + uint32_t type, int8_t locale) const; FeatureID m_id; feature::TypesHolder m_types; @@ -157,6 +155,8 @@ private: storage::CountryInfo & info) const; } m_region; + string GetRegionName(storage::CountryInfoGetter const * pInfo, uint32_t fType) const; + m2::PointD GetCenter() const { return m_region.m_point; } double m_distance; diff --git a/search/result.cpp b/search/result.cpp index 6f9a9b79fa..ae57ad26c3 100644 --- a/search/result.cpp +++ b/search/result.cpp @@ -15,14 +15,25 @@ Result::Result(FeatureID const & id, m2::PointD const & pt, string const & str, , m_featureType(featureType) , m_metadata(meta) { - // Features with empty names can be found after suggestion. - if (m_str.empty()) - m_str = type; + PatchNameIfNeeded(); +} + +Result::Result(FeatureID const & id, m2::PointD const & pt, string const & str, + string const & region, string const & type) + : m_id(id) + , m_center(pt) + , m_str(str) + , m_region(region) + , m_type(type) +{ + PatchNameIfNeeded(); } -Result::Result(m2::PointD const & pt, string const & str, string const & type) - : m_center(pt), m_str(str), m_type(type) +void Result::PatchNameIfNeeded() { + // Features with empty names can be found after suggestion. + if (m_str.empty()) + m_str = m_type; } Result::Result(m2::PointD const & pt, string const & str, diff --git a/search/result.hpp b/search/result.hpp index 57c8605577..abd4c92a45 100644 --- a/search/result.hpp +++ b/search/result.hpp @@ -39,8 +39,9 @@ public: Result(FeatureID const & id, m2::PointD const & pt, string const & str, string const & region, string const & type, uint32_t featureType, Metadata const & meta); - /// Used for point-like results on the map. - Result(m2::PointD const & pt, string const & str, string const & type); + /// Used for generation viewport results. + Result(FeatureID const & id, m2::PointD const & pt, string const & str, + string const & region, string const & type); /// @param[in] type Empty string - RESULT_LATLON, building address otherwise. Result(m2::PointD const & pt, string const & str, @@ -91,6 +92,8 @@ public: void AppendCity(string const & name); private: + void PatchNameIfNeeded(); + FeatureID m_id; m2::PointD m_center; string m_str, m_region, m_type; diff --git a/search/search_query.cpp b/search/search_query.cpp index d8412b59fc..2487b0f134 100644 --- a/search/search_query.cpp +++ b/search/search_query.cpp @@ -825,8 +825,8 @@ void Query::SearchViewportPoints(Results & res) if (IsCancelled()) break; - res.AddResultNoChecks( - (*(indV[i])).GeneratePointResult(m_pCategories, &m_prefferedTypes, m_currentLocaleCode)); + res.AddResultNoChecks((*(indV[i])).GeneratePointResult(m_pInfoGetter, m_pCategories, + &m_prefferedTypes, m_currentLocaleCode)); } } @@ -942,6 +942,10 @@ void Query::ProcessSuggestions(vector<T> & vec, Results & res) const void Query::AddResultFromTrie(TTrieValue const & val, MwmSet::MwmId const & mwmID, ViewportID vID /*= DEFAULT_V*/) { + // If we are in viewport search mode, check actual "point-in-viewport" criteria. + if (m_queuesCount == 1 && !m_viewport[CURRENT_V].IsPointInside(val.m_pt)) + return; + impl::PreResult1 res(FeatureID(mwmID, val.m_featureId), val.m_rank, val.m_pt, GetPosition(vID), vID); |