Merge pull request #22 from mapsme/geocoder.locality-building-rank-fix

[geocoder] Fix locality building rank
This commit is contained in:
Sergey Yershov 2019-10-16 19:03:23 +03:00 committed by GitHub
commit 244e8fc311
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View file

@ -447,17 +447,23 @@ void Geocoder::FillBuildingsLayer(Context & ctx, Tokens const & subquery, vector
// let's stay on the safer side and mark the tokens as potential house number.
ctx.MarkHouseNumberPositionsInQuery(subqueryTokenIds);
auto const & lastLayer = ctx.GetLayers().back();
auto const forSublocalityLayer =
lastLayer.m_type == Type::Suburb || lastLayer.m_type == Type::Sublocality;
for (auto const & docId : layer.m_entries)
{
m_index.ForEachRelatedBuilding(docId, [&](Index::DocId const & buildingDocId) {
auto const & bld = m_index.GetDoc(buildingDocId);
auto const & multipleHN = bld.GetNormalizedMultipleNames(
auto const & building = m_index.GetDoc(buildingDocId);
auto const & multipleHN = building.GetNormalizedMultipleNames(
Type::Building, m_hierarchy.GetNormalizedNameDictionary());
auto const & realHN = multipleHN.GetMainName();
auto const & realHNUniStr = strings::MakeUniString(realHN);
if (search::house_numbers::HouseNumbersMatch(realHNUniStr, subqueryHN,
false /* queryIsPrefix */))
{
if (forSublocalityLayer && !HasParent(ctx.GetLayers(), building))
return;
curLayer.m_entries.emplace_back(buildingDocId);
}
});

View file

@ -319,6 +319,24 @@ UNIT_TEST(Geocoder_LocalityBuilding)
TestGeocoder(geocoder, "Zelenograd 2", {{building2, 1.0}});
}
//--------------------------------------------------------------------------------------------------
UNIT_TEST(Geocoder_LocalityBuildingRankWithSuburb)
{
string const kData = R"#(
10 {"properties": {"locales": {"default": {"address": {"locality": "Москва"}}}}}
11 {"properties": {"locales": {"default": {"address": {"suburb": "Арбат", "locality": "Москва"}}}}}
12 {"properties": {"locales": {"default": {"address": {"building": "1", "suburb": "Арбат", "locality": "Москва"}}}}}
13 {"properties": {"locales": {"default": {"address": {"suburb": "район Северный", "locality": "Москва"}}}}}
14 {"properties": {"locales": {"default": {"address": {"building": "1", "suburb": "район Северный", "locality": "Москва"}}}}}
)#";
Geocoder geocoder;
ScopedFile const regionsJsonFile("regions.jsonl", kData);
geocoder.LoadFromJsonl(regionsJsonFile.GetFullPath());
TestGeocoder(geocoder, "Москва, Арбат 1", {{Id{0x12}, 1.0}, {Id{0x14}, 0.836066}});
}
//--------------------------------------------------------------------------------------------------
UNIT_TEST(Geocoder_LocalityAndStreetBuildingsRank)
{