[search] Optimization of BUILDING-STREET intersection.

This commit is contained in:
Yuri Gorshenin 2015-12-24 19:24:26 +03:00 committed by Sergey Yershov
parent ee3d060e88
commit 7ad477761d
2 changed files with 57 additions and 11 deletions

View file

@ -22,20 +22,25 @@ FeaturesLayerMatcher::FeaturesLayerMatcher(Index & index, MwmContext & context,
ASSERT(m_houseToStreetTable.get(), ("Can't load HouseToStreetTable"));
}
uint32_t FeaturesLayerMatcher::GetMatchingStreet(uint32_t houseId)
{
auto const it = m_matchingStreetsCache.find(houseId);
if (it != m_matchingStreetsCache.cend())
return it->second;
FeatureType houseFeature;
m_context.m_vector.GetByIndex(houseId, houseFeature);
return GetMatchingStreetImpl(houseId, houseFeature);
}
uint32_t FeaturesLayerMatcher::GetMatchingStreet(uint32_t houseId, FeatureType & houseFeature)
{
auto const it = m_matchingStreetsCache.find(houseId);
if (it != m_matchingStreetsCache.cend())
return it->second;
auto const & streets = GetNearbyStreets(houseId, houseFeature);
uint32_t const streetIndex = m_houseToStreetTable->Get(houseId);
uint32_t streetId = kInvalidId;
if (streetIndex < streets.size() && streets[streetIndex].m_id.m_mwmId == m_context.m_id)
streetId = streets[streetIndex].m_id.m_index;
m_matchingStreetsCache[houseId] = streetId;
return streetId;
return GetMatchingStreetImpl(houseId, houseFeature);
}
vector<ReverseGeocoder::Street> const & FeaturesLayerMatcher::GetNearbyStreets(uint32_t featureId)
@ -47,9 +52,7 @@ vector<ReverseGeocoder::Street> const & FeaturesLayerMatcher::GetNearbyStreets(u
FeatureType feature;
m_context.m_vector.GetByIndex(featureId, feature);
auto & streets = m_nearbyStreetsCache[featureId];
m_reverseGeocoder.GetNearbyStreets(feature, streets);
return streets;
return GetNearbyStreetsImpl(featureId, feature);
}
vector<ReverseGeocoder::Street> const & FeaturesLayerMatcher::GetNearbyStreets(
@ -59,6 +62,24 @@ vector<ReverseGeocoder::Street> const & FeaturesLayerMatcher::GetNearbyStreets(
if (it != m_nearbyStreetsCache.cend())
return it->second;
return GetNearbyStreetsImpl(featureId, feature);
}
uint32_t FeaturesLayerMatcher::GetMatchingStreetImpl(uint32_t houseId, FeatureType & houseFeature)
{
auto const & streets = GetNearbyStreets(houseId, houseFeature);
uint32_t const streetIndex = m_houseToStreetTable->Get(houseId);
uint32_t streetId = kInvalidId;
if (streetIndex < streets.size() && streets[streetIndex].m_id.m_mwmId == m_context.m_id)
streetId = streets[streetIndex].m_id.m_index;
m_matchingStreetsCache[houseId] = streetId;
return streetId;
}
vector<ReverseGeocoder::Street> const & FeaturesLayerMatcher::GetNearbyStreetsImpl(
uint32_t featureId, FeatureType & feature)
{
auto & streets = m_nearbyStreetsCache[featureId];
m_reverseGeocoder.GetNearbyStreets(feature, streets);
return streets;

View file

@ -134,6 +134,24 @@ private:
bool const queryLooksLikeHouseNumber =
!queryTokens.empty() && feature::IsHouseNumber(child.m_subQuery);
// When building name does not look like a house number it's
// faster to check nearby streets for each building instead of
// street vicinities loading.
if (!queryLooksLikeHouseNumber &&
child.m_sortedFeatures->size() < parent.m_sortedFeatures->size())
{
for (uint32_t houseId : *child.m_sortedFeatures)
{
uint32_t streetId = GetMatchingStreet(houseId);
if (binary_search(parent.m_sortedFeatures->begin(), parent.m_sortedFeatures->end(),
streetId))
{
fn(houseId, streetId);
}
}
return;
}
uint32_t numFilterInvocations = 0;
auto filter = [&](uint32_t id, FeatureType & feature) -> bool
{
@ -174,6 +192,8 @@ private:
// Returns id of a street feature corresponding to a |houseId|, or
// kInvalidId if there're not such street.
uint32_t GetMatchingStreet(uint32_t houseId);
uint32_t GetMatchingStreet(uint32_t houseId, FeatureType & houseFeature);
vector<ReverseGeocoder::Street> const & GetNearbyStreets(uint32_t featureId);
@ -181,6 +201,11 @@ private:
vector<ReverseGeocoder::Street> const & GetNearbyStreets(uint32_t featureId,
FeatureType & feature);
uint32_t GetMatchingStreetImpl(uint32_t houseId, FeatureType & houseFeature);
vector<ReverseGeocoder::Street> const & GetNearbyStreetsImpl(uint32_t featureId,
FeatureType & feature);
MwmContext & m_context;
ReverseGeocoder m_reverseGeocoder;