From ca2248c3ff2187d6f4e1d3a43696be251d1a93ca Mon Sep 17 00:00:00 2001 From: vng Date: Tue, 19 Jan 2016 16:57:45 +0300 Subject: [PATCH] [search] Restore multiple search on map. --- search/search_query.cpp | 15 ++++++++--- search/search_query.hpp | 9 ++++++- search/v2/geocoder.cpp | 48 ++++++++++++++++++++++++++++++----- search/v2/geocoder.hpp | 7 +++-- search/v2/search_query_v2.cpp | 19 +++++++++++--- 5 files changed, 81 insertions(+), 17 deletions(-) diff --git a/search/search_query.cpp b/search/search_query.cpp index 341be8feb1..5dd0bc1d9f 100644 --- a/search/search_query.cpp +++ b/search/search_query.cpp @@ -534,7 +534,7 @@ void Query::Search(Results & res, size_t resCount) LONG_OP(SearchAddress(res)); LONG_OP(SearchFeatures()); - LONG_OP(FlushResults(res, false, resCount)); + LONG_OP(FlushResults(res, false /* allMWMs */, resCount, true /* oldHouseSearch */)); } void Query::SearchViewportPoints(Results & res) @@ -542,6 +542,11 @@ void Query::SearchViewportPoints(Results & res) LONG_OP(SearchAddress(res)); LONG_OP(SearchFeaturesInViewport(CURRENT_V)); + FlushViewportResults(res, true /* oldHouseSearch */); +} + +void Query::FlushViewportResults(Results & res, bool oldHouseSearch) +{ vector indV; vector streets; @@ -552,7 +557,8 @@ void Query::SearchViewportPoints(Results & res) RemoveDuplicatingLinear(indV); #ifdef HOUSE_SEARCH_TEST - FlushHouses(res, false, streets); + if (oldHouseSearch) + FlushHouses(res, false, streets); #endif for (size_t i = 0; i < indV.size(); ++i) @@ -794,7 +800,7 @@ void Query::FlushHouses(Results & res, bool allMWMs, vector const & s } } -void Query::FlushResults(Results & res, bool allMWMs, size_t resCount) +void Query::FlushResults(Results & res, bool allMWMs, size_t resCount, bool oldHouseSearch) { vector indV; vector streets; @@ -813,7 +819,8 @@ void Query::FlushResults(Results & res, bool allMWMs, size_t resCount) ProcessSuggestions(indV, res); #ifdef HOUSE_SEARCH_TEST - FlushHouses(res, allMWMs, streets); + if (oldHouseSearch) + FlushHouses(res, allMWMs, streets); #endif // emit feature results diff --git a/search/search_query.hpp b/search/search_query.hpp index f63d08829a..ef2ac2f41f 100644 --- a/search/search_query.hpp +++ b/search/search_query.hpp @@ -175,8 +175,15 @@ protected: ViewportID viewportId = DEFAULT_V); template void MakePreResult2(vector & cont, vector & streets); + + /// @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(Results & res, bool allMWMs, size_t resCount); + + void FlushResults(Results & res, bool allMWMs, size_t resCount, bool oldHouseSearch); + void FlushViewportResults(Results & res, bool oldHouseSearch); + //@} void RemoveStringPrefix(string const & str, string & res) const; void GetSuggestion(string const & name, string & suggest) const; diff --git a/search/v2/geocoder.cpp b/search/v2/geocoder.cpp index d4783f682e..fdd5339667 100644 --- a/search/v2/geocoder.cpp +++ b/search/v2/geocoder.cpp @@ -178,7 +178,7 @@ bool HasSearchIndex(MwmValue const & value) { return value.m_cont.IsExist(SEARCH bool HasGeometryIndex(MwmValue & value) { return value.m_cont.IsExist(INDEX_FILE_TAG); } -MwmSet::MwmHandle FindWorld(Index & index, vector> & infos) +MwmSet::MwmHandle FindWorld(Index & index, vector> const & infos) { MwmSet::MwmHandle handle; for (auto const & info : infos) @@ -291,11 +291,34 @@ void Geocoder::Go(vector & results) m_results = &results; + vector> infos; + m_index.GetMwmsInfo(infos); + + GoImpl(infos, false /* inViewport */); +} + +void Geocoder::GoInViewport(vector & results) +{ + if (m_numTokens == 0) + return; + + m_results = &results; + + vector> infos; + m_index.GetMwmsInfo(infos); + + infos.erase(remove_if(infos.begin(), infos.end(), [this](shared_ptr p) + { + return !m_params.m_viewport.IsIntersect(p->m_limitRect); + }), infos.end()); + + GoImpl(infos, true /* inViewport */); +} + +void Geocoder::GoImpl(vector> & infos, bool inViewport) +{ try { - vector> infos; - m_index.GetMwmsInfo(infos); - // Tries to find world and fill localities table. { m_cities.clear(); @@ -344,14 +367,26 @@ void Geocoder::Go(vector & results) m_matcher.reset(new FeaturesLayerMatcher(m_index, *m_context, *this /* cancellable */)); + unique_ptr viewportCBV; + if (inViewport) + { + viewportCBV = Retrieval::RetrieveGeometryFeatures( + m_context->m_value, static_cast(*this), + m_params.m_viewport, m_params.m_scale); + } + // Creates a cache of posting lists for each token. m_addressFeatures.resize(m_numTokens); for (size_t i = 0; i < m_numTokens; ++i) { PrepareRetrievalParams(i, i + 1); + m_addressFeatures[i] = Retrieval::RetrieveAddressFeatures( m_context->m_value, *this /* cancellable */, m_retrievalParams); ASSERT(m_addressFeatures[i], ()); + + if (viewportCBV) + m_addressFeatures[i] = coding::CompressedBitVector::Intersect(*m_addressFeatures[i], *viewportCBV); } m_streets = LoadStreets(*m_context); @@ -647,7 +682,8 @@ void Geocoder::MatchViewportAndPosition() } // Extracts features around user position. - if (!position.EqualDxDy(viewport.Center(), kComparePoints)) + if (!position.EqualDxDy({0, 0}, kComparePoints) && + !position.EqualDxDy(viewport.Center(), kComparePoints)) { m2::RectD const rect = GetRectAroundPoistion(position); allFeatures.Union(RetrieveGeometryFeatures(*m_context, rect, POSITION_ID)); @@ -797,7 +833,7 @@ void Geocoder::MatchPOIsAndBuildings(size_t curToken) SearchModel::SearchType const searchType = m_model.GetSearchType(feature); // All SEARCH_TYPE_CITY features were filtered in DoGeocodingWithLocalities(). - // All SEARCH_TYPE_STREET features were filtered in GreedyMatchStreets(). + // All SEARCH_TYPE_STREET features were filtered in GreedilyMatchStreets(). if (searchType < SearchModel::SEARCH_TYPE_STREET) clusters[searchType].push_back(featureId); }; diff --git a/search/v2/geocoder.hpp b/search/v2/geocoder.hpp index a042dad899..c9c5480162 100644 --- a/search/v2/geocoder.hpp +++ b/search/v2/geocoder.hpp @@ -8,7 +8,6 @@ #include "search/v2/mwm_context.hpp" #include "search/v2/search_model.hpp" -#include "indexer/mwm_set.hpp" #include "indexer/index.hpp" #include "coding/compressed_bit_vector.hpp" @@ -26,6 +25,7 @@ #include "std/unordered_map.hpp" #include "std/vector.hpp" +class MwmInfo; class MwmValue; namespace coding @@ -68,7 +68,7 @@ public: Params(); m2::RectD m_viewport; - m2::PointD m_position; + m2::PointD m_position; ///< Default = {0, 0} as empty. size_t m_maxNumResults; }; @@ -82,10 +82,13 @@ public: // Starts geocoding, retrieved features will be appended to // |results|. void Go(vector & results); + void GoInViewport(vector & results); void ClearCaches(); private: + void GoImpl(vector> & infos, bool inViewport); + struct Locality { uint32_t m_featureId = 0; diff --git a/search/v2/search_query_v2.cpp b/search/v2/search_query_v2.cpp index 0e2f975f05..fb6cbc39b5 100644 --- a/search/v2/search_query_v2.cpp +++ b/search/v2/search_query_v2.cpp @@ -32,8 +32,6 @@ void SearchQueryV2::Cancel() void SearchQueryV2::Search(Results & res, size_t resCount) { - if (IsCancelled()) - return; if (m_tokens.empty()) SuggestStrings(res); @@ -48,10 +46,23 @@ void SearchQueryV2::Search(Results & res, size_t resCount) m_geocoder.Go(results); AddPreResults1(results); - FlushResults(res, false /* allMWMs */, resCount); + FlushResults(res, false /* allMWMs */, resCount, false /* oldHouseSearch */); } -void SearchQueryV2::SearchViewportPoints(Results & res) { NOTIMPLEMENTED(); } +void SearchQueryV2::SearchViewportPoints(Results & res) +{ + Geocoder::Params params; + InitParams(false /* localitySearch */, params); + params.m_viewport = m_viewport[CURRENT_V]; + params.m_maxNumResults = kPreResultsCount; + m_geocoder.SetParams(params); + + vector results; + m_geocoder.GoInViewport(results); + AddPreResults1(results); + + FlushViewportResults(res, false /* oldHouseSearch */); +} void SearchQueryV2::ClearCaches() {