forked from organicmaps/organicmaps
[search] Filter villages by distance from viewport center/user position/region center.
This commit is contained in:
parent
c55650aa52
commit
8484170d95
8 changed files with 50 additions and 8 deletions
|
@ -424,7 +424,8 @@ void Geocoder::SetParamsForCategorialSearch(Params const & params)
|
|||
|
||||
Geocoder::ExtendedMwmInfos::ExtendedMwmInfo Geocoder::GetExtendedMwmInfo(
|
||||
shared_ptr<MwmInfo> const & info, bool inViewport,
|
||||
function<bool(shared_ptr<MwmInfo> const &)> const & isMwmWithMatchedCity) const
|
||||
function<bool(shared_ptr<MwmInfo> const &)> const & isMwmWithMatchedCity,
|
||||
function<bool(shared_ptr<MwmInfo> const &)> const & isMwmWithMatchedState) const
|
||||
{
|
||||
ExtendedMwmInfos::ExtendedMwmInfo extendedInfo;
|
||||
extendedInfo.m_info = info;
|
||||
|
@ -434,6 +435,7 @@ Geocoder::ExtendedMwmInfos::ExtendedMwmInfo Geocoder::GetExtendedMwmInfo(
|
|||
extendedInfo.m_type.m_containsUserPosition =
|
||||
m_params.m_position && rect.IsPointInside(*m_params.m_position);
|
||||
extendedInfo.m_type.m_containsMatchedCity = isMwmWithMatchedCity(info);
|
||||
extendedInfo.m_type.m_containsMatchedState = isMwmWithMatchedState(info);
|
||||
|
||||
extendedInfo.m_similarity = GetSimilarity(m_params.m_pivot, rect);
|
||||
if (!inViewport && extendedInfo.m_type.m_containsUserPosition)
|
||||
|
@ -447,6 +449,7 @@ Geocoder::ExtendedMwmInfos Geocoder::OrderCountries(bool inViewport,
|
|||
vector<shared_ptr<MwmInfo>> const & infos)
|
||||
{
|
||||
set<storage::CountryId> mwmsWithCities;
|
||||
set<storage::CountryId> mwmsWithStates;
|
||||
if (!inViewport)
|
||||
{
|
||||
for (auto const & p : m_cities)
|
||||
|
@ -454,15 +457,26 @@ Geocoder::ExtendedMwmInfos Geocoder::OrderCountries(bool inViewport,
|
|||
for (auto const & city : p.second)
|
||||
mwmsWithCities.insert(m_infoGetter.GetRegionCountryId(city.m_rect.Center()));
|
||||
}
|
||||
for (auto const & p : m_regions[Region::TYPE_STATE])
|
||||
{
|
||||
for (auto const & state : p.second)
|
||||
{
|
||||
mwmsWithStates.insert(m_infoGetter.GetRegionCountryId(state.m_center));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ExtendedMwmInfos res;
|
||||
res.m_infos.reserve(infos.size());
|
||||
auto const hasMatchedCity = [&mwmsWithCities](auto const & i) {
|
||||
return mwmsWithCities.count(i->GetCountryName()) != 0;
|
||||
};
|
||||
auto const hasMatchedState = [&mwmsWithStates](auto const & i) {
|
||||
return mwmsWithStates.count(i->GetCountryName()) != 0;
|
||||
};
|
||||
for (auto const & info : infos)
|
||||
{
|
||||
res.m_infos.push_back(GetExtendedMwmInfo(info, inViewport, [&mwmsWithCities](auto const & i) {
|
||||
return mwmsWithCities.count(i->GetCountryName()) != 0;
|
||||
}));
|
||||
res.m_infos.push_back(GetExtendedMwmInfo(info, inViewport, hasMatchedCity, hasMatchedState));
|
||||
}
|
||||
sort(res.m_infos.begin(), res.m_infos.end());
|
||||
|
||||
|
@ -766,8 +780,24 @@ void Geocoder::FillVillageLocalities(BaseContext const & ctx)
|
|||
if (m_model.GetType(*ft) != Model::TYPE_VILLAGE)
|
||||
continue;
|
||||
|
||||
// We accept lines and areas as village features.
|
||||
auto const center = feature::GetCenter(*ft);
|
||||
m2::PointD center;
|
||||
// m_context->GetCenter is faster but may not work for editor created features.
|
||||
if (!m_context->GetCenter(l.m_featureId, center))
|
||||
center = feature::GetCenter(*ft);
|
||||
|
||||
vector<m2::PointD> pivotPoints = {m_params.m_pivot.Center()};
|
||||
if (m_params.m_position)
|
||||
pivotPoints.push_back(*m_params.m_position);
|
||||
auto const mwmType = m_context->GetType();
|
||||
CHECK(mwmType, ());
|
||||
if (!mwmType->m_containsMatchedState &&
|
||||
!any_of(pivotPoints.begin(), pivotPoints.end(), [&](auto const & p) {
|
||||
return mercator::DistanceOnEarth(center, p) <= m_params.m_villageSearchRadiusM;
|
||||
}))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
++numVillages;
|
||||
City village(l, Model::TYPE_VILLAGE);
|
||||
|
||||
|
|
|
@ -93,6 +93,7 @@ public:
|
|||
std::vector<uint32_t> m_preferredTypes;
|
||||
std::shared_ptr<Tracer> m_tracer;
|
||||
double m_streetSearchRadiusM = 0.0;
|
||||
double m_villageSearchRadiusM = 0.0;
|
||||
};
|
||||
|
||||
Geocoder(DataSource const & dataSource, storage::CountryInfoGetter const & infoGetter,
|
||||
|
@ -285,7 +286,8 @@ private:
|
|||
|
||||
ExtendedMwmInfos::ExtendedMwmInfo GetExtendedMwmInfo(
|
||||
std::shared_ptr<MwmInfo> const & info, bool inViewport,
|
||||
std::function<bool(std::shared_ptr<MwmInfo> const &)> const & isMwmWithMatchedCity) const;
|
||||
std::function<bool(std::shared_ptr<MwmInfo> const &)> const & isMwmWithMatchedCity,
|
||||
std::function<bool(std::shared_ptr<MwmInfo> const &)> const & isMwmWithMatchedState) const;
|
||||
|
||||
// Reorders maps in a way that prefix consists of "best" maps to search and suffix consists of all
|
||||
// other maps ordered by minimum distance from pivot. Returns ExtendedMwmInfos structure which
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
bool m_viewportIntersected = false;
|
||||
bool m_containsUserPosition = false;
|
||||
bool m_containsMatchedCity = false;
|
||||
bool m_containsMatchedState = false;
|
||||
};
|
||||
|
||||
explicit MwmContext(MwmSet::MwmHandle handle);
|
||||
|
|
|
@ -730,6 +730,7 @@ void Processor::InitGeocoder(Geocoder::Params & geocoderParams, SearchParams con
|
|||
geocoderParams.m_preferredTypes = m_preferredTypes;
|
||||
geocoderParams.m_tracer = searchParams.m_tracer;
|
||||
geocoderParams.m_streetSearchRadiusM = searchParams.m_streetSearchRadiusM;
|
||||
geocoderParams.m_villageSearchRadiusM = searchParams.m_villageSearchRadiusM;
|
||||
|
||||
m_geocoder.SetParams(geocoderParams);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,8 @@ struct SearchParams
|
|||
inline static size_t const kDefaultNumResultsEverywhere = 30;
|
||||
inline static size_t const kDefaultNumResultsInViewport = 200;
|
||||
inline static size_t const kPreResultsCount = 200;
|
||||
inline static double const kDefaultStreetSearchRadiusM = 80000;
|
||||
inline static double const kDefaultStreetSearchRadiusM = 8e4;
|
||||
inline static double const kDefaultVillageSearchRadiusM = 2e5;
|
||||
inline static std::chrono::steady_clock::duration const kDefaultTimeout =
|
||||
std::chrono::seconds(3);
|
||||
inline static std::chrono::steady_clock::duration const kDefaultDesktopTimeout =
|
||||
|
@ -76,6 +77,8 @@ struct SearchParams
|
|||
|
||||
// Street search radius from pivot or matched city center for everywhere search mode.
|
||||
double m_streetSearchRadiusM = kDefaultStreetSearchRadiusM;
|
||||
// Street search radius from pivot for everywhere search mode.
|
||||
double m_villageSearchRadiusM = kDefaultVillageSearchRadiusM;
|
||||
|
||||
Mode m_mode = Mode::Everywhere;
|
||||
|
||||
|
|
|
@ -89,6 +89,8 @@ unique_ptr<tests_support::TestSearchRequest> SearchTest::MakeRequest(
|
|||
params.m_needAddress = true;
|
||||
params.m_suggestsEnabled = false;
|
||||
params.m_streetSearchRadiusM = tests_support::TestSearchRequest::kDefaultTestStreetSearchRadiusM;
|
||||
params.m_villageSearchRadiusM =
|
||||
tests_support::TestSearchRequest::kDefaultTestVillageSearchRadiusM;
|
||||
|
||||
auto request = make_unique<tests_support::TestSearchRequest>(m_engine, params);
|
||||
request->Run();
|
||||
|
|
|
@ -26,6 +26,7 @@ TestSearchRequest::TestSearchRequest(TestSearchEngine & engine, string const & q
|
|||
m_params.m_viewport = viewport;
|
||||
m_params.m_mode = mode;
|
||||
m_params.m_streetSearchRadiusM = kDefaultTestStreetSearchRadiusM;
|
||||
m_params.m_villageSearchRadiusM = kDefaultTestVillageSearchRadiusM;
|
||||
SetUpCallbacks();
|
||||
SetUpResultParams();
|
||||
}
|
||||
|
@ -49,6 +50,7 @@ TestSearchRequest::TestSearchRequest(TestSearchEngine & engine, string const & q
|
|||
m_params.m_onStarted = onStarted;
|
||||
m_params.m_onResults = onResults;
|
||||
m_params.m_streetSearchRadiusM = kDefaultTestStreetSearchRadiusM;
|
||||
m_params.m_villageSearchRadiusM = kDefaultTestVillageSearchRadiusM;
|
||||
SetUpResultParams();
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ class TestSearchRequest
|
|||
{
|
||||
public:
|
||||
inline static double const kDefaultTestStreetSearchRadiusM = 2e7;
|
||||
inline static double const kDefaultTestVillageSearchRadiusM = 2e7;
|
||||
|
||||
TestSearchRequest(TestSearchEngine & engine, std::string const & query,
|
||||
std::string const & locale, Mode mode, m2::RectD const & viewport);
|
||||
|
|
Loading…
Add table
Reference in a new issue