From 0226c8c3eb1eebdc427cd62250fd0ce8900dbdc5 Mon Sep 17 00:00:00 2001 From: Yury Melnichek Date: Thu, 29 Sep 2011 14:07:46 +0200 Subject: [PATCH] Move GetSearchRank() from FeatureType to an external function. --- indexer/feature.cpp | 6 ----- indexer/feature.hpp | 1 - indexer/feature_utils.cpp | 41 ++++++++++++++++++++++++-------- indexer/feature_utils.hpp | 4 ++++ indexer/search_index_builder.cpp | 3 ++- search/intermediate_result.cpp | 2 +- 6 files changed, 38 insertions(+), 19 deletions(-) diff --git a/indexer/feature.cpp b/indexer/feature.cpp index 5cc0efa090..af38996a95 100644 --- a/indexer/feature.cpp +++ b/indexer/feature.cpp @@ -279,9 +279,3 @@ double FeatureType::GetPopulationDrawRank() const return min(upperBound, static_cast(n)) / upperBound; } } - -uint8_t FeatureType::GetSearchRank() const -{ - ParseCommon(); - return m_Params.rank; -} diff --git a/indexer/feature.hpp b/indexer/feature.hpp index 075c041309..45c5099c95 100644 --- a/indexer/feature.hpp +++ b/indexer/feature.hpp @@ -222,7 +222,6 @@ public: uint32_t GetPopulation() const; double GetPopulationDrawRank() const; - uint8_t GetSearchRank() const; inline string GetRoadNumber() const { return m_Params.ref; } diff --git a/indexer/feature_utils.cpp b/indexer/feature_utils.cpp index d71524d17f..60fad6e9a5 100644 --- a/indexer/feature_utils.cpp +++ b/indexer/feature_utils.cpp @@ -4,14 +4,17 @@ #include "../base/base.hpp" #include "../std/vector.hpp" -namespace +namespace feature { -class FeatureViewportEstimator +namespace impl +{ + +class FeatureEstimator { public: - FeatureViewportEstimator() + FeatureEstimator() { m_TypeContinent = GetType("place", "continent"); m_TypeCountry = GetType("place", "country"); @@ -42,6 +45,14 @@ public: maxSizeMeters.x, maxSizeMeters.y); } + uint8_t GetSearchRank(FeatureType const & feature) const + { + uint32_t const population = feature.GetPopulation(); + return static_cast(log(double(population)) / log(1.1)); + } + +private: + // Returns width and height (lon and lat) for a given type. m2::PointD GetSizeForType(uint32_t const type, FeatureType const & feature) const { @@ -66,8 +77,6 @@ public: return m2::PointD(0, 0); } -private: - static uint32_t GetType(string const & s1, string const & s2 = string(), string const & s3 = string()) @@ -87,10 +96,22 @@ private: uint32_t m_TypeVillage; }; -} // unnamed namespace - -m2::RectD feature::GetFeatureViewport(FeatureType const & feature) +FeatureEstimator const & GetFeatureEstimator() { - static FeatureViewportEstimator const featureViewportEstimator; - return featureViewportEstimator.GetViewport(feature); + static FeatureEstimator const featureEstimator; + return featureEstimator; } + +} // namespace feature::impl + +m2::RectD GetFeatureViewport(FeatureType const & feature) +{ + return impl::GetFeatureEstimator().GetViewport(feature); +} + +uint8_t GetSearchRank(FeatureType const & feature) +{ + return impl::GetFeatureEstimator().GetSearchRank(feature); +} + +} // namespace feature diff --git a/indexer/feature_utils.hpp b/indexer/feature_utils.hpp index 271d43d9da..97bfea4b49 100644 --- a/indexer/feature_utils.hpp +++ b/indexer/feature_utils.hpp @@ -1,6 +1,7 @@ #pragma once #include "feature.hpp" #include "../geometry/rect2d.hpp" +#include "../base/base.hpp" namespace feature { @@ -8,4 +9,7 @@ namespace feature // Get viewport to show given feature. Used in search. m2::RectD GetFeatureViewport(FeatureType const & feature); +// Get search rank for a feature. Roughly, rank + 1 means that feature is 1.x times more popular. +uint8_t GetSearchRank(FeatureType const & feature); + } // namespace feature diff --git a/indexer/search_index_builder.cpp b/indexer/search_index_builder.cpp index 9b0175b2cb..1a2f99178c 100644 --- a/indexer/search_index_builder.cpp +++ b/indexer/search_index_builder.cpp @@ -1,5 +1,6 @@ #include "search_index_builder.hpp" +#include "feature_utils.hpp" #include "features_vector.hpp" #include "search_delimiters.hpp" #include "search_trie.hpp" @@ -92,7 +93,7 @@ struct FeatureInserter explicit FeatureInserter(vector & names) : m_names(names) {} void operator() (FeatureType const & feature, uint64_t pos) const { - FeatureNameInserter f(m_names, static_cast(pos), feature.GetSearchRank()); + FeatureNameInserter f(m_names, static_cast(pos), feature::GetSearchRank(feature)); feature.ForEachNameRef(f); } }; diff --git a/search/intermediate_result.cpp b/search/intermediate_result.cpp index 8cbe01de21..38ed253707 100644 --- a/search/intermediate_result.cpp +++ b/search/intermediate_result.cpp @@ -22,7 +22,7 @@ IntermediateResult::IntermediateResult(m2::RectD const & viewportRect, m_type = types.m_types[0]; m_distance = ResultDistance(viewportRect.Center(), m_rect.Center()); m_direction = ResultDirection(viewportRect.Center(), m_rect.Center()); - m_searchRank = feature.GetSearchRank(); + m_searchRank = feature::GetSearchRank(feature); } IntermediateResult::IntermediateResult(m2::RectD const & viewportRect,