diff options
author | tatiana-yan <tatiana.kondakova@gmail.com> | 2018-07-16 21:52:36 +0300 |
---|---|---|
committer | mpimenov <mpimenov@users.noreply.github.com> | 2018-07-18 15:11:04 +0300 |
commit | be9d13f61bac225210c560587526116c52232593 (patch) | |
tree | 8bf15bc4e1bef5225ea17a239b4d956875d8e630 /search | |
parent | 6e824691f7519313d0c463ceb0fc8c95799a718f (diff) |
[search] Add helper for fast DiscoveryButton search
Diffstat (limited to 'search')
-rw-r--r-- | search/utils.cpp | 39 | ||||
-rw-r--r-- | search/utils.hpp | 9 |
2 files changed, 48 insertions, 0 deletions
diff --git a/search/utils.cpp b/search/utils.cpp index c316995269..b8defe8f63 100644 --- a/search/utils.cpp +++ b/search/utils.cpp @@ -1,8 +1,14 @@ #include "search/utils.hpp" +#include "search/categories_cache.hpp" +#include "search/features_filter.hpp" +#include "search/geometry_cache.hpp" +#include "search/mwm_context.hpp" + #include "indexer/data_source.hpp" #include <cctype> +#include <utility> using namespace std; @@ -63,4 +69,37 @@ MwmSet::MwmHandle FindWorld(DataSource const & dataSource) dataSource.GetMwmsInfo(infos); return FindWorld(dataSource, infos); } + +void ForEachOfTypesInRect(DataSource const & dataSource, set<uint32_t> const & types, + m2::RectD const & pivot, FeatureIndexCallback const & fn) +{ + vector<shared_ptr<MwmInfo>> infos; + dataSource.GetMwmsInfo(infos); + + CategoriesCache cache(types, {} /* cancellable */); + auto pivotRectsCache = PivotRectsCache(1 /* maxNumEntries */, {} /* cancellable */, + max(pivot.SizeX(), pivot.SizeY()) /* maxRadiusMeters */); + + for (auto const & info : infos) + { + if (!pivot.IsIntersect(info->m_bordersRect)) + continue; + + auto handle = dataSource.GetMwmHandleById(MwmSet::MwmId(info)); + auto & value = *handle.GetValue<MwmValue>(); + if (!value.HasSearchIndex()) + continue; + + MwmContext const mwmContext(move(handle)); + auto features = cache.Get(mwmContext); + + auto const pivotFeatures = pivotRectsCache.Get(mwmContext, pivot, scales::GetUpperScale()); + ViewportFilter const filter(pivotFeatures, 0 /* threshold */); + features = filter.Filter(features); + MwmSet::MwmId mwmId(info); + features.ForEach([&fn, &mwmId](uint64_t bit) { + fn(FeatureID(mwmId, ::base::asserted_cast<uint32_t>(bit))); + }); + } +} } // namespace search diff --git a/search/utils.hpp b/search/utils.hpp index 11d5cd97dd..390e30cd0e 100644 --- a/search/utils.hpp +++ b/search/utils.hpp @@ -5,11 +5,14 @@ #include "search/token_slice.hpp" #include "indexer/categories_holder.hpp" +#include "indexer/feature_decl.hpp" #include "indexer/mwm_set.hpp" #include "indexer/search_delimiters.hpp" #include "indexer/search_string_utils.hpp" #include "indexer/trie.hpp" +#include "geometry/rect2d.hpp" + #include "base/levenshtein_dfa.hpp" #include "base/stl_helpers.hpp" #include "base/string_utils.hpp" @@ -18,6 +21,7 @@ #include <cstdint> #include <functional> #include <memory> +#include <set> #include <vector> class DataSource; @@ -117,4 +121,9 @@ bool FillCategories(QuerySliceOnRawStrings<T> const & slice, Locales const & loc MwmSet::MwmHandle FindWorld(DataSource const & dataSource, std::vector<std::shared_ptr<MwmInfo>> const & infos); MwmSet::MwmHandle FindWorld(DataSource const & dataSource); + +using FeatureIndexCallback = std::function<void(FeatureID const &)>; +// Applies |fn| to each feature index of type from |types| in |rect|. +void ForEachOfTypesInRect(DataSource const & dataSource, std::set<uint32_t> const & types, + m2::RectD const & rect, FeatureIndexCallback const & fn); } // namespace search |