[search] Get locality when full search in MWM (SearchAdditional).

This commit is contained in:
vng 2015-10-08 19:36:03 +03:00
parent 25ba417f9d
commit cbc4eeec92
3 changed files with 35 additions and 17 deletions

View file

@ -91,7 +91,6 @@ private:
};
LocalityItem::LocalityItem(m2::RectD const & rect, uint32_t population, ID id, string const & name)
: m_rect(rect), m_name(name), m_population(population), m_id(id)
{
@ -156,20 +155,34 @@ void LocalityFinder::SetViewportByIndex(m2::RectD const & rect, size_t idx)
RecreateCache(m_cache[idx], rect);
}
void LocalityFinder::GetLocalityInViewport(const m2::PointD & pt, string & name) const
void LocalityFinder::SetViewportSafe(m2::RectD const & rect)
{
for (size_t i = 0; i < MAX_VIEWPORT_COUNT; ++i)
m_cache[i].GetLocality(pt, name);
size_t constexpr kSafeIndex = 2;
if (m_cache[kSafeIndex].m_rect.IsValid() && m_cache[kSafeIndex].m_rect.IsRectInside(rect))
return;
SetViewportByIndex(rect, kSafeIndex);
}
void LocalityFinder::GetLocalityCreateCache(const m2::PointD & pt, string & name) const
void LocalityFinder::GetLocalityInViewport(m2::PointD const & pt, string & name) const
{
name.clear();
for (size_t i = 0; i < MAX_VIEWPORT_COUNT; ++i)
{
m_cache[i].GetLocality(pt, name);
if (!name.empty())
break;
}
}
void LocalityFinder::GetLocalityCreateCache(m2::PointD const & pt, string & name)
{
// search in temporary caches and find most unused cache
size_t minUsageIdx = 0;
size_t minUsage = numeric_limits<size_t>::max();
for (size_t idx = 0; idx < MAX_CACHE_TMP_COUNT; ++idx)
for (size_t idx = 0; idx < MAX_VIEWPORT_COUNT; ++idx)
{
Cache const & cache = m_cache_tmp[idx];
Cache const & cache = m_cache[idx];
cache.GetLocality(pt, name);
if (!name.empty())
return;
@ -181,7 +194,7 @@ void LocalityFinder::GetLocalityCreateCache(const m2::PointD & pt, string & name
}
}
Cache & cache = m_cache_tmp[minUsageIdx];
Cache & cache = m_cache[minUsageIdx];
RecreateCache(cache, MercatorBounds::RectByCenterXYAndSizeInMeters(pt, MAX_RADIUS_CITY));
cache.GetLocality(pt, name);
}
@ -190,9 +203,6 @@ void LocalityFinder::ClearCacheAll()
{
for (size_t i = 0; i < MAX_VIEWPORT_COUNT; ++i)
ClearCache(i);
for (size_t i = 0; i < MAX_CACHE_TMP_COUNT; ++i)
m_cache_tmp[i].Clear();
}
void LocalityFinder::ClearCache(size_t idx)
@ -201,8 +211,6 @@ void LocalityFinder::ClearCache(size_t idx)
m_cache[idx].Clear();
}
void LocalityFinder::Cache::Clear()
{
m_usage = 0;

View file

@ -56,11 +56,12 @@ public:
}
void SetViewportByIndex(m2::RectD const & rect, size_t idx);
void SetViewportSafe(m2::RectD const & rect);
/// Check for localities in pre-cached viewports only.
void GetLocalityInViewport(m2::PointD const & pt, string & name) const;
/// Checl for localities in all Index and make new cache if needed.
void GetLocalityCreateCache(m2::PointD const & pt, string & name) const;
void GetLocalityCreateCache(m2::PointD const & pt, string & name);
void ClearCacheAll();
void ClearCache(size_t idx);
@ -74,9 +75,8 @@ private:
Index const * m_pIndex;
enum { MAX_VIEWPORT_COUNT = 3, MAX_CACHE_TMP_COUNT = 4};
enum { MAX_VIEWPORT_COUNT = 3 };
Cache m_cache[MAX_VIEWPORT_COUNT];
mutable Cache m_cache_tmp[MAX_CACHE_TMP_COUNT];
int8_t m_lang;
};

View file

@ -931,7 +931,7 @@ void Query::ProcessSuggestions(vector<T> & vec, Results & res) const
return;
int added = 0;
for (typename vector<T>::iterator i = vec.begin(); i != vec.end();)
for (auto i = vec.begin(); i != vec.end();)
{
impl::PreResult2 const & r = **i;
@ -1967,6 +1967,16 @@ void Query::SearchAdditional(Results & res, size_t resCount)
}
}
#ifdef FIND_LOCALITY_TEST
m2::RectD rect;
for (auto const & r : m_results[0])
rect.Add(r.GetCenter());
// Hack with 90.0 is important for the countries divided by 180 meridian.
if (rect.IsValid() && (rect.maxX() - rect.minX()) <= 90.0)
m_locality.SetViewportSafe(rect);
#endif
FlushResults(res, true, resCount);
}
}