diff --git a/search/result.cpp b/search/result.cpp index 5ec642fbb9..0a3176388a 100644 --- a/search/result.cpp +++ b/search/result.cpp @@ -109,6 +109,17 @@ pair const & Result::GetHighlightRange(size_t idx) const return m_hightlightRanges[idx]; } +void Result::AppendCity(string const & name) +{ + if (name.empty()) + return; + + if (m_region.empty()) + m_region = name; + else + m_region += (", " + name); +} + bool Results::AddResultCheckExisting(Result const & r) { if (find(m_vec.begin(), m_vec.end(), r) == m_vec.end()) diff --git a/search/result.hpp b/search/result.hpp index 05902daee7..aff55f58b5 100644 --- a/search/result.hpp +++ b/search/result.hpp @@ -76,6 +76,7 @@ public: pair const & GetHighlightRange(size_t idx) const; inline size_t GetHighlightRangesCount() const { return m_hightlightRanges.size(); } + void AppendCity(string const & name); private: FeatureID m_id; diff --git a/search/search_query.cpp b/search/search_query.cpp index 5c22f889b5..bf121e6b30 100644 --- a/search/search_query.cpp +++ b/search/search_query.cpp @@ -78,7 +78,12 @@ Query::Query(Index const * pIndex, m_pCategories(pCategories), m_pStringsToSuggest(pStringsToSuggest), m_pInfoGetter(pInfoGetter), +#ifdef HOUSE_SEARCH_TEST m_houseDetector(pIndex), +#endif +#ifdef FIND_LOCALITY_TEST + m_locality(pIndex), +#endif m_worldSearch(true), m_sortByViewport(false), m_position(empty_pos_value, empty_pos_value) @@ -157,10 +162,20 @@ void Query::SetViewportByIndex(MWMVectorT const & mwmInfo, m2::RectD const & vie { m_viewport[idx] = viewport; UpdateViewportOffsets(mwmInfo, viewport, m_offsetsInViewport[idx]); + +#ifdef FIND_LOCALITY_TEST + m_locality.SetViewportByIndex(mwmInfo, viewport, idx); +#endif } } else + { ClearCache(idx); + +#ifdef FIND_LOCALITY_TEST + m_locality.ClearCache(idx); +#endif + } } void Query::SetPreferredLanguage(string const & lang) @@ -171,6 +186,10 @@ void Query::SetPreferredLanguage(string const & lang) // Default initialization. // If you want to reset input language, call SetInputLanguage before search. SetInputLanguage(code); + +#ifdef FIND_LOCALITY_TEST + m_locality.SetLanguage(code); +#endif } void Query::SetInputLanguage(int8_t lang) @@ -730,9 +749,12 @@ ftypes::Type Query::GetLocalityIndex(feature::TypesHolder const & types) const Type const type = IsLocalityChecker::Instance().GetType(types); switch (type) { - case TOWN: return CITY; - case VILLAGE: return NONE; - default: return type; + case TOWN: + return CITY; + case VILLAGE: + return NONE; + default: + return type; } } @@ -930,11 +952,20 @@ public: }; - Result Query::MakeResult(impl::PreResult2 const & r) const { Result res = r.GenerateFinalResult(m_pInfoGetter, m_pCategories, &m_prefferedTypes, GetLanguage(LANG_CURRENT)); MakeResultHighlight(res); + +#ifdef FIND_LOCALITY_TEST + if (ftypes::IsLocalityChecker::Instance().GetType(r.GetTypes()) == ftypes::NONE) + { + string city; + m_locality.GetLocality(res.GetFeatureCenter(), city); + res.AppendCity(city); + } +#endif + return res; } diff --git a/search/search_query.hpp b/search/search_query.hpp index d7c93fe532..f4fa25924b 100644 --- a/search/search_query.hpp +++ b/search/search_query.hpp @@ -20,11 +20,16 @@ #define HOUSE_SEARCH_TEST +#define FIND_LOCALITY_TEST #ifdef HOUSE_SEARCH_TEST #include "house_detector.hpp" #endif +#ifdef FIND_LOCALITY_TEST +#include "locality_finder.hpp" +#endif + class FeatureType; class CategoriesHolder; @@ -223,7 +228,11 @@ private: #ifdef HOUSE_SEARCH_TEST strings::UniString m_house; vector m_streetID; - search::HouseDetector m_houseDetector; + HouseDetector m_houseDetector; +#endif + +#ifdef FIND_LOCALITY_TEST + LocalityFinder m_locality; #endif static int const MAX_SUGGESTS_COUNT = 5;