diff options
author | vng <viktor.govako@gmail.com> | 2012-02-15 22:52:45 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:34:08 +0300 |
commit | 53bcf037e7d850eb77c1bc7dfd964b31a5d43557 (patch) | |
tree | b30d8a7015e351e20da4f17a2bfdb4ae767336b4 | |
parent | fd4d12b7c3bea550e964f93da08160f42304e66b (diff) |
[search] Do index only for visibly types in MWM. Closed #626.
-rw-r--r-- | indexer/classificator.cpp | 28 | ||||
-rw-r--r-- | indexer/classificator.hpp | 2 | ||||
-rw-r--r-- | indexer/feature_loader_base.hpp | 1 | ||||
-rw-r--r-- | indexer/feature_visibility.cpp | 38 | ||||
-rw-r--r-- | indexer/feature_visibility.hpp | 1 | ||||
-rw-r--r-- | indexer/features_vector.hpp | 6 | ||||
-rw-r--r-- | indexer/search_index_builder.cpp | 25 |
7 files changed, 94 insertions, 7 deletions
diff --git a/indexer/classificator.cpp b/indexer/classificator.cpp index 1c8f0e2145..f23823e374 100644 --- a/indexer/classificator.cpp +++ b/indexer/classificator.cpp @@ -444,6 +444,34 @@ bool ClassifObject::IsDrawableLike(FeatureGeoType ft) const return false; } +pair<int, int> ClassifObject::GetDrawScaleRange() const +{ + if (!IsDrawableAny()) + return make_pair(-1, -1); + + size_t const count = m_visibility.size(); + + int left = -1; + for (int i = 0; i < count; ++i) + if (m_visibility[i]) + { + left = i; + break; + } + + ASSERT_NOT_EQUAL ( left, -1, () ); + + int right = left; + for (int i = count-1; i > left; --i) + if (m_visibility[i]) + { + right = i; + break; + } + + return make_pair(left, right); +} + void Classificator::ReadClassificator(istream & s) { m_root.Clear(); diff --git a/indexer/classificator.hpp b/indexer/classificator.hpp index d43a8eaf0e..01d5a6adb8 100644 --- a/indexer/classificator.hpp +++ b/indexer/classificator.hpp @@ -88,6 +88,8 @@ public: bool IsDrawableAny() const; bool IsDrawableLike(FeatureGeoType ft) const; + pair<int, int> GetDrawScaleRange() const; + template <class ToDo> void ForEachObject(ToDo toDo) { diff --git a/indexer/feature_loader_base.hpp b/indexer/feature_loader_base.hpp index 962e8d71be..55fccbd396 100644 --- a/indexer/feature_loader_base.hpp +++ b/indexer/feature_loader_base.hpp @@ -41,6 +41,7 @@ namespace feature inline int GetScalesCount() const { return static_cast<int>(m_header.GetScalesCount()); } inline int GetScale(int i) const { return m_header.GetScale(i); } inline int GetLastScale() const { return m_header.GetLastScale(); } + inline pair<int, int> GetScaleRange() const { return m_header.GetScaleRange(); } }; class LoaderBase diff --git a/indexer/feature_visibility.cpp b/indexer/feature_visibility.cpp index 8881da212e..e3e80370b1 100644 --- a/indexer/feature_visibility.cpp +++ b/indexer/feature_visibility.cpp @@ -267,6 +267,44 @@ int MinDrawableScaleForFeature(FeatureBase const & f) namespace { + class DoGetScalesRange + { + pair<int, int> m_scales; + public: + DoGetScalesRange() : m_scales(1000, -1000) {} + typedef bool ResultType; + + void operator() (ClassifObject const *) {} + bool operator() (ClassifObject const * p, bool & res) + { + res = true; + + pair<int, int> scales = p->GetDrawScaleRange(); + if (scales.first != -1) + { + m_scales.first = min(m_scales.first, scales.first); + m_scales.second = max(m_scales.second, scales.second); + } + + return false; + } + + pair<int, int> GetScale() const + { + return (m_scales.first > m_scales.second ? make_pair(-1, -1) : m_scales); + } + }; +} + +pair<int, int> DrawableScaleRangeForType(uint32_t type) +{ + DoGetScalesRange doGet; + (void)classif().ProcessObjects(type, doGet); + return doGet.GetScale(); +} + +namespace +{ bool IsDrawable(feature::TypesHolder const & types, int level) { Classificator const & c = classif(); diff --git a/indexer/feature_visibility.hpp b/indexer/feature_visibility.hpp index bd9b30984c..77be9cd9b3 100644 --- a/indexer/feature_visibility.hpp +++ b/indexer/feature_visibility.hpp @@ -27,6 +27,7 @@ namespace feature bool IsDrawableForIndex(FeatureBase const & f, int level); int MinDrawableScaleForFeature(FeatureBase const & f); + pair<int, int> DrawableScaleRangeForType(uint32_t type); /// @name Get scale range when feature's text is visible. /// @return [-1, -1] if no any text exists diff --git a/indexer/features_vector.hpp b/indexer/features_vector.hpp index 59f7edf1c1..92766a1e8a 100644 --- a/indexer/features_vector.hpp +++ b/indexer/features_vector.hpp @@ -28,7 +28,11 @@ public: m_RecordReader.ForEachRecord(DoGetFeatures<ToDo>(m_LoadInfo, toDo)); } - serial::CodingParams const & GetCodingParams() const { return m_LoadInfo.GetDefCodingParams(); } + inline serial::CodingParams const & GetCodingParams() const + { + return m_LoadInfo.GetDefCodingParams(); + } + inline pair<int, int> GetScaleRange() const { return m_LoadInfo.GetScaleRange(); } private: template <class ToDo> class DoGetFeatures diff --git a/indexer/search_index_builder.cpp b/indexer/search_index_builder.cpp index b155c67444..f468f55b71 100644 --- a/indexer/search_index_builder.cpp +++ b/indexer/search_index_builder.cpp @@ -7,6 +7,7 @@ #include "search_string_utils.hpp" #include "string_file.hpp" #include "classificator.hpp" +#include "feature_visibility.hpp" #include "../defines.hpp" @@ -67,6 +68,8 @@ class FeatureInserter typedef search::trie::ValueReader SaverT; SaverT m_valueSaver; + pair<int, int> m_scales; + class CalcPolyCenter { typedef m2::PointD P; @@ -220,8 +223,10 @@ class FeatureInserter }; public: - FeatureInserter(StringsFile & names, serial::CodingParams const & cp) - : m_names(names), m_valueSaver(cp) + FeatureInserter(StringsFile & names, + serial::CodingParams const & cp, + pair<int, int> const & scales) + : m_names(names), m_valueSaver(cp), m_scales(scales) { } @@ -246,20 +251,28 @@ public: // add names of categories of the feature for (size_t i = 0; i < types.Size(); ++i) - inserter.AddToken(search::CATEGORIES_LANG, search::FeatureTypeToString(types[i])); + { + // Do index only for visible types in mwm. + pair<int, int> const r = feature::DrawableScaleRangeForType(types[i]); + if (my::between_s(m_scales.first, m_scales.second, r.first) || + my::between_s(m_scales.first, m_scales.second, r.second)) + { + inserter.AddToken(search::CATEGORIES_LANG, search::FeatureTypeToString(types[i])); + } + } } }; } // unnamed namespace -void indexer::BuildSearchIndex(FeaturesVector const & featuresVector, Writer & writer, +void indexer::BuildSearchIndex(FeaturesVector const & featuresV, Writer & writer, string const & tmpFilePath) { { StringsFile names(tmpFilePath); - serial::CodingParams cp(search::GetCPForTrie(featuresVector.GetCodingParams())); + serial::CodingParams cp(search::GetCPForTrie(featuresV.GetCodingParams())); - featuresVector.ForEachOffset(FeatureInserter(names, cp)); + featuresV.ForEachOffset(FeatureInserter(names, cp, featuresV.GetScaleRange())); names.EndAdding(); names.OpenForRead(); |