forked from organicmaps/organicmaps-tmp
Review fixes.
This commit is contained in:
parent
39d7c7ef32
commit
ad94413e85
7 changed files with 142 additions and 103 deletions
|
@ -44,6 +44,7 @@ HEADERS += \
|
|||
search_string_utils.hpp \
|
||||
search_trie.hpp \
|
||||
suggest.hpp \
|
||||
v2/cbv_ptr.hpp \
|
||||
v2/features_filter.hpp \
|
||||
v2/features_layer.hpp \
|
||||
v2/features_layer_matcher.hpp \
|
||||
|
@ -83,6 +84,7 @@ SOURCES += \
|
|||
search_query.cpp \
|
||||
search_query_params.cpp \
|
||||
search_string_utils.cpp \
|
||||
v2/cbv_ptr.cpp \
|
||||
v2/features_filter.cpp \
|
||||
v2/features_layer.cpp \
|
||||
v2/features_layer_matcher.cpp \
|
||||
|
|
69
search/v2/cbv_ptr.cpp
Normal file
69
search/v2/cbv_ptr.cpp
Normal file
|
@ -0,0 +1,69 @@
|
|||
#include "search/v2/cbv_ptr.hpp"
|
||||
|
||||
#include "coding/compressed_bit_vector.hpp"
|
||||
|
||||
namespace search
|
||||
{
|
||||
namespace v2
|
||||
{
|
||||
|
||||
void CBVPtr::Release()
|
||||
{
|
||||
if (m_isOwner)
|
||||
delete m_ptr;
|
||||
|
||||
m_ptr = nullptr;
|
||||
m_isOwner = false;
|
||||
m_isFull = false;
|
||||
}
|
||||
|
||||
void CBVPtr::Set(coding::CompressedBitVector const * p, bool isOwner/* = false*/)
|
||||
{
|
||||
Release();
|
||||
|
||||
m_ptr = p;
|
||||
m_isOwner = p && isOwner;
|
||||
}
|
||||
|
||||
void CBVPtr::Union(coding::CompressedBitVector const * p)
|
||||
{
|
||||
if (!p || m_isFull)
|
||||
return;
|
||||
|
||||
if (!m_ptr)
|
||||
{
|
||||
m_ptr = p;
|
||||
m_isFull = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Set(coding::CompressedBitVector::Union(*m_ptr, *p).release(), true);
|
||||
}
|
||||
}
|
||||
|
||||
void CBVPtr::Intersect(coding::CompressedBitVector const * p)
|
||||
{
|
||||
if (!p)
|
||||
{
|
||||
Release();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_ptr)
|
||||
{
|
||||
Set(coding::CompressedBitVector::Intersect(*m_ptr, *p).release(), true);
|
||||
}
|
||||
else if (m_isFull)
|
||||
{
|
||||
m_ptr = p;
|
||||
m_isFull = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool CBVPtr::IsEmpty() const
|
||||
{
|
||||
return !m_isFull && coding::CompressedBitVector::IsEmpty(m_ptr);
|
||||
}
|
||||
|
||||
} // namespace v2
|
||||
} // namespace search
|
47
search/v2/cbv_ptr.hpp
Normal file
47
search/v2/cbv_ptr.hpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#pragma once
|
||||
|
||||
#include "base/macros.hpp"
|
||||
|
||||
namespace coding
|
||||
{
|
||||
class CompressedBitVector;
|
||||
}
|
||||
|
||||
namespace search
|
||||
{
|
||||
namespace v2
|
||||
{
|
||||
/// CompressedBitVector pointer class that incapsulates
|
||||
/// binary operators logic and takes ownership if needed.
|
||||
class CBVPtr
|
||||
{
|
||||
DISALLOW_COPY_AND_MOVE(CBVPtr);
|
||||
|
||||
coding::CompressedBitVector const * m_ptr = nullptr;
|
||||
bool m_isOwner = false;
|
||||
bool m_isFull = false; ///< True iff all bits are set to one.
|
||||
|
||||
void Release();
|
||||
|
||||
public:
|
||||
CBVPtr() = default;
|
||||
~CBVPtr() { Release(); }
|
||||
|
||||
inline void SetFull()
|
||||
{
|
||||
Release();
|
||||
m_isFull = true;
|
||||
}
|
||||
|
||||
void Set(coding::CompressedBitVector const * p, bool isOwner = false);
|
||||
|
||||
inline coding::CompressedBitVector const * Get() const { return m_ptr; }
|
||||
|
||||
bool IsEmpty() const;
|
||||
|
||||
void Union(coding::CompressedBitVector const * p);
|
||||
void Intersect(coding::CompressedBitVector const * p);
|
||||
};
|
||||
|
||||
} // namespace v2
|
||||
} // namespace search
|
|
@ -26,51 +26,5 @@ unique_ptr<coding::CompressedBitVector> FeaturesFilter::Filter(
|
|||
return coding::CompressedBitVector::Intersect(*m_filter, cbv);
|
||||
}
|
||||
|
||||
void CBVPtr::Free()
|
||||
{
|
||||
if (m_isOwner)
|
||||
delete m_ptr;
|
||||
|
||||
m_ptr = nullptr;
|
||||
m_isOwner = false;
|
||||
m_isFull = false;
|
||||
}
|
||||
|
||||
void CBVPtr::Union(coding::CompressedBitVector const * p)
|
||||
{
|
||||
if (!p || m_isFull)
|
||||
return;
|
||||
|
||||
if (!m_ptr)
|
||||
{
|
||||
m_ptr = p;
|
||||
m_isFull = false;
|
||||
}
|
||||
else
|
||||
Set(coding::CompressedBitVector::Union(*m_ptr, *p).release(), true);
|
||||
}
|
||||
|
||||
void CBVPtr::Intersect(coding::CompressedBitVector const * p)
|
||||
{
|
||||
if (!p)
|
||||
{
|
||||
Free();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_ptr)
|
||||
Set(coding::CompressedBitVector::Intersect(*m_ptr, *p).release(), true);
|
||||
else if (m_isFull)
|
||||
{
|
||||
m_ptr = p;
|
||||
m_isFull = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool CBVPtr::IsEmpty() const
|
||||
{
|
||||
return !m_isFull && coding::CompressedBitVector::IsEmpty(m_ptr);
|
||||
}
|
||||
|
||||
} // namespace v2
|
||||
} // namespace search
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include "base/macros.hpp"
|
||||
|
||||
#include "std/unique_ptr.hpp"
|
||||
|
||||
namespace coding
|
||||
|
@ -36,44 +34,5 @@ private:
|
|||
uint32_t m_threshold;
|
||||
};
|
||||
|
||||
|
||||
/// CompressedBitVector pointer class that incapsulates
|
||||
/// binary operators logic and takes ownership if needed.
|
||||
class CBVPtr
|
||||
{
|
||||
DISALLOW_COPY_AND_MOVE(CBVPtr);
|
||||
|
||||
coding::CompressedBitVector const * m_ptr = nullptr;
|
||||
bool m_isOwner = false;
|
||||
bool m_isFull = false;
|
||||
|
||||
void Free();
|
||||
|
||||
public:
|
||||
CBVPtr() = default;
|
||||
~CBVPtr() { Free(); }
|
||||
|
||||
inline void SetFull()
|
||||
{
|
||||
Free();
|
||||
m_isFull = true;
|
||||
}
|
||||
|
||||
inline void Set(coding::CompressedBitVector const * p, bool isOwner = false)
|
||||
{
|
||||
Free();
|
||||
|
||||
m_ptr = p;
|
||||
m_isOwner = p && isOwner;
|
||||
}
|
||||
|
||||
inline coding::CompressedBitVector const * Get() const { return m_ptr; }
|
||||
|
||||
bool IsEmpty() const;
|
||||
|
||||
void Union(coding::CompressedBitVector const * p);
|
||||
void Intersect(coding::CompressedBitVector const * p);
|
||||
};
|
||||
|
||||
} // namespace v2
|
||||
} // namespace search
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "search/retrieval.hpp"
|
||||
#include "search/search_delimiters.hpp"
|
||||
#include "search/search_string_utils.hpp"
|
||||
#include "search/v2/cbv_ptr.hpp"
|
||||
#include "search/v2/features_layer_matcher.hpp"
|
||||
|
||||
#include "indexer/classificator.hpp"
|
||||
|
@ -46,7 +47,7 @@ namespace v2
|
|||
namespace
|
||||
{
|
||||
|
||||
size_t const kMaxLocalitiesCount = 5;
|
||||
size_t constexpr kMaxLocalitiesCount = 5;
|
||||
double constexpr kComparePoints = MercatorBounds::GetCellID2PointAbsEpsilon();
|
||||
|
||||
void JoinQueryTokens(SearchQueryParams const & params, size_t curToken, size_t endToken,
|
||||
|
@ -257,13 +258,13 @@ void Geocoder::FillLocalitiesTable(MwmContext const & context)
|
|||
context.m_value, static_cast<my::Cancellable const &>(*this), m_retrievalParams));
|
||||
}
|
||||
|
||||
// 2. Get all locality candidates with all the token ranges.
|
||||
// 2. Get all locality candidates for the continuous token ranges.
|
||||
vector<Locality> preLocalities;
|
||||
|
||||
for (size_t i = 0; i < m_numTokens; ++i)
|
||||
{
|
||||
CBVPtr intersection;
|
||||
intersection.Set(tokensCBV[i].get(), false);
|
||||
intersection.Set(tokensCBV[i].get(), false /*isOwner*/);
|
||||
if (intersection.IsEmpty())
|
||||
continue;
|
||||
|
||||
|
@ -314,12 +315,13 @@ void Geocoder::FillLocalitiesTable(MwmContext const & context)
|
|||
}), preLocalities.end());
|
||||
|
||||
// 4. Leave most popular localities.
|
||||
// Use 2*kMaxLocalitiesCount because there can be countries, states, ...
|
||||
if (preLocalities.size() > 2*kMaxLocalitiesCount)
|
||||
// Use 2 * kMaxLocalitiesCount because there can be countries, states, ...
|
||||
size_t count = 2 * kMaxLocalitiesCount;
|
||||
if (preLocalities.size() > count)
|
||||
{
|
||||
auto rankTable = search::RankTable::Load(context.m_value.m_cont);
|
||||
|
||||
sort(preLocalities.begin(), preLocalities.end(),
|
||||
nth_element(preLocalities.begin(), preLocalities.begin() + count, preLocalities.end(),
|
||||
[&] (Locality const & l1, Locality const & l2)
|
||||
{
|
||||
auto const d1 = tokensCountFn(l1);
|
||||
|
@ -328,21 +330,26 @@ void Geocoder::FillLocalitiesTable(MwmContext const & context)
|
|||
return d1 > d2;
|
||||
return rankTable->Get(l1.m_featureId) > rankTable->Get(l2.m_featureId);
|
||||
});
|
||||
preLocalities.resize(2*kMaxLocalitiesCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
count = preLocalities.size();
|
||||
}
|
||||
|
||||
// 5. Fill result container.
|
||||
size_t count = 0;
|
||||
for (auto & l : preLocalities)
|
||||
size_t citiesCount = 0;
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
auto & l = preLocalities[i];
|
||||
|
||||
FeatureType ft;
|
||||
context.m_vector.GetByIndex(l.m_featureId, ft);
|
||||
|
||||
if (count < kMaxLocalitiesCount &&
|
||||
if (citiesCount < kMaxLocalitiesCount &&
|
||||
ft.GetFeatureType() == feature::GEOM_POINT &&
|
||||
m_model.GetSearchType(ft) == SearchModel::SEARCH_TYPE_CITY)
|
||||
{
|
||||
++count;
|
||||
++citiesCount;
|
||||
l.m_rect = MercatorBounds::RectByCenterXYAndSizeInMeters(
|
||||
ft.GetCenter(), ftypes::GetRadiusByPopulation(ft.GetPopulation()));
|
||||
|
||||
|
@ -754,18 +761,18 @@ coding::CompressedBitVector const * Geocoder::RetrieveGeometryFeatures(
|
|||
/// - Implement more smart strategy according to id.
|
||||
/// - Move all rect limits here
|
||||
|
||||
auto & featuresV = m_geometryFeatures[context.m_id];
|
||||
for (auto const & v : featuresV)
|
||||
auto & features = m_geometryFeatures[context.m_id];
|
||||
for (auto const & v : features)
|
||||
{
|
||||
if (v.m_rect.IsRectInside(rect))
|
||||
return v.m_cbv.get();
|
||||
}
|
||||
|
||||
auto features = Retrieval::RetrieveGeometryFeatures(
|
||||
auto cbv = Retrieval::RetrieveGeometryFeatures(
|
||||
context.m_value, static_cast<my::Cancellable const &>(*this), rect, m_params.m_scale);
|
||||
|
||||
auto const * result = features.get();
|
||||
featuresV.push_back({ m2::Inflate(rect, kComparePoints, kComparePoints), move(features), id });
|
||||
auto const * result = cbv.get();
|
||||
features.push_back({ m2::Inflate(rect, kComparePoints, kComparePoints), move(cbv), id });
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ using std::max;
|
|||
using std::max_element;
|
||||
using std::min;
|
||||
using std::next_permutation;
|
||||
using std::nth_element;
|
||||
using std::partial_sort;
|
||||
using std::remove_if;
|
||||
using std::replace;
|
||||
|
|
Loading…
Add table
Reference in a new issue