From f227a2f797c447ec1f20974874e709978d5dade4 Mon Sep 17 00:00:00 2001 From: Maxim Pimenov Date: Fri, 27 May 2016 12:32:04 +0300 Subject: [PATCH 1/2] [search] Merged Processor and ProcessorV2. --- map/framework.cpp | 2 + search/intermediate_result.hpp | 1 + search/processor.cpp | 371 ++++++++++-------- search/processor.hpp | 74 ++-- search/processor_factory.hpp | 4 +- search/search.pro | 2 - search/search_engine.cpp | 4 +- ...h_query_v2_test.cpp => processor_test.cpp} | 17 +- .../search_integration_tests.pro | 6 +- search/v2/processor_v2.cpp | 73 ---- search/v2/processor_v2.hpp | 29 -- 11 files changed, 252 insertions(+), 331 deletions(-) rename search/search_integration_tests/{search_query_v2_test.cpp => processor_test.cpp} (98%) delete mode 100644 search/v2/processor_v2.cpp delete mode 100644 search/v2/processor_v2.hpp diff --git a/map/framework.cpp b/map/framework.cpp index 928f090264..55e69387e8 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -61,7 +61,9 @@ #include "coding/png_memory_encoder.hpp" #include "geometry/angles.hpp" +#include "geometry/any_rect2d.hpp" #include "geometry/distance_on_sphere.hpp" +#include "geometry/rect2d.hpp" #include "geometry/triangle2d.hpp" #include "base/math.hpp" diff --git a/search/intermediate_result.hpp b/search/intermediate_result.hpp index 1a4d744281..07172b6366 100644 --- a/search/intermediate_result.hpp +++ b/search/intermediate_result.hpp @@ -1,4 +1,5 @@ #pragma once + #include "search/result.hpp" #include "search/v2/pre_ranking_info.hpp" #include "search/v2/ranking_info.hpp" diff --git a/search/processor.cpp b/search/processor.cpp index bf74e215d7..30ef79a680 100644 --- a/search/processor.cpp +++ b/search/processor.cpp @@ -31,6 +31,8 @@ #include "indexer/search_string_utils.hpp" #include "indexer/trie_reader.hpp" +#include "geometry/mercator.hpp" + #include "platform/mwm_traits.hpp" #include "platform/mwm_version.hpp" #include "platform/preferred_languages.hpp" @@ -226,9 +228,10 @@ Processor::Processor(Index & index, CategoriesHolder const & categories, , m_mode(Mode::Everywhere) , m_worldSearch(true) , m_suggestsEnabled(true) - , m_preRanker(kPreResultsCount) , m_viewportSearch(false) - , m_keepHouseNumberInQuery(false) + , m_keepHouseNumberInQuery(true) + , m_preRanker(kPreResultsCount) + , m_geocoder(index, infoGetter) , m_reverseGeocoder(index) { // Initialize keywords scorer. @@ -244,30 +247,14 @@ Processor::Processor(Index & index, CategoriesHolder const & categories, SetPreferredLocale("en"); } -void Processor::SetLanguage(int id, int8_t lang) +void Processor::Init(bool viewportSearch) { - m_keywordsScorer.SetLanguage(GetLangIndex(id), lang); -} + Reset(); -int8_t Processor::GetLanguage(int id) const -{ - return m_keywordsScorer.GetLanguage(GetLangIndex(id)); -} - -m2::PointD Processor::GetPivotPoint() const -{ - m2::RectD const & viewport = m_viewport[CURRENT_V]; - if (viewport.IsPointInside(GetPosition())) - return GetPosition(); - return viewport.Center(); -} - -m2::RectD Processor::GetPivotRect() const -{ - m2::RectD const & viewport = m_viewport[CURRENT_V]; - if (viewport.IsPointInside(GetPosition())) - return GetRectAroundPosition(GetPosition()); - return NormalizeViewport(viewport); + m_tokens.clear(); + m_prefix.clear(); + m_preRanker.Clear(); + m_viewportSearch = viewportSearch; } void Processor::SetViewport(m2::RectD const & viewport, bool forceUpdate) @@ -280,59 +267,6 @@ void Processor::SetViewport(m2::RectD const & viewport, bool forceUpdate) SetViewportByIndex(mwmsInfo, viewport, CURRENT_V, forceUpdate); } -void Processor::SetViewportByIndex(TMWMVector const & mwmsInfo, m2::RectD const & viewport, - size_t idx, bool forceUpdate) -{ - ASSERT(idx < COUNT_V, (idx)); - - if (viewport.IsValid()) - { - // Check if we can skip this cache query. - if (m_viewport[idx].IsValid()) - { - // Threshold to compare for equal or inner rects. - // It doesn't influence on result cached features because it's smaller - // than minimal cell size in geometry index (i'm almost sure :)). - double constexpr epsMeters = 10.0; - - if (forceUpdate) - { - // skip if rects are equal - if (IsEqualMercator(m_viewport[idx], viewport, epsMeters)) - return; - } - else - { - // skip if the new viewport is inside the old one (no need to recache) - m2::RectD r(m_viewport[idx]); - double constexpr eps = epsMeters * MercatorBounds::degreeInMetres; - r.Inflate(eps, eps); - - if (r.IsRectInside(viewport)) - return; - } - } - - m_viewport[idx] = viewport; - } - else - { - ClearCache(idx); - } -} - -void Processor::SetRankPivot(m2::PointD const & pivot) -{ - if (!m2::AlmostEqualULPs(pivot, m_pivot)) - { - storage::CountryInfo ci; - m_infoGetter.GetRegionInfo(pivot, ci); - m_region.swap(ci.m_name); - } - - m_pivot = pivot; -} - void Processor::SetPreferredLocale(string const & locale) { ASSERT(!locale.empty(), ()); @@ -365,72 +299,6 @@ void Processor::SetInputLocale(string const & locale) } } -void Processor::ClearCaches() -{ - for (size_t i = 0; i < COUNT_V; ++i) - ClearCache(i); - - m_locality.ClearCache(); -} - -void Processor::ClearCache(size_t ind) { m_viewport[ind].MakeEmpty(); } - -void Processor::Init(bool viewportSearch) -{ - Reset(); - - m_tokens.clear(); - m_prefix.clear(); - m_preRanker.Clear(); - m_viewportSearch = viewportSearch; -} - -int Processor::GetCategoryLocales(int8_t(&arr)[3]) const -{ - static int8_t const enLocaleCode = CategoriesHolder::MapLocaleToInteger("en"); - - // Prepare array of processing locales. English locale is always present for category matching. - int count = 0; - if (m_currentLocaleCode != -1) - arr[count++] = m_currentLocaleCode; - if (m_inputLocaleCode != -1 && m_inputLocaleCode != m_currentLocaleCode) - arr[count++] = m_inputLocaleCode; - if (enLocaleCode != m_currentLocaleCode && enLocaleCode != m_inputLocaleCode) - arr[count++] = enLocaleCode; - - return count; -} - -template -void Processor::ForEachCategoryTypes(StringSliceBase const & slice, ToDo toDo) const -{ - int8_t arrLocales[3]; - int const localesCount = GetCategoryLocales(arrLocales); - - for (size_t i = 0; i < slice.Size(); ++i) - { - auto token = RemoveHashtag(slice.Get(i)); - for (int j = 0; j < localesCount; ++j) - m_categories.ForEachTypeByName(arrLocales[j], token, bind(ref(toDo), i, _1)); - ProcessEmojiIfNeeded(token, i, toDo); - } -} - -template -void Processor::ProcessEmojiIfNeeded(strings::UniString const & token, size_t ind, - ToDo & toDo) const -{ - // Special process of 2 codepoints emoji (e.g. black guy on a bike). - // Only emoji synonyms can have one codepoint. - if (token.size() > 1) - { - static int8_t const enLocaleCode = CategoriesHolder::MapLocaleToInteger("en"); - - m_categories.ForEachTypeByName(enLocaleCode, strings::UniString(1, token[0]), - bind(ref(toDo), ind, _1)); - } -} - void Processor::SetQuery(string const & query) { m_query = query; @@ -499,30 +367,167 @@ void Processor::SetQuery(string const & query) }); } -void Processor::FlushViewportResults(v2::Geocoder::Params const & params, Results & res, - bool oldHouseSearch) +void Processor::SetRankPivot(m2::PointD const & pivot) { - vector indV; - vector streets; - - MakePreResult2(params, indV, streets); - RemoveDuplicatingLinear(indV); - if (indV.empty()) - return; - - sort(indV.begin(), indV.end(), my::LessBy(&IndexedValue::GetDistanceToPivot)); - - for (size_t i = 0; i < indV.size(); ++i) + if (!m2::AlmostEqualULPs(pivot, m_pivot)) { - if (IsCancelled()) - break; - - res.AddResultNoChecks( - (*(indV[i])) - .GenerateFinalResult(m_infoGetter, &m_categories, &m_prefferedTypes, - m_currentLocaleCode, - nullptr /* Viewport results don't need calculated address */)); + storage::CountryInfo ci; + m_infoGetter.GetRegionInfo(pivot, ci); + m_region.swap(ci.m_name); } + + m_pivot = pivot; +} + +void Processor::SetLanguage(int id, int8_t lang) +{ + m_keywordsScorer.SetLanguage(GetLangIndex(id), lang); +} + +int8_t Processor::GetLanguage(int id) const +{ + return m_keywordsScorer.GetLanguage(GetLangIndex(id)); +} + +m2::PointD Processor::GetPivotPoint() const +{ + m2::RectD const & viewport = m_viewport[CURRENT_V]; + if (viewport.IsPointInside(GetPosition())) + return GetPosition(); + return viewport.Center(); +} + +m2::RectD Processor::GetPivotRect() const +{ + m2::RectD const & viewport = m_viewport[CURRENT_V]; + if (viewport.IsPointInside(GetPosition())) + return GetRectAroundPosition(GetPosition()); + return NormalizeViewport(viewport); +} + +void Processor::SetViewportByIndex(TMWMVector const & mwmsInfo, m2::RectD const & viewport, + size_t idx, bool forceUpdate) +{ + ASSERT(idx < COUNT_V, (idx)); + + if (viewport.IsValid()) + { + // Check if we can skip this cache query. + if (m_viewport[idx].IsValid()) + { + // Threshold to compare for equal or inner rects. + // It doesn't influence on result cached features because it's smaller + // than minimal cell size in geometry index (i'm almost sure :)). + double constexpr epsMeters = 10.0; + + if (forceUpdate) + { + // skip if rects are equal + if (IsEqualMercator(m_viewport[idx], viewport, epsMeters)) + return; + } + else + { + // skip if the new viewport is inside the old one (no need to recache) + m2::RectD r(m_viewport[idx]); + double constexpr eps = epsMeters * MercatorBounds::degreeInMetres; + r.Inflate(eps, eps); + + if (r.IsRectInside(viewport)) + return; + } + } + + m_viewport[idx] = viewport; + } + else + { + ClearCache(idx); + } +} + +void Processor::ClearCache(size_t ind) { m_viewport[ind].MakeEmpty(); } + +int Processor::GetCategoryLocales(int8_t(&arr)[3]) const +{ + static int8_t const enLocaleCode = CategoriesHolder::MapLocaleToInteger("en"); + + // Prepare array of processing locales. English locale is always present for category matching. + int count = 0; + if (m_currentLocaleCode != -1) + arr[count++] = m_currentLocaleCode; + if (m_inputLocaleCode != -1 && m_inputLocaleCode != m_currentLocaleCode) + arr[count++] = m_inputLocaleCode; + if (enLocaleCode != m_currentLocaleCode && enLocaleCode != m_inputLocaleCode) + arr[count++] = enLocaleCode; + + return count; +} + +template +void Processor::ForEachCategoryTypes(StringSliceBase const & slice, ToDo toDo) const +{ + int8_t arrLocales[3]; + int const localesCount = GetCategoryLocales(arrLocales); + + for (size_t i = 0; i < slice.Size(); ++i) + { + auto token = RemoveHashtag(slice.Get(i)); + for (int j = 0; j < localesCount; ++j) + m_categories.ForEachTypeByName(arrLocales[j], token, bind(ref(toDo), i, _1)); + ProcessEmojiIfNeeded(token, i, toDo); + } +} + +template +void Processor::ProcessEmojiIfNeeded(strings::UniString const & token, size_t ind, + ToDo & toDo) const +{ + // Special process of 2 codepoints emoji (e.g. black guy on a bike). + // Only emoji synonyms can have one codepoint. + if (token.size() > 1) + { + static int8_t const enLocaleCode = CategoriesHolder::MapLocaleToInteger("en"); + + m_categories.ForEachTypeByName(enLocaleCode, strings::UniString(1, token[0]), + bind(ref(toDo), ind, _1)); + } +} + +int Processor::GetQueryIndexScale(m2::RectD const & viewport) const +{ + return search::GetQueryIndexScale(viewport); +} + +void Processor::Search(Results & results, size_t limit) +{ + if (m_tokens.empty()) + SuggestStrings(results); + + v2::Geocoder::Params params; + InitParams(false /* localitySearch */, params); + params.m_mode = m_mode; + + params.m_pivot = GetPivotRect(); + params.m_accuratePivotCenter = GetPivotPoint(); + m_geocoder.SetParams(params); + + m_geocoder.GoEverywhere(m_preRanker); + + FlushResults(params, results, false /* allMWMs */, limit, false /* oldHouseSearch */); +} + +void Processor::SearchViewportPoints(Results & results) +{ + v2::Geocoder::Params params; + InitParams(false /* localitySearch */, params); + params.m_pivot = m_viewport[CURRENT_V]; + params.m_accuratePivotCenter = params.m_pivot.Center(); + m_geocoder.SetParams(params); + + m_geocoder.GoInViewport(m_preRanker); + + FlushViewportResults(params, results, false /* oldHouseSearch */); } void Processor::SearchCoordinates(Results & res) const @@ -741,9 +746,30 @@ void Processor::FlushResults(v2::Geocoder::Params const & params, Results & res, } } -int Processor::GetQueryIndexScale(m2::RectD const & viewport) const +void Processor::FlushViewportResults(v2::Geocoder::Params const & params, Results & res, + bool oldHouseSearch) { - return search::GetQueryIndexScale(viewport); + vector indV; + vector streets; + + MakePreResult2(params, indV, streets); + RemoveDuplicatingLinear(indV); + if (indV.empty()) + return; + + sort(indV.begin(), indV.end(), my::LessBy(&IndexedValue::GetDistanceToPivot)); + + for (size_t i = 0; i < indV.size(); ++i) + { + if (IsCancelled()) + break; + + res.AddResultNoChecks( + (*(indV[i])) + .GenerateFinalResult(m_infoGetter, &m_categories, &m_prefferedTypes, + m_currentLocaleCode, + nullptr /* Viewport results don't need calculated address */)); + } } void Processor::RemoveStringPrefix(string const & str, string & res) const @@ -1159,6 +1185,19 @@ void Processor::InitParams(bool localitySearch, QueryParams & params) params.m_langs.insert(GetLanguage(i)); } +void Processor::ClearCaches() +{ + for (size_t i = 0; i < COUNT_V; ++i) + ClearCache(i); + + m_locality.ClearCache(); + m_geocoder.ClearCaches(); +} + +void Processor::Reset() { m_geocoder.Reset(); } + +void Processor::Cancel() { m_geocoder.Cancel(); } + void Processor::SuggestStrings(Results & res) { if (m_prefix.empty() || !m_suggestsEnabled) diff --git a/search/processor.hpp b/search/processor.hpp index e3febba23c..5b4800433e 100644 --- a/search/processor.hpp +++ b/search/processor.hpp @@ -50,6 +50,12 @@ namespace search struct Locality; struct Region; struct QueryParams; +class ReverseGeocoder; + +namespace v2 +{ +class Geocoder; +} // namespace search::v2 namespace impl { @@ -79,50 +85,48 @@ public: /// @param[in] forceUpdate Pass true (default) to recache feature's ids even /// if viewport is a part of the old cached rect. void SetViewport(m2::RectD const & viewport, bool forceUpdate); - + void SetPreferredLocale(string const & locale); + void SetInputLocale(string const & locale); + void SetQuery(string const & query); // TODO (@y): this function must be removed. void SetRankPivot(m2::PointD const & pivot); - inline string const & GetPivotRegion() const { return m_region; } - inline void SetPosition(m2::PointD const & position) { m_position = position; } - inline m2::PointD const & GetPosition() const { return m_position; } - inline void SetMode(Mode mode) { m_mode = mode; } inline void SetSearchInWorld(bool b) { m_worldSearch = b; } inline void SetSuggestsEnabled(bool enabled) { m_suggestsEnabled = enabled; } + inline void SetPosition(m2::PointD const & position) { m_position = position; } + + inline string const & GetPivotRegion() const { return m_region; } + inline m2::PointD const & GetPosition() const { return m_position; } + + // Get scale level to make geometry index query for current viewport. + int GetQueryIndexScale(m2::RectD const & viewport) const; /// Suggestions language code, not the same as we use in mwm data int8_t m_inputLocaleCode, m_currentLocaleCode; - void SetPreferredLocale(string const & locale); - void SetInputLocale(string const & locale); - - void SetQuery(string const & query); inline bool IsEmptyQuery() const { return (m_prefix.empty() && m_tokens.empty()); } - /// @name Different search functions. + /// @name Various search functions. //@{ - virtual void Search(Results & results, size_t limit) = 0; - virtual void SearchViewportPoints(Results & results) = 0; + void Search(Results & results, size_t limit); + void SearchViewportPoints(Results & results); // Tries to generate a (lat, lon) result from |m_query|. void SearchCoordinates(Results & res) const; //@} - // Get scale level to make geometry index query for current viewport. - virtual int GetQueryIndexScale(m2::RectD const & viewport) const; - - virtual void ClearCaches(); - struct CancelException { }; - /// @name This stuff is public for implementation classes in processor.cpp - /// Do not use it in client code. - //@{ - void InitParams(bool localitySearch, QueryParams & params); + void ClearCaches(); + + // my::Cancellable overrides: + void Reset() override; + void Cancel() override; + protected: enum ViewportID { @@ -164,8 +168,6 @@ protected: /// @param allMWMs Deprecated, need to support old search algorithm. /// @param oldHouseSearch Deprecated, need to support old search algorithm. //@{ - void FlushHouses(Results & res, bool allMWMs, vector const & streets); - void FlushResults(v2::Geocoder::Params const & params, Results & res, bool allMWMs, size_t resCount, bool oldHouseSearch); void FlushViewportResults(v2::Geocoder::Params const & params, Results & res, @@ -221,30 +223,12 @@ protected: bool m_supportOldFormat; - template - class TCompare - { - using TFunction = function; - TFunction m_fn; - - public: - TCompare() : m_fn(0) {} - explicit TCompare(TFunction const & fn) : m_fn(fn) {} - - template - bool operator()(T const & v1, T const & v2) const - { - return m_fn(v1, v2); - } - }; - - using TQueueCompare = TCompare; - using TQueue = my::limited_priority_queue; - protected: - PreRanker m_preRanker; bool m_viewportSearch; bool m_keepHouseNumberInQuery; - search::ReverseGeocoder const m_reverseGeocoder; + + PreRanker m_preRanker; + v2::Geocoder m_geocoder; + ReverseGeocoder const m_reverseGeocoder; }; } // namespace search diff --git a/search/processor_factory.hpp b/search/processor_factory.hpp index 83538df79f..e322d6bf10 100644 --- a/search/processor_factory.hpp +++ b/search/processor_factory.hpp @@ -1,7 +1,7 @@ #pragma once #include "search/suggest.hpp" -#include "search/v2/processor_v2.hpp" +#include "search/processor.hpp" #include "std/unique_ptr.hpp" @@ -21,7 +21,7 @@ public: vector const & suggests, storage::CountryInfoGetter const & infoGetter) { - return make_unique(index, categories, suggests, infoGetter); + return make_unique(index, categories, suggests, infoGetter); } }; } // namespace search diff --git a/search/search.pro b/search/search.pro index 8757ba31cf..504169295d 100644 --- a/search/search.pro +++ b/search/search.pro @@ -56,7 +56,6 @@ HEADERS += \ v2/mwm_context.hpp \ v2/nested_rects_cache.hpp \ v2/pre_ranking_info.hpp \ - v2/processor_v2.hpp \ v2/rank_table_cache.hpp \ v2/ranking_info.hpp \ v2/ranking_utils.hpp \ @@ -103,7 +102,6 @@ SOURCES += \ v2/mwm_context.cpp \ v2/nested_rects_cache.cpp \ v2/pre_ranking_info.cpp \ - v2/processor_v2.cpp \ v2/rank_table_cache.cpp \ v2/ranking_info.cpp \ v2/ranking_utils.cpp \ diff --git a/search/search_engine.cpp b/search/search_engine.cpp index 7bb5ac4cdd..5bfe2f6c42 100644 --- a/search/search_engine.cpp +++ b/search/search_engine.cpp @@ -160,9 +160,9 @@ Engine::~Engine() weak_ptr Engine::Search(SearchParams const & params, m2::RectD const & viewport) { shared_ptr handle(new ProcessorHandle()); - PostMessage(Message::TYPE_TASK, [this, params, viewport, handle](Processor & query) + PostMessage(Message::TYPE_TASK, [this, params, viewport, handle](Processor & processor) { - DoSearch(params, viewport, handle, query); + DoSearch(params, viewport, handle, processor); }); return handle; } diff --git a/search/search_integration_tests/search_query_v2_test.cpp b/search/search_integration_tests/processor_test.cpp similarity index 98% rename from search/search_integration_tests/search_query_v2_test.cpp rename to search/search_integration_tests/processor_test.cpp index 679d3e81a4..4d81c982d9 100644 --- a/search/search_integration_tests/search_query_v2_test.cpp +++ b/search/search_integration_tests/processor_test.cpp @@ -30,7 +30,7 @@ namespace search { namespace { -class ProcessorV2Test : public SearchTest +class ProcessorTest : public SearchTest { public: unique_ptr MakeRequest(string const & query) @@ -53,7 +53,7 @@ public: } }; -UNIT_CLASS_TEST(ProcessorV2Test, Smoke) +UNIT_CLASS_TEST(ProcessorTest, Smoke) { string const countryName = "Wonderland"; TestCountry wonderlandCountry(m2::PointD(10, 10), countryName, "en"); @@ -193,7 +193,7 @@ UNIT_CLASS_TEST(ProcessorV2Test, Smoke) } } -UNIT_CLASS_TEST(ProcessorV2Test, SearchInWorld) +UNIT_CLASS_TEST(ProcessorTest, SearchInWorld) { string const countryName = "Wonderland"; TestCountry wonderland(m2::PointD(0, 0), countryName, "en"); @@ -221,7 +221,7 @@ UNIT_CLASS_TEST(ProcessorV2Test, SearchInWorld) } } -UNIT_CLASS_TEST(ProcessorV2Test, SearchByName) +UNIT_CLASS_TEST(ProcessorTest, SearchByName) { string const countryName = "Wonderland"; TestCity london(m2::PointD(1, 1), "London", "en", 100 /* rank */); @@ -259,7 +259,7 @@ UNIT_CLASS_TEST(ProcessorV2Test, SearchByName) } } -UNIT_CLASS_TEST(ProcessorV2Test, DisableSuggests) +UNIT_CLASS_TEST(ProcessorTest, DisableSuggests) { TestCity london1(m2::PointD(1, 1), "London", "en", 100 /* rank */); TestCity london2(m2::PointD(-1, -1), "London", "en", 100 /* rank */); @@ -286,7 +286,7 @@ UNIT_CLASS_TEST(ProcessorV2Test, DisableSuggests) } } -UNIT_CLASS_TEST(ProcessorV2Test, TestRankingInfo) +UNIT_CLASS_TEST(ProcessorTest, TestRankingInfo) { string const countryName = "Wonderland"; @@ -367,7 +367,7 @@ UNIT_CLASS_TEST(ProcessorV2Test, TestRankingInfo) } } -UNIT_CLASS_TEST(ProcessorV2Test, TestPostcodes) +UNIT_CLASS_TEST(ProcessorTest, TestPostcodes) { string const countryName = "Russia"; @@ -441,7 +441,6 @@ UNIT_CLASS_TEST(ProcessorV2Test, TestPostcodes) { TRules rules{ExactMatch(countryId, building28), ExactMatch(countryId, building29)}; TEST(ResultsMatch("Долгопрудный первомайская 141701", "ru", rules), ()); - } { TRules rules{ExactMatch(countryId, building28), ExactMatch(countryId, building29)}; @@ -462,7 +461,7 @@ UNIT_CLASS_TEST(ProcessorV2Test, TestPostcodes) } } -UNIT_CLASS_TEST(ProcessorV2Test, TestCategories) +UNIT_CLASS_TEST(ProcessorTest, TestCategories) { string const countryName = "Wonderland"; diff --git a/search/search_integration_tests/search_integration_tests.pro b/search/search_integration_tests/search_integration_tests.pro index 8b10e50c53..2ede061546 100644 --- a/search/search_integration_tests/search_integration_tests.pro +++ b/search/search_integration_tests/search_integration_tests.pro @@ -19,10 +19,10 @@ macx-*: LIBS *= "-framework IOKit" SOURCES += \ ../../testing/testingmain.cpp \ - helpers.cpp \ - search_query_v2_test.cpp \ - smoke_test.cpp \ generate_tests.cpp \ + helpers.cpp \ + processor_test.cpp \ + smoke_test.cpp \ HEADERS += \ helpers.hpp \ diff --git a/search/v2/processor_v2.cpp b/search/v2/processor_v2.cpp deleted file mode 100644 index 277d859dd7..0000000000 --- a/search/v2/processor_v2.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include "search/v2/processor_v2.hpp" - -#include "search/dummy_rank_table.hpp" - -#include "indexer/rank_table.hpp" - -#include "geometry/mercator.hpp" -#include "geometry/rect2d.hpp" - -#include "base/macros.hpp" - -namespace search -{ -namespace v2 -{ -ProcessorV2::ProcessorV2(Index & index, CategoriesHolder const & categories, - vector const & suggests, - storage::CountryInfoGetter const & infoGetter) - : Processor(index, categories, suggests, infoGetter), m_geocoder(index, infoGetter) -{ - m_keepHouseNumberInQuery = true; -} - -void ProcessorV2::Reset() -{ - Processor::Reset(); - m_geocoder.Reset(); -} - -void ProcessorV2::Cancel() -{ - Processor::Cancel(); - m_geocoder.Cancel(); -} - -void ProcessorV2::Search(Results & results, size_t limit) -{ - if (m_tokens.empty()) - SuggestStrings(results); - - Geocoder::Params params; - InitParams(false /* localitySearch */, params); - params.m_mode = m_mode; - - params.m_pivot = GetPivotRect(); - params.m_accuratePivotCenter = GetPivotPoint(); - m_geocoder.SetParams(params); - - m_geocoder.GoEverywhere(m_preRanker); - - FlushResults(params, results, false /* allMWMs */, limit, false /* oldHouseSearch */); -} - -void ProcessorV2::SearchViewportPoints(Results & results) -{ - Geocoder::Params params; - InitParams(false /* localitySearch */, params); - params.m_pivot = m_viewport[CURRENT_V]; - params.m_accuratePivotCenter = params.m_pivot.Center(); - m_geocoder.SetParams(params); - - m_geocoder.GoInViewport(m_preRanker); - - FlushViewportResults(params, results, false /* oldHouseSearch */); -} - -void ProcessorV2::ClearCaches() -{ - Processor::ClearCaches(); - m_geocoder.ClearCaches(); -} -} // namespace v2 -} // namespace search diff --git a/search/v2/processor_v2.hpp b/search/v2/processor_v2.hpp deleted file mode 100644 index c76a494458..0000000000 --- a/search/v2/processor_v2.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include "search/processor.hpp" -#include "search/v2/geocoder.hpp" - -namespace search -{ -namespace v2 -{ -class ProcessorV2 : public Processor -{ -public: - ProcessorV2(Index & index, CategoriesHolder const & categories, vector const & suggests, - storage::CountryInfoGetter const & infoGetter); - - // my::Cancellable overrides: - void Reset() override; - void Cancel() override; - - // Query overrides: - void Search(Results & results, size_t limit) override; - void SearchViewportPoints(Results & results) override; - void ClearCaches() override; - -protected: - Geocoder m_geocoder; -}; -} // namespace v2 -} // namespace search From 4cb85be42ae4b832e7bc67090cca871a577ebf6b Mon Sep 17 00:00:00 2001 From: Maxim Pimenov Date: Tue, 31 May 2016 00:06:30 +0300 Subject: [PATCH 2/2] Review fixes. --- search/processor.cpp | 78 ++++++++++++++---------------------- search/processor.hpp | 15 ++----- search/processor_factory.hpp | 2 +- 3 files changed, 35 insertions(+), 60 deletions(-) diff --git a/search/processor.cpp b/search/processor.cpp index 30ef79a680..d3a4727094 100644 --- a/search/processor.cpp +++ b/search/processor.cpp @@ -289,14 +289,12 @@ void Processor::SetPreferredLocale(string const & locale) void Processor::SetInputLocale(string const & locale) { - if (!locale.empty()) - { - LOG(LDEBUG, ("New input locale:", locale)); + if (locale.empty()) + return; - SetLanguage(LANG_INPUT, StringUtf8Multilang::GetLangIndex(languages::Normalize(locale))); - - m_inputLocaleCode = CategoriesHolder::MapLocaleToInteger(locale); - } + LOG(LDEBUG, ("New input locale:", locale)); + SetLanguage(LANG_INPUT, StringUtf8Multilang::GetLangIndex(languages::Normalize(locale))); + m_inputLocaleCode = CategoriesHolder::MapLocaleToInteger(locale); } void Processor::SetQuery(string const & query) @@ -494,18 +492,13 @@ void Processor::ProcessEmojiIfNeeded(strings::UniString const & token, size_t in } } -int Processor::GetQueryIndexScale(m2::RectD const & viewport) const -{ - return search::GetQueryIndexScale(viewport); -} - void Processor::Search(Results & results, size_t limit) { if (m_tokens.empty()) SuggestStrings(results); v2::Geocoder::Params params; - InitParams(false /* localitySearch */, params); + InitParams(params); params.m_mode = m_mode; params.m_pivot = GetPivotRect(); @@ -514,20 +507,20 @@ void Processor::Search(Results & results, size_t limit) m_geocoder.GoEverywhere(m_preRanker); - FlushResults(params, results, false /* allMWMs */, limit, false /* oldHouseSearch */); + FlushResults(params, results, limit); } void Processor::SearchViewportPoints(Results & results) { v2::Geocoder::Params params; - InitParams(false /* localitySearch */, params); + InitParams(params); params.m_pivot = m_viewport[CURRENT_V]; params.m_accuratePivotCenter = params.m_pivot.Center(); m_geocoder.SetParams(params); m_geocoder.GoInViewport(m_preRanker); - FlushViewportResults(params, results, false /* oldHouseSearch */); + FlushViewportResults(params, results); } void Processor::SearchCoordinates(Results & res) const @@ -714,8 +707,7 @@ void Processor::MakePreResult2(v2::Geocoder::Params const & params, vector & }); } -void Processor::FlushResults(v2::Geocoder::Params const & params, Results & res, bool allMWMs, - size_t resCount, bool oldHouseSearch) +void Processor::FlushResults(v2::Geocoder::Params const & params, Results & res, size_t resCount) { vector indV; vector streets; @@ -727,9 +719,7 @@ void Processor::FlushResults(v2::Geocoder::Params const & params, Results & res, sort(indV.rbegin(), indV.rend(), my::LessBy(&IndexedValue::GetRank)); - // Do not process suggestions in additional search. - if (!allMWMs || res.GetCount() == 0) - ProcessSuggestions(indV, res); + ProcessSuggestions(indV, res); // Emit feature results. size_t count = res.GetCount(); @@ -746,8 +736,7 @@ void Processor::FlushResults(v2::Geocoder::Params const & params, Results & res, } } -void Processor::FlushViewportResults(v2::Geocoder::Params const & params, Results & res, - bool oldHouseSearch) +void Processor::FlushViewportResults(v2::Geocoder::Params const & params, Results & res) { vector indV; vector streets; @@ -1129,7 +1118,7 @@ int GetOldTypeFromIndex(size_t index) } } // namespace -void Processor::InitParams(bool localitySearch, QueryParams & params) +void Processor::InitParams(QueryParams & params) { params.Clear(); @@ -1146,32 +1135,27 @@ void Processor::InitParams(bool localitySearch, QueryParams & params) params.m_isCategorySynonym.assign(tokensCount + (m_prefix.empty() ? 0 : 1), false); // Add names of categories (and synonyms). - if (!localitySearch) - { - Classificator const & c = classif(); - auto addSyms = [&](size_t i, uint32_t t) + Classificator const & c = classif(); + auto addSyms = [&](size_t i, uint32_t t) { + QueryParams::TSynonymsVector & v = params.GetTokens(i); + + uint32_t const index = c.GetIndexForType(t); + v.push_back(FeatureTypeToString(index)); + params.m_isCategorySynonym[i] = true; + + // v2-version MWM has raw classificator types in search index prefix, so + // do the hack: add synonyms for old convention if needed. + if (m_supportOldFormat) { - QueryParams::TSynonymsVector & v = params.GetTokens(i); - - uint32_t const index = c.GetIndexForType(t); - v.push_back(FeatureTypeToString(index)); - params.m_isCategorySynonym[i] = true; - - // v2-version MWM has raw classificator types in search index prefix, so - // do the hack: add synonyms for old convention if needed. - if (m_supportOldFormat) + int const type = GetOldTypeFromIndex(index); + if (type >= 0) { - int const type = GetOldTypeFromIndex(index); - if (type >= 0) - { - ASSERT(type == 70 || type > 4000, (type)); - v.push_back(FeatureTypeToString(static_cast(type))); - } + ASSERT(type == 70 || type > 4000, (type)); + v.push_back(FeatureTypeToString(static_cast(type))); } - }; - ForEachCategoryTypes(v2::QuerySliceOnRawStrings(m_tokens, m_prefix), - addSyms); - } + } + }; + ForEachCategoryTypes(v2::QuerySliceOnRawStrings(m_tokens, m_prefix), addSyms); for (auto & tokens : params.m_tokens) { diff --git a/search/processor.hpp b/search/processor.hpp index 5b4800433e..514b2e1994 100644 --- a/search/processor.hpp +++ b/search/processor.hpp @@ -98,9 +98,6 @@ public: inline string const & GetPivotRegion() const { return m_region; } inline m2::PointD const & GetPosition() const { return m_position; } - // Get scale level to make geometry index query for current viewport. - int GetQueryIndexScale(m2::RectD const & viewport) const; - /// Suggestions language code, not the same as we use in mwm data int8_t m_inputLocaleCode, m_currentLocaleCode; @@ -119,7 +116,7 @@ public: { }; - void InitParams(bool localitySearch, QueryParams & params); + void InitParams(QueryParams & params); void ClearCaches(); @@ -165,14 +162,8 @@ protected: void MakePreResult2(v2::Geocoder::Params const & params, vector & cont, vector & streets); - /// @param allMWMs Deprecated, need to support old search algorithm. - /// @param oldHouseSearch Deprecated, need to support old search algorithm. - //@{ - void FlushResults(v2::Geocoder::Params const & params, Results & res, bool allMWMs, - size_t resCount, bool oldHouseSearch); - void FlushViewportResults(v2::Geocoder::Params const & params, Results & res, - bool oldHouseSearch); - //@} + void FlushResults(v2::Geocoder::Params const & params, Results & res, size_t resCount); + void FlushViewportResults(v2::Geocoder::Params const & params, Results & res); void RemoveStringPrefix(string const & str, string & res) const; void GetSuggestion(string const & name, string & suggest) const; diff --git a/search/processor_factory.hpp b/search/processor_factory.hpp index e322d6bf10..5e0fc0fe78 100644 --- a/search/processor_factory.hpp +++ b/search/processor_factory.hpp @@ -1,7 +1,7 @@ #pragma once -#include "search/suggest.hpp" #include "search/processor.hpp" +#include "search/suggest.hpp" #include "std/unique_ptr.hpp"