diff options
author | vng <viktor.govako@gmail.com> | 2012-12-19 01:04:48 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:48:06 +0300 |
commit | 836d3f86cf8e7a682e7215d4a509b8152a3cb740 (patch) | |
tree | 1c3bacb695370635cb9469e46848ebfde06991a5 | |
parent | 3841eefecc8f83d47c9a654678b5d8ece6a80ba5 (diff) |
[search] Get english country name from mwm file name.
-rw-r--r-- | indexer/index.cpp | 38 | ||||
-rw-r--r-- | indexer/index.hpp | 26 | ||||
-rw-r--r-- | indexer/mwm_set.cpp | 7 | ||||
-rw-r--r-- | indexer/mwm_set.hpp | 1 | ||||
-rw-r--r-- | search/search_query.cpp | 37 |
5 files changed, 64 insertions, 45 deletions
diff --git a/indexer/index.cpp b/indexer/index.cpp index cd6989798d..ec00db4d9d 100644 --- a/indexer/index.cpp +++ b/indexer/index.cpp @@ -2,16 +2,43 @@ #include "data_header.hpp" #include "../platform/platform.hpp" +#include "../platform/file_name_utils.hpp" #include "../coding/internal/file_data.hpp" +////////////////////////////////////////////////////////////////////////////////// +// MwmValue implementation +////////////////////////////////////////////////////////////////////////////////// + MwmValue::MwmValue(string const & name) - : m_cont(GetPlatform().GetReader(name)), m_name(name) + : m_cont(GetPlatform().GetReader(name)) { m_factory.Load(m_cont); } +string MwmValue::GetFileName() const +{ + string s = m_cont.GetFileName(); + pl::GetNameFromURLRequest(s); + pl::GetNameWithoutExt(s); + return s; +} + +////////////////////////////////////////////////////////////////////////////////// +// Index::MwmLock implementation +////////////////////////////////////////////////////////////////////////////////// + +string Index::MwmLock::GetFileName() const +{ + MwmValue * p = GetValue(); + return (p ? p->GetFileName() : string()); +} + +////////////////////////////////////////////////////////////////////////////////// +// Index implementation +////////////////////////////////////////////////////////////////////////////////// + int Index::GetInfo(string const & name, MwmInfo & info) const { MwmValue value(name); @@ -121,6 +148,10 @@ void Index::UpdateMwmInfo(MwmId id) } } +////////////////////////////////////////////////////////////////////////////////// +// Index::FeaturesLoaderGuard implementation +////////////////////////////////////////////////////////////////////////////////// + Index::FeaturesLoaderGuard::FeaturesLoaderGuard(Index const & parent, MwmId id) : m_lock(parent, id), /// @note This guard is suitable when mwm is loaded @@ -128,6 +159,11 @@ Index::FeaturesLoaderGuard::FeaturesLoaderGuard(Index const & parent, MwmId id) { } +bool Index::FeaturesLoaderGuard::IsWorld() const +{ + return (m_lock.GetValue()->GetHeader().GetType() == feature::DataHeader::world); +} + void Index::FeaturesLoaderGuard::GetFeature(uint32_t offset, FeatureType & ft) { m_vector.Get(offset, ft); diff --git a/indexer/index.hpp b/indexer/index.hpp index 669624f6e9..40a5423b07 100644 --- a/indexer/index.hpp +++ b/indexer/index.hpp @@ -18,17 +18,17 @@ class MwmValue : public MwmSet::MwmValueBase { public: FilesContainerR m_cont; - string m_name; IndexFactory m_factory; explicit MwmValue(string const & name); - inline feature::DataHeader const & GetHeader() const - { - return m_factory.GetHeader(); - } + inline feature::DataHeader const & GetHeader() const { return m_factory.GetHeader(); } + + /// @return MWM file name without extension. + string GetFileName() const; }; + class Index : public MwmSet { protected: @@ -43,17 +43,19 @@ public: class MwmLock : public MwmSet::MwmLock { + typedef MwmSet::MwmLock BaseT; public: MwmLock(Index const & index, MwmId mwmId) - : MwmSet::MwmLock(const_cast<Index &>(index), mwmId) {} + : BaseT(const_cast<Index &>(index), mwmId) {} inline MwmValue * GetValue() const { - return static_cast<MwmValue *>(MwmSet::MwmLock::GetValue()); + return static_cast<MwmValue *>(BaseT::GetValue()); } - inline FilesContainerR const & GetContainer() const { return GetValue()->m_cont; } - inline feature::DataHeader const & GetHeader() const { return GetValue()->GetHeader(); } + /// @return MWM file name without extension. + /// If value is 0, an empty string returned. + string GetFileName() const; }; bool DeleteMap(string const & fileName); @@ -82,8 +84,14 @@ public: { MwmLock m_lock; FeaturesVector m_vector; + public: FeaturesLoaderGuard(Index const & parent, MwmId id); + + inline MwmSet::MwmId GetID() const { return m_lock.GetID(); } + inline string GetFileName() const { return m_lock.GetFileName(); } + + bool IsWorld() const; void GetFeature(uint32_t offset, FeatureType & ft); }; diff --git a/indexer/mwm_set.cpp b/indexer/mwm_set.cpp index 12d34e5dc5..9477616b4a 100644 --- a/indexer/mwm_set.cpp +++ b/indexer/mwm_set.cpp @@ -106,13 +106,6 @@ MwmSet::MwmId MwmSet::GetIdByName(string const & name) return INVALID_MWM_ID; } -string MwmSet::MwmLock::GetCountryName() const -{ - string const & src = m_mwmSet.m_name[m_id]; - ASSERT ( !src.empty(), () ); - return src.substr(0, src.size() - strlen(DATA_FILE_EXTENSION)); -} - int MwmSet::Add(string const & fileName, m2::RectD & rect) { threads::MutexGuard mutexGuard(m_lock); diff --git a/indexer/mwm_set.hpp b/indexer/mwm_set.hpp index 8e7124fd2b..f7ae576c11 100644 --- a/indexer/mwm_set.hpp +++ b/indexer/mwm_set.hpp @@ -62,7 +62,6 @@ public: ~MwmLock(); inline MwmValueBase * GetValue() const { return m_pValue; } - string GetCountryName() const; inline MwmId GetID() const { return m_id; } private: diff --git a/search/search_query.cpp b/search/search_query.cpp index 3302af7c7d..1c6b5e92e7 100644 --- a/search/search_query.cpp +++ b/search/search_query.cpp @@ -428,44 +428,27 @@ namespace impl { class PreResult2Maker { - struct LockedFeaturesVector - { - Index::MwmLock m_lock; - FeaturesVector m_vector; - - // Assume that we didn't remove maps during search, so m_lock.GetValue() != 0. - LockedFeaturesVector(Index const & index, MwmSet::MwmId const & id) - : m_lock(index, id), m_vector(m_lock.GetContainer(), m_lock.GetHeader()) - { - } - - string GetCountry() const - { - if (m_lock.GetHeader().GetType() == feature::DataHeader::world) - return string(); - return m_lock.GetCountryName(); - } - - MwmSet::MwmId GetID() const { return m_lock.GetID(); } - }; - Query & m_query; - scoped_ptr<LockedFeaturesVector> m_pFV; + scoped_ptr<Index::FeaturesLoaderGuard> m_pFV; // For the best performance, incoming id's should be sorted by id.first (mwm file id). void LoadFeature(pair<size_t, uint32_t> const & id, FeatureType & f, string & name, string & country) { if (m_pFV.get() == 0 || m_pFV->GetID() != id.first) - m_pFV.reset(new LockedFeaturesVector(*m_query.m_pIndex, id.first)); + m_pFV.reset(new Index::FeaturesLoaderGuard(*m_query.m_pIndex, id.first)); - m_pFV->m_vector.Get(id.second, f); + m_pFV->GetFeature(id.second, f); uint32_t penalty; m_query.GetBestMatchName(f, penalty, name); - country = m_pFV->GetCountry(); + // country (region) name is a file name if feature isn't from World.mwm + if (m_pFV->IsWorld()) + country.clear(); + else + country = m_pFV->GetFileName(); } public: @@ -1489,7 +1472,7 @@ void Query::SearchInMWM(Index::MwmLock const & mwmLock, Params const & params, i TrieRootPrefix(*pLangRoot, edge), filter, categoriesHolder, emitter); - LOG(LDEBUG, ("Country", pMwm->m_name, + LOG(LDEBUG, ("Country", pMwm->GetFileName(), "Lang", StringUtf8Multilang::GetLangByCode(static_cast<int8_t>(edge[0])), "Matched", emitter.GetCount())); @@ -1653,7 +1636,7 @@ void Query::SearchAdditional(Results & res, bool nearMe, bool inViewport) for (MwmSet::MwmId mwmId = 0; mwmId < mwmInfo.size(); ++mwmId) { Index::MwmLock mwmLock(*m_pIndex, mwmId); - string const s = mwmLock.GetCountryName(); + string const s = mwmLock.GetFileName(); if (s == name[0] || s == name[1]) SearchInMWM(mwmLock, params); |