forked from organicmaps/organicmaps
[search] MwmContext is used in Retrieval now.
This commit is contained in:
parent
b36ab27345
commit
e3d6e1e675
5 changed files with 43 additions and 62 deletions
|
@ -659,8 +659,7 @@ void Geocoder::InitBaseContext(BaseContext & ctx)
|
|||
for (size_t i = 0; i < ctx.m_features.size(); ++i)
|
||||
{
|
||||
PrepareRetrievalParams(i, i + 1);
|
||||
ctx.m_features[i] = RetrieveAddressFeatures(m_context->GetId(), m_context->m_value,
|
||||
m_cancellable, m_retrievalParams);
|
||||
ctx.m_features[i] = RetrieveAddressFeatures(*m_context, m_cancellable, m_retrievalParams);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1417,8 +1416,7 @@ CBV Geocoder::LoadCategories(MwmContext & context, vector<strings::UniString> co
|
|||
for_each(categories.begin(), categories.end(), [&](strings::UniString const & category)
|
||||
{
|
||||
m_retrievalParams.m_tokens[0][0] = category;
|
||||
CBV cbv(RetrieveAddressFeatures(context.GetId(), context.m_value, m_cancellable,
|
||||
m_retrievalParams));
|
||||
CBV cbv(RetrieveAddressFeatures(context, m_cancellable, m_retrievalParams));
|
||||
if (!cbv.IsEmpty())
|
||||
cbvs.push_back(move(cbv));
|
||||
});
|
||||
|
@ -1454,8 +1452,7 @@ CBV Geocoder::LoadVillages(MwmContext & context)
|
|||
|
||||
CBV Geocoder::RetrievePostcodeFeatures(MwmContext const & context, TokenSlice const & slice)
|
||||
{
|
||||
return CBV(
|
||||
::search::RetrievePostcodeFeatures(context.GetId(), context.m_value, m_cancellable, slice));
|
||||
return CBV(::search::RetrievePostcodeFeatures(context, m_cancellable, slice));
|
||||
}
|
||||
|
||||
CBV Geocoder::RetrieveGeometryFeatures(MwmContext const & context, m2::RectD const & rect,
|
||||
|
|
|
@ -32,6 +32,7 @@ private:
|
|||
public:
|
||||
explicit MwmContext(MwmSet::MwmHandle handle);
|
||||
|
||||
inline bool IsAlive() const { return m_handle.IsAlive(); }
|
||||
inline MwmSet::MwmId const & GetId() const { return m_handle.GetId(); }
|
||||
inline string const & GetName() const { return GetInfo()->GetCountryName(); }
|
||||
inline shared_ptr<MwmInfo> const & GetInfo() const { return GetId().GetInfo(); }
|
||||
|
|
|
@ -198,51 +198,43 @@ void WithSearchTrieRoot(MwmValue & value, TFn && fn)
|
|||
// features matching to |params|.
|
||||
template <typename TValue>
|
||||
unique_ptr<coding::CompressedBitVector> RetrieveAddressFeaturesImpl(
|
||||
MwmSet::MwmId const & id, MwmValue & value, my::Cancellable const & cancellable,
|
||||
QueryParams const & params)
|
||||
MwmContext const & context, my::Cancellable const & cancellable, QueryParams const & params)
|
||||
{
|
||||
EditedFeaturesHolder holder(id);
|
||||
EditedFeaturesHolder holder(context.GetId());
|
||||
vector<uint64_t> features;
|
||||
FeaturesCollector collector(cancellable, features);
|
||||
|
||||
WithSearchTrieRoot<TValue>(value, [&](TrieRoot<TValue> const & root)
|
||||
{
|
||||
MatchFeaturesInTrie(params, root, [&holder](uint32_t featureIndex)
|
||||
{
|
||||
return !holder.ModifiedOrDeleted(featureIndex);
|
||||
},
|
||||
collector);
|
||||
WithSearchTrieRoot<TValue>(context.m_value, [&](TrieRoot<TValue> const & root) {
|
||||
MatchFeaturesInTrie(
|
||||
params, root,
|
||||
[&holder](uint32_t featureIndex) { return !holder.ModifiedOrDeleted(featureIndex); },
|
||||
collector);
|
||||
});
|
||||
holder.ForEachModifiedOrCreated([&](FeatureType & ft, uint64_t index) {
|
||||
if (MatchFeatureByName(ft, params))
|
||||
features.push_back(index);
|
||||
});
|
||||
holder.ForEachModifiedOrCreated([&](FeatureType & ft, uint64_t index)
|
||||
{
|
||||
if (MatchFeatureByName(ft, params))
|
||||
features.push_back(index);
|
||||
});
|
||||
return SortFeaturesAndBuildCBV(move(features));
|
||||
}
|
||||
|
||||
template <typename TValue>
|
||||
unique_ptr<coding::CompressedBitVector> RetrievePostcodeFeaturesImpl(
|
||||
MwmSet::MwmId const & id, MwmValue & value, my::Cancellable const & cancellable,
|
||||
TokenSlice const & slice)
|
||||
MwmContext const & context, my::Cancellable const & cancellable, TokenSlice const & slice)
|
||||
{
|
||||
EditedFeaturesHolder holder(id);
|
||||
EditedFeaturesHolder holder(context.GetId());
|
||||
vector<uint64_t> features;
|
||||
FeaturesCollector collector(cancellable, features);
|
||||
|
||||
WithSearchTrieRoot<TValue>(value, [&](TrieRoot<TValue> const & root)
|
||||
{
|
||||
MatchPostcodesInTrie(slice, root, [&holder](uint32_t featureIndex)
|
||||
{
|
||||
return !holder.ModifiedOrDeleted(featureIndex);
|
||||
},
|
||||
collector);
|
||||
WithSearchTrieRoot<TValue>(context.m_value, [&](TrieRoot<TValue> const & root) {
|
||||
MatchPostcodesInTrie(
|
||||
slice, root,
|
||||
[&holder](uint32_t featureIndex) { return !holder.ModifiedOrDeleted(featureIndex); },
|
||||
collector);
|
||||
});
|
||||
holder.ForEachModifiedOrCreated([&](FeatureType & ft, uint64_t index) {
|
||||
if (MatchFeatureByPostcode(ft, slice))
|
||||
features.push_back(index);
|
||||
});
|
||||
holder.ForEachModifiedOrCreated([&](FeatureType & ft, uint64_t index)
|
||||
{
|
||||
if (MatchFeatureByPostcode(ft, slice))
|
||||
features.push_back(index);
|
||||
});
|
||||
return SortFeaturesAndBuildCBV(move(features));
|
||||
}
|
||||
|
||||
|
@ -284,52 +276,48 @@ template <template <typename> class T>
|
|||
struct Selector
|
||||
{
|
||||
template <typename... TArgs>
|
||||
unique_ptr<coding::CompressedBitVector> operator()(MwmSet::MwmId const & id, MwmValue & value,
|
||||
TArgs &&... args)
|
||||
unique_ptr<coding::CompressedBitVector> operator()(MwmContext const & context, TArgs &&... args)
|
||||
{
|
||||
version::MwmTraits mwmTraits(value.GetMwmVersion().GetFormat());
|
||||
version::MwmTraits mwmTraits(context.m_value.GetMwmVersion().GetFormat());
|
||||
|
||||
if (mwmTraits.GetSearchIndexFormat() ==
|
||||
version::MwmTraits::SearchIndexFormat::FeaturesWithRankAndCenter)
|
||||
{
|
||||
T<FeatureWithRankAndCenter> t;
|
||||
return t(id, value, forward<TArgs>(args)...);
|
||||
return t(context, forward<TArgs>(args)...);
|
||||
}
|
||||
if (mwmTraits.GetSearchIndexFormat() ==
|
||||
version::MwmTraits::SearchIndexFormat::CompressedBitVector)
|
||||
{
|
||||
T<FeatureIndexValue> t;
|
||||
return t(id, value, forward<TArgs>(args)...);
|
||||
return t(context, forward<TArgs>(args)...);
|
||||
}
|
||||
return unique_ptr<coding::CompressedBitVector>();
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
unique_ptr<coding::CompressedBitVector> RetrieveAddressFeatures(MwmSet::MwmId const & id,
|
||||
MwmValue & value,
|
||||
unique_ptr<coding::CompressedBitVector> RetrieveAddressFeatures(MwmContext const & context,
|
||||
my::Cancellable const & cancellable,
|
||||
QueryParams const & params)
|
||||
{
|
||||
Selector<RetrieveAddressFeaturesAdaptor> selector;
|
||||
return selector(id, value, cancellable, params);
|
||||
return selector(context, cancellable, params);
|
||||
}
|
||||
|
||||
unique_ptr<coding::CompressedBitVector> RetrievePostcodeFeatures(
|
||||
MwmSet::MwmId const & id, MwmValue & value, my::Cancellable const & cancellable,
|
||||
TokenSlice const & slice)
|
||||
MwmContext const & context, my::Cancellable const & cancellable, TokenSlice const & slice)
|
||||
{
|
||||
Selector<RetrievePostcodeFeaturesAdaptor> selector;
|
||||
return selector(id, value, cancellable, slice);
|
||||
return selector(context, cancellable, slice);
|
||||
}
|
||||
|
||||
unique_ptr<coding::CompressedBitVector> RetrieveGeometryFeatures(
|
||||
MwmContext const & context, my::Cancellable const & cancellable,
|
||||
m2::RectD const & rect, int scale)
|
||||
MwmContext const & context, my::Cancellable const & cancellable, m2::RectD const & rect,
|
||||
int scale)
|
||||
{
|
||||
covering::IntervalsT coverage;
|
||||
CoverRect(rect, scale, coverage);
|
||||
return RetrieveGeometryFeaturesImpl(context, cancellable, coverage, scale);
|
||||
}
|
||||
|
||||
} // namespace search
|
||||
|
|
|
@ -2,13 +2,12 @@
|
|||
|
||||
#include "search/query_params.hpp"
|
||||
|
||||
#include "indexer/mwm_set.hpp"
|
||||
#include "geometry/rect2d.hpp"
|
||||
|
||||
#include "base/cancellable.hpp"
|
||||
|
||||
#include "std/unique_ptr.hpp"
|
||||
|
||||
|
||||
class MwmValue;
|
||||
|
||||
namespace coding
|
||||
|
@ -23,20 +22,17 @@ class TokenSlice;
|
|||
|
||||
// Retrieves from the search index corresponding to |value| all
|
||||
// features matching to |params|.
|
||||
unique_ptr<coding::CompressedBitVector> RetrieveAddressFeatures(MwmSet::MwmId const & id,
|
||||
MwmValue & value,
|
||||
unique_ptr<coding::CompressedBitVector> RetrieveAddressFeatures(MwmContext const & context,
|
||||
my::Cancellable const & cancellable,
|
||||
QueryParams const & params);
|
||||
|
||||
// Retrieves from the search index corresponding to |value| all
|
||||
// postcodes matching to |slice|.
|
||||
unique_ptr<coding::CompressedBitVector> RetrievePostcodeFeatures(
|
||||
MwmSet::MwmId const & id, MwmValue & value, my::Cancellable const & cancellable,
|
||||
TokenSlice const & slice);
|
||||
MwmContext const & context, my::Cancellable const & cancellable, TokenSlice const & slice);
|
||||
|
||||
// Retrieves from the geometry index corresponding to |value| all features belonging to |rect|.
|
||||
unique_ptr<coding::CompressedBitVector> RetrieveGeometryFeatures(
|
||||
MwmContext const & context, my::Cancellable const & cancellable, m2::RectD const & rect,
|
||||
int scale);
|
||||
|
||||
} // namespace search
|
||||
} // namespace search
|
||||
|
|
|
@ -491,15 +491,14 @@ UNIT_CLASS_TEST(ProcessorTest, TestPostcodes)
|
|||
|
||||
// Tests that postcode is added to the search index.
|
||||
{
|
||||
auto handle = m_engine.GetMwmHandleById(countryId);
|
||||
TEST(handle.IsAlive(), ());
|
||||
MwmContext context(m_engine.GetMwmHandleById(countryId));
|
||||
TEST(context.IsAlive(), ());
|
||||
my::Cancellable cancellable;
|
||||
|
||||
QueryParams params;
|
||||
params.m_tokens.emplace_back();
|
||||
params.m_tokens.back().push_back(strings::MakeUniString("141702"));
|
||||
auto * value = handle.GetValue<MwmValue>();
|
||||
auto features = RetrievePostcodeFeatures(countryId, *value, cancellable,
|
||||
auto features = RetrievePostcodeFeatures(context, cancellable,
|
||||
TokenSlice(params, 0, params.m_tokens.size()));
|
||||
TEST_EQUAL(1, features->PopCount(), ());
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue