diff options
author | tatiana-yan <tatiana.kondakova@gmail.com> | 2018-10-25 18:02:47 +0300 |
---|---|---|
committer | mpimenov <mpimenov@users.noreply.github.com> | 2018-11-19 17:09:15 +0300 |
commit | 19182210bd9b3653a9737aad98cda4cc43bf0589 (patch) | |
tree | 2d78611f69b9f2c971a6b8993cb9a14d496cf59b /indexer | |
parent | 18e985eaf825b2fcf5fc5eb739177a36b955f3ca (diff) |
[search] Faster GetAddress for ranker and reverse geocoding.
Diffstat (limited to 'indexer')
-rw-r--r-- | indexer/data_source.cpp | 23 | ||||
-rw-r--r-- | indexer/data_source.hpp | 7 | ||||
-rw-r--r-- | indexer/feature_covering.hpp | 5 |
3 files changed, 34 insertions, 1 deletions
diff --git a/indexer/data_source.cpp b/indexer/data_source.cpp index 30b290fb69..f393e7cbe5 100644 --- a/indexer/data_source.cpp +++ b/indexer/data_source.cpp @@ -18,6 +18,13 @@ public: ReadMWMFunctor(FeatureSourceFactory const & factory, Fn const & fn) : m_factory(factory), m_fn(fn) { + m_stop = []() { return false; }; + } + + ReadMWMFunctor(FeatureSourceFactory const & factory, Fn const & fn, + DataSource::StopSearchCallback const & stop) + : m_factory(factory), m_fn(fn), m_stop(stop) + { } // Reads features visible at |scale| covered by |cov| from mwm and applies |m_fn| to them. @@ -53,6 +60,8 @@ public: return; m_fn(index, *src); }); + if (m_stop()) + break; } } // Check created features container. @@ -65,6 +74,7 @@ public: private: FeatureSourceFactory const & m_factory; Fn m_fn; + DataSource::StopSearchCallback m_stop; }; void ReadFeatureType(function<void(FeatureType &)> const & fn, FeatureSource & src, uint32_t index) @@ -242,6 +252,18 @@ void DataSource::ForEachInRect(FeatureCallback const & f, m2::RectD const & rect ForEachInIntervals(readFunctor, covering::ViewportWithLowLevels, rect, scale); } +void DataSource::ForClosestToPoint(FeatureCallback const & f, StopSearchCallback const & stop, + m2::PointD const & center, double sizeM, int scale) const +{ + auto const rect = MercatorBounds::RectByCenterXYAndSizeInMeters(center, sizeM); + + auto readFeatureType = [&f](uint32_t index, FeatureSource & src) { + ReadFeatureType(f, src, index); + }; + ReadMWMFunctor readFunctor(*m_factory, readFeatureType, stop); + ForEachInIntervals(readFunctor, covering::CoveringMode::Spiral, rect, scale); +} + void DataSource::ForEachInScale(FeatureCallback const & f, int scale) const { auto readFeatureType = [&f](uint32_t index, FeatureSource & src) { @@ -262,6 +284,7 @@ void DataSource::ForEachInRectForMWM(FeatureCallback const & f, m2::RectD const auto readFeatureType = [&f](uint32_t index, FeatureSource & src) { ReadFeatureType(f, src, index); }; + ReadMWMFunctor readFunctor(*m_factory, readFeatureType); readFunctor(handle, cov, scale); } diff --git a/indexer/data_source.hpp b/indexer/data_source.hpp index c6dc708425..a186680f6c 100644 --- a/indexer/data_source.hpp +++ b/indexer/data_source.hpp @@ -27,6 +27,7 @@ class DataSource : public MwmSet public: using FeatureCallback = std::function<void(FeatureType &)>; using FeatureIdCallback = std::function<void(FeatureID const &)>; + using StopSearchCallback = std::function<bool(void)>; ~DataSource() override = default; @@ -42,6 +43,12 @@ public: void ForEachFeatureIDInRect(FeatureIdCallback const & f, m2::RectD const & rect, int scale) const; void ForEachInRect(FeatureCallback const & f, m2::RectD const & rect, int scale) const; + // Calls |f| for features closest to |center| until |stopCallback| returns true or distance + // |sizeM| from has been reached. Then for EditableDataSource calls |f| for each edited feature + // inside square with center |center| and side |2 * sizeM|. Edited features are not in the same + // hierarchy and there is no fast way to merge frozen and edited features. + void ForClosestToPoint(FeatureCallback const & f, StopSearchCallback const & stopCallback, + m2::PointD const & center, double sizeM, int scale) const; void ForEachInScale(FeatureCallback const & f, int scale) const; void ForEachInRectForMWM(FeatureCallback const & f, m2::RectD const & rect, int scale, MwmId const & id) const; diff --git a/indexer/feature_covering.hpp b/indexer/feature_covering.hpp index a5c7a87a5e..7524435d70 100644 --- a/indexer/feature_covering.hpp +++ b/indexer/feature_covering.hpp @@ -160,7 +160,10 @@ public: }; for (auto const & id : ids) - AppendLowerLevels<DEPTH_LEVELS>(id, cellDepth, insertInterval); + { + if (cellDepth > id.Level()) + AppendLowerLevels<DEPTH_LEVELS>(id, cellDepth, insertInterval); + } } } } |