From c0b3220afbd3dfcfa1ee3efe8b7ad92c558a2f91 Mon Sep 17 00:00:00 2001 From: vng Date: Wed, 17 Oct 2012 03:14:33 +0300 Subject: Return better feature type than "building" if feature has many choices. --- indexer/feature_data.cpp | 32 +++++++++++++++++++++++++++++ indexer/feature_data.hpp | 3 +++ iphone/Maps/Classes/MapViewController.mm | 6 +++--- iphone/Maps/Classes/SearchVC.mm | 4 ++-- map/address_finder.cpp | 35 +++++++++++++++++++++++++++++++- map/framework.hpp | 3 +++ search/intermediate_result.cpp | 3 ++- 7 files changed, 79 insertions(+), 7 deletions(-) diff --git a/indexer/feature_data.cpp b/indexer/feature_data.cpp index 6decfe5e83..868c7aeb08 100644 --- a/indexer/feature_data.cpp +++ b/indexer/feature_data.cpp @@ -7,6 +7,10 @@ using namespace feature; +//////////////////////////////////////////////////////////////////////////////////// +// TypesHolder implementation +//////////////////////////////////////////////////////////////////////////////////// + TypesHolder::TypesHolder(FeatureBase const & f) : m_size(0), m_geoType(f.GetFeatureType()) { @@ -33,6 +37,34 @@ void TypesHolder::Remove(uint32_t t) } } +void TypesHolder::SortBySpec() +{ + if (m_size < 2) + return; + + // do very simple thing - put "very common" types to the end + /// @todo Make this function usefull for many "common" types. + + // initialize common types + Classificator const & c = classif(); + vector path(1); + path[0] = "building"; + uint32_t const buildingT = c.GetTypeByPath(path); + + // do swaps with "common" types + size_t end = m_size-1; + for (size_t i = 0; i < end; ++i) + if (m_types[i] == buildingT) + { + swap(m_types[i], m_types[end]); + ASSERT_NOT_EQUAL(m_types[i], buildingT, ()); + break; + } +} + +//////////////////////////////////////////////////////////////////////////////////// +// FeatureParamsBase implementation +//////////////////////////////////////////////////////////////////////////////////// void FeatureParamsBase::MakeZero() { diff --git a/indexer/feature_data.hpp b/indexer/feature_data.hpp index 35b70c2a8c..850a0d70f9 100644 --- a/indexer/feature_data.hpp +++ b/indexer/feature_data.hpp @@ -89,6 +89,9 @@ namespace feature void Remove(uint32_t t); string DebugPrint() const; + + /// Sort types by it's specification (more detailed type goes first). + void SortBySpec(); }; inline string DebugPrint(TypesHolder const & t) diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index d2bf09724b..19aaf7504c 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -151,10 +151,10 @@ { NSString * res = [NSString stringWithUTF8String:info.m_name.c_str()]; - // @TODO fix "empty" type for coordinates search result - if (!info.m_types.empty() && !info.m_types[0].empty()) + char const * cType = info.GetBestType(); + if (cType) { - NSString * type = [NSString stringWithUTF8String:info.m_types[0].c_str()]; + NSString * type = [NSString stringWithUTF8String:cType]; if (res.length == 0) res = [type capitalizedString]; diff --git a/iphone/Maps/Classes/SearchVC.mm b/iphone/Maps/Classes/SearchVC.mm index 832f9bf276..28e30ce97e 100644 --- a/iphone/Maps/Classes/SearchVC.mm +++ b/iphone/Maps/Classes/SearchVC.mm @@ -438,8 +438,8 @@ static void OnSearchResultCallback(search::Results const & res) m_framework->ShowSearchResult(res); Framework::AddressInfo info; - info.m_name = res.GetString(); - info.m_types.push_back(res.GetFeatureType()); + info.MakeFrom(res); + [[MapsAppDelegate theApp].m_mapViewController showSearchResultAsBookmarkAtMercatorPoint:res.GetFeatureCenter() withInfo:info]; [self onCloseButton:nil]; diff --git a/map/address_finder.cpp b/map/address_finder.cpp index 4b2c9d8be0..c414cd9bcd 100644 --- a/map/address_finder.cpp +++ b/map/address_finder.cpp @@ -1,5 +1,7 @@ #include "framework.hpp" +#include "../search/result.hpp" + #include "../indexer/classificator.hpp" #include "../indexer/feature_visibility.hpp" @@ -323,9 +325,11 @@ namespace } static void GetReadableTypes(search::Engine const * eng, int8_t lang, - feature::TypesHolder const & types, + feature::TypesHolder & types, Framework::AddressInfo & info) { + types.SortBySpec(); + // Try to add types from categories. size_t const count = types.Size(); for (size_t i = 0; i < count; ++i) @@ -540,6 +544,25 @@ void Framework::GetLocality(m2::PointD const & pt, AddressInfo & info) const getLocality.FillLocality(info, *this); } +//////////////////////////////////////////////////////////////////////////////////// +// Framework::AddressInfo implementation +//////////////////////////////////////////////////////////////////////////////////// + +void Framework::AddressInfo::MakeFrom(search::Result const & res) +{ + ASSERT_EQUAL ( res.GetResultType(), search::Result::RESULT_FEATURE, () ); + + // push the feature type + string const type = res.GetFeatureType(); + if (!type.empty()) + m_types.push_back(type); + + // assign name if it's not equal with type + string name = res.GetString(); + if (name != type) + m_name.swap(name); +} + string Framework::AddressInfo::FormatAddress() const { string result = m_house; @@ -577,6 +600,16 @@ string Framework::AddressInfo::FormatTypes() const return result; } +char const * Framework::AddressInfo::GetBestType() const +{ + if (!m_types.empty()) + { + ASSERT ( !m_types[0].empty(), () ); + return m_types[0].c_str(); + } + return 0; +} + void Framework::AddressInfo::Clear() { m_country.clear(); diff --git a/map/framework.hpp b/map/framework.hpp index 8db087969b..679edd6e2e 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -308,8 +308,11 @@ public: string m_country, m_city, m_street, m_house, m_name; vector m_types; + void MakeFrom(search::Result const & res); + string FormatAddress() const; string FormatTypes() const; + char const * GetBestType() const; void Clear(); }; diff --git a/search/intermediate_result.cpp b/search/intermediate_result.cpp index 256182d22b..0b067a8348 100644 --- a/search/intermediate_result.cpp +++ b/search/intermediate_result.cpp @@ -146,7 +146,8 @@ PreResult2::PreResult2(FeatureType const & f, PreResult1 const & res, m_rank(res.m_rank), m_viewportDistance(res.m_viewportDistance) { - ASSERT_GREATER(m_types.Size(), 0, ()); + ASSERT ( !m_types.Empty(), () ); + m_types.SortBySpec(); // It's better to get exact center for point feature. if (f.GetFeatureType() == feature::GEOM_POINT) -- cgit v1.2.3