forked from organicmaps/organicmaps
[search] Restore multiple search on map.
This commit is contained in:
parent
ba3d16283a
commit
ca2248c3ff
5 changed files with 81 additions and 17 deletions
|
@ -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<IndexedValue> indV;
|
||||
vector<FeatureID> 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<FeatureID> 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<IndexedValue> indV;
|
||||
vector<FeatureID> 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
|
||||
|
|
|
@ -175,8 +175,15 @@ protected:
|
|||
ViewportID viewportId = DEFAULT_V);
|
||||
|
||||
template <class T> void MakePreResult2(vector<T> & cont, vector<FeatureID> & 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<FeatureID> 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;
|
||||
|
|
|
@ -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<shared_ptr<MwmInfo>> & infos)
|
||||
MwmSet::MwmHandle FindWorld(Index & index, vector<shared_ptr<MwmInfo>> const & infos)
|
||||
{
|
||||
MwmSet::MwmHandle handle;
|
||||
for (auto const & info : infos)
|
||||
|
@ -291,11 +291,34 @@ void Geocoder::Go(vector<FeatureID> & results)
|
|||
|
||||
m_results = &results;
|
||||
|
||||
vector<shared_ptr<MwmInfo>> infos;
|
||||
m_index.GetMwmsInfo(infos);
|
||||
|
||||
GoImpl(infos, false /* inViewport */);
|
||||
}
|
||||
|
||||
void Geocoder::GoInViewport(vector<FeatureID> & results)
|
||||
{
|
||||
if (m_numTokens == 0)
|
||||
return;
|
||||
|
||||
m_results = &results;
|
||||
|
||||
vector<shared_ptr<MwmInfo>> infos;
|
||||
m_index.GetMwmsInfo(infos);
|
||||
|
||||
infos.erase(remove_if(infos.begin(), infos.end(), [this](shared_ptr<MwmInfo> p)
|
||||
{
|
||||
return !m_params.m_viewport.IsIntersect(p->m_limitRect);
|
||||
}), infos.end());
|
||||
|
||||
GoImpl(infos, true /* inViewport */);
|
||||
}
|
||||
|
||||
void Geocoder::GoImpl(vector<shared_ptr<MwmInfo>> & infos, bool inViewport)
|
||||
{
|
||||
try
|
||||
{
|
||||
vector<shared_ptr<MwmInfo>> infos;
|
||||
m_index.GetMwmsInfo(infos);
|
||||
|
||||
// Tries to find world and fill localities table.
|
||||
{
|
||||
m_cities.clear();
|
||||
|
@ -344,14 +367,26 @@ void Geocoder::Go(vector<FeatureID> & results)
|
|||
|
||||
m_matcher.reset(new FeaturesLayerMatcher(m_index, *m_context, *this /* cancellable */));
|
||||
|
||||
unique_ptr<coding::CompressedBitVector> viewportCBV;
|
||||
if (inViewport)
|
||||
{
|
||||
viewportCBV = Retrieval::RetrieveGeometryFeatures(
|
||||
m_context->m_value, static_cast<my::Cancellable const &>(*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);
|
||||
};
|
||||
|
|
|
@ -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<FeatureID> & results);
|
||||
void GoInViewport(vector<FeatureID> & results);
|
||||
|
||||
void ClearCaches();
|
||||
|
||||
private:
|
||||
void GoImpl(vector<shared_ptr<MwmInfo>> & infos, bool inViewport);
|
||||
|
||||
struct Locality
|
||||
{
|
||||
uint32_t m_featureId = 0;
|
||||
|
|
|
@ -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<FeatureID> results;
|
||||
m_geocoder.GoInViewport(results);
|
||||
AddPreResults1(results);
|
||||
|
||||
FlushViewportResults(res, false /* oldHouseSearch */);
|
||||
}
|
||||
|
||||
void SearchQueryV2::ClearCaches()
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue