forked from organicmaps/organicmaps
Review fixes.
This commit is contained in:
parent
71c25b0647
commit
4f7254b175
8 changed files with 39 additions and 63 deletions
|
@ -18,47 +18,28 @@ namespace search
|
|||
// CategoriesCache ---------------------------------------------------------------------------------
|
||||
CBV CategoriesCache::Get(MwmContext const & context)
|
||||
{
|
||||
if (!context.m_handle.IsAlive() || !context.m_value.HasSearchIndex())
|
||||
return CBV();
|
||||
CHECK(context.m_handle.IsAlive(), ());
|
||||
ASSERT(context.m_value.HasSearchIndex(), ());
|
||||
|
||||
auto id = context.m_handle.GetId();
|
||||
auto const id = context.m_handle.GetId();
|
||||
auto const it = m_cache.find(id);
|
||||
if (it != m_cache.cend())
|
||||
return it->second;
|
||||
|
||||
auto cbv = Load(context);
|
||||
auto const cbv = Load(context);
|
||||
m_cache[id] = cbv;
|
||||
return cbv;
|
||||
}
|
||||
|
||||
CBV CategoriesCache::GetFuzzy(MwmContext const & context)
|
||||
{
|
||||
if (!context.m_handle.IsAlive() || !context.m_value.HasSearchIndex())
|
||||
return CBV();
|
||||
|
||||
auto id = context.m_handle.GetId();
|
||||
auto const it = m_cacheFuzzy.find(id);
|
||||
if (it != m_cacheFuzzy.cend())
|
||||
return it->second;
|
||||
|
||||
auto cbv = LoadFuzzy(context);
|
||||
m_cacheFuzzy[id] = cbv;
|
||||
return cbv;
|
||||
}
|
||||
|
||||
void CategoriesCache::Clear()
|
||||
{
|
||||
m_cacheFuzzy.clear();
|
||||
m_cache.clear();
|
||||
}
|
||||
|
||||
CBV CategoriesCache::Load(MwmContext const & context)
|
||||
CBV CategoriesCache::Load(MwmContext const & context) const
|
||||
{
|
||||
ASSERT(context.m_handle.IsAlive(), ());
|
||||
ASSERT(context.m_value.HasSearchIndex(), ());
|
||||
|
||||
auto const & c = classif();
|
||||
|
||||
// Any DFA will do, since we only use requests's m_categories,
|
||||
// but the interface of Retrieval forces us to make a choice.
|
||||
SearchTrieRequest<strings::UniStringDFA> request;
|
||||
|
||||
m_categories.ForEach([&request, &c](uint32_t const type) {
|
||||
|
@ -69,23 +50,6 @@ CBV CategoriesCache::Load(MwmContext const & context)
|
|||
return CBV(retrieval.RetrieveAddressFeatures(request));
|
||||
}
|
||||
|
||||
CBV CategoriesCache::LoadFuzzy(MwmContext const & context)
|
||||
{
|
||||
ASSERT(context.m_handle.IsAlive(), ());
|
||||
ASSERT(context.m_value.HasSearchIndex(), ());
|
||||
|
||||
auto const & c = classif();
|
||||
|
||||
SearchTrieRequest<strings::LevenshteinDFA> request;
|
||||
|
||||
m_categories.ForEach([&request, &c](uint32_t const type) {
|
||||
request.m_categories.emplace_back(FeatureTypeToString(c.GetIndexForType(type)));
|
||||
});
|
||||
|
||||
Retrieval retrieval(context, m_cancellable);
|
||||
return CBV(retrieval.RetrieveAddressFeaturesFuzzy(request));
|
||||
}
|
||||
|
||||
// StreetsCache ------------------------------------------------------------------------------------
|
||||
StreetsCache::StreetsCache(my::Cancellable const & cancellable)
|
||||
: CategoriesCache(ftypes::IsStreetChecker::Instance(), cancellable)
|
||||
|
|
|
@ -24,7 +24,7 @@ public:
|
|||
source.ForEachType([this](uint32_t type) { m_categories.Add(type); });
|
||||
}
|
||||
|
||||
CategoriesCache(set<uint32_t> types, my::Cancellable const & cancellable)
|
||||
CategoriesCache(set<uint32_t> const & types, my::Cancellable const & cancellable)
|
||||
: m_cancellable(cancellable)
|
||||
{
|
||||
for (uint32_t type : types)
|
||||
|
@ -34,18 +34,15 @@ public:
|
|||
virtual ~CategoriesCache() = default;
|
||||
|
||||
CBV Get(MwmContext const & context);
|
||||
CBV GetFuzzy(MwmContext const & context);
|
||||
|
||||
void Clear();
|
||||
inline void Clear() { m_cache.clear(); }
|
||||
|
||||
private:
|
||||
CBV Load(MwmContext const & context);
|
||||
CBV LoadFuzzy(MwmContext const & context);
|
||||
CBV Load(MwmContext const & context) const;
|
||||
|
||||
CategoriesSet m_categories;
|
||||
my::Cancellable const & m_cancellable;
|
||||
map<MwmSet::MwmId, CBV> m_cache;
|
||||
map<MwmSet::MwmId, CBV> m_cacheFuzzy;
|
||||
};
|
||||
|
||||
class StreetsCache : public CategoriesCache
|
||||
|
|
|
@ -547,7 +547,7 @@ void Geocoder::GoImpl(vector<shared_ptr<MwmInfo>> & infos, bool inViewport)
|
|||
features = features.Intersect(viewportCBV);
|
||||
}
|
||||
|
||||
ctx.m_villages = m_villagesCache.GetFuzzy(*m_context);
|
||||
ctx.m_villages = m_villagesCache.Get(*m_context);
|
||||
|
||||
auto citiesFromWorld = m_cities;
|
||||
FillVillageLocalities(ctx);
|
||||
|
@ -556,15 +556,16 @@ void Geocoder::GoImpl(vector<shared_ptr<MwmInfo>> & infos, bool inViewport)
|
|||
m_cities = citiesFromWorld;
|
||||
});
|
||||
|
||||
bool const intersectsPivot = index < numIntersectingMaps;
|
||||
if (m_params.IsCategorialRequest())
|
||||
{
|
||||
MatchCategories(ctx);
|
||||
MatchCategories(ctx, intersectsPivot);
|
||||
}
|
||||
else
|
||||
{
|
||||
MatchRegions(ctx, Region::TYPE_COUNTRY);
|
||||
|
||||
if (index < numIntersectingMaps || m_preRanker.NumSentResults() == 0)
|
||||
if (intersectsPivot || m_preRanker.NumSentResults() == 0)
|
||||
MatchAroundPivot(ctx);
|
||||
}
|
||||
|
||||
|
@ -599,9 +600,13 @@ void Geocoder::InitBaseContext(BaseContext & ctx)
|
|||
ctx.m_features[i] = cache.Get(*m_context);
|
||||
}
|
||||
else if (m_params.IsPrefixToken(i))
|
||||
ctx.m_features[i] = retrieval.RetrieveAddressFeaturesFuzzy(m_prefixTokenRequest);
|
||||
{
|
||||
ctx.m_features[i] = retrieval.RetrieveAddressFeatures(m_prefixTokenRequest);
|
||||
}
|
||||
else
|
||||
ctx.m_features[i] = retrieval.RetrieveAddressFeaturesFuzzy(m_tokenRequests[i]);
|
||||
{
|
||||
ctx.m_features[i] = retrieval.RetrieveAddressFeatures(m_tokenRequests[i]);
|
||||
}
|
||||
|
||||
if (m_params.m_cianMode)
|
||||
ctx.m_features[i] = DecimateCianResults(ctx.m_features[i]);
|
||||
|
@ -776,8 +781,17 @@ void Geocoder::ForEachCountry(vector<shared_ptr<MwmInfo>> const & infos, TFn &&
|
|||
}
|
||||
}
|
||||
|
||||
void Geocoder::MatchCategories(BaseContext & ctx)
|
||||
void Geocoder::MatchCategories(BaseContext & ctx, bool aroundPivot)
|
||||
{
|
||||
auto features = ctx.m_features[0];
|
||||
|
||||
if (aroundPivot)
|
||||
{
|
||||
auto const pivotFeatures = RetrieveGeometryFeatures(*m_context, m_params.m_pivot, RECT_ID_PIVOT);
|
||||
ViewportFilter filter(pivotFeatures, m_preRanker.Limit() /* threshold */);
|
||||
features = filter.Filter(features);
|
||||
}
|
||||
|
||||
auto emit = [&](uint64_t bit) {
|
||||
auto const featureId = base::asserted_cast<uint32_t>(bit);
|
||||
Model::Type type;
|
||||
|
@ -791,7 +805,7 @@ void Geocoder::MatchCategories(BaseContext & ctx)
|
|||
// Its features have been retrieved from the search index
|
||||
// using the exact (non-fuzzy) matching and intersected
|
||||
// with viewport, if needed. Every such feature is relevant.
|
||||
ctx.m_features[0].ForEach(emit);
|
||||
features.ForEach(emit);
|
||||
}
|
||||
|
||||
void Geocoder::MatchRegions(BaseContext & ctx, Region::Type type)
|
||||
|
@ -930,7 +944,7 @@ void Geocoder::LimitedSearch(BaseContext & ctx, FeaturesFilter const & filter)
|
|||
});
|
||||
|
||||
if (!ctx.m_streets)
|
||||
ctx.m_streets = m_streetsCache.GetFuzzy(*m_context);
|
||||
ctx.m_streets = m_streetsCache.Get(*m_context);
|
||||
|
||||
MatchUnclassified(ctx, 0 /* curToken */);
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ private:
|
|||
inline void BailIfCancelled() { ::search::BailIfCancelled(m_cancellable); }
|
||||
|
||||
// A fast-path branch for categorial requests.
|
||||
void MatchCategories(BaseContext & ctx);
|
||||
void MatchCategories(BaseContext & ctx, bool aroundPivot);
|
||||
|
||||
// Tries to find all countries and states in a search query and then
|
||||
// performs matching of cities in found maps.
|
||||
|
|
|
@ -390,6 +390,7 @@ void Processor::SetViewportByIndex(m2::RectD const & viewport, size_t idx, bool
|
|||
}
|
||||
|
||||
void Processor::ClearCache(size_t ind) { m_viewport[ind].MakeEmpty(); }
|
||||
|
||||
Locales Processor::GetCategoryLocales() const
|
||||
{
|
||||
static int8_t const enLocaleCode = CategoriesHolder::MapLocaleToInteger("en");
|
||||
|
|
|
@ -115,7 +115,7 @@ public:
|
|||
inline Langs const & GetLangs() const { return m_langs; }
|
||||
inline bool LangExists(int8_t lang) const { return m_langs.Contains(lang); }
|
||||
|
||||
inline void SetCategorialRequest(bool rhs) { m_isCategorialRequest = rhs; }
|
||||
inline void SetCategorialRequest(bool isCategorial) { m_isCategorialRequest = isCategorial; }
|
||||
inline bool IsCategorialRequest() const { return m_isCategorialRequest; }
|
||||
|
||||
inline int GetScale() const { return m_scale; }
|
||||
|
|
|
@ -329,13 +329,13 @@ unique_ptr<coding::CompressedBitVector> Retrieval::RetrieveAddressFeatures(
|
|||
return Retrieve<RetrieveAddressFeaturesAdaptor>(request);
|
||||
}
|
||||
|
||||
unique_ptr<coding::CompressedBitVector> Retrieval::RetrieveAddressFeaturesFuzzy(
|
||||
unique_ptr<coding::CompressedBitVector> Retrieval::RetrieveAddressFeatures(
|
||||
SearchTrieRequest<LevenshteinDFA> const & request)
|
||||
{
|
||||
return Retrieve<RetrieveAddressFeaturesAdaptor>(request);
|
||||
}
|
||||
|
||||
unique_ptr<coding::CompressedBitVector> Retrieval::RetrieveAddressFeaturesFuzzy(
|
||||
unique_ptr<coding::CompressedBitVector> Retrieval::RetrieveAddressFeatures(
|
||||
SearchTrieRequest<PrefixDFAModifier<LevenshteinDFA>> const & request)
|
||||
{
|
||||
return Retrieve<RetrieveAddressFeaturesAdaptor>(request);
|
||||
|
|
|
@ -43,10 +43,10 @@ public:
|
|||
unique_ptr<coding::CompressedBitVector> RetrieveAddressFeatures(
|
||||
SearchTrieRequest<strings::PrefixDFAModifier<strings::UniStringDFA>> const & request);
|
||||
|
||||
unique_ptr<coding::CompressedBitVector> RetrieveAddressFeaturesFuzzy(
|
||||
unique_ptr<coding::CompressedBitVector> RetrieveAddressFeatures(
|
||||
SearchTrieRequest<strings::LevenshteinDFA> const & request);
|
||||
|
||||
unique_ptr<coding::CompressedBitVector> RetrieveAddressFeaturesFuzzy(
|
||||
unique_ptr<coding::CompressedBitVector> RetrieveAddressFeatures(
|
||||
SearchTrieRequest<strings::PrefixDFAModifier<strings::LevenshteinDFA>> const & request);
|
||||
|
||||
// Retrieves from the search index corresponding to |value| all
|
||||
|
|
Loading…
Add table
Reference in a new issue