[geocoder] Fix locality building rank

This commit is contained in:
Anatoly Serdtcev 2019-10-15 12:20:40 +03:00 committed by LaGrunge
parent d37030b1a8
commit c36513c3f8
2 changed files with 25 additions and 4 deletions

View file

@ -29,6 +29,7 @@
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptor/reversed.hpp>
using namespace std;
@ -436,9 +437,10 @@ void Geocoder::FillBuildingsLayer(Context & ctx, Tokens const & subquery, vector
if (!search::house_numbers::LooksLikeHouseNumber(subqueryHN, false /* isPrefix */))
return;
for_each(ctx.GetLayers().rbegin(), ctx.GetLayers().rend(), [&, this] (auto const & layer) {
for (auto const & layer : boost::adaptors::reverse(ctx.GetLayers()))
{
if (layer.m_type != Type::Street && layer.m_type != Type::Locality)
return;
continue;
// We've already filled a street/location layer and now see something that resembles
// a house number. While it still can be something else (a zip code, for example)
@ -460,7 +462,9 @@ void Geocoder::FillBuildingsLayer(Context & ctx, Tokens const & subquery, vector
}
});
}
});
break;
}
}
void Geocoder::FillRegularLayer(Context const & ctx, Type type, Tokens const & subquery,

View file

@ -22,7 +22,7 @@ namespace
{
using Id = base::GeoObjectId;
double const kCertaintyEps = 1e-6;
double const kCertaintyEps = 1e-4;
string const kRegionsData = R"#(
C00000000004B279 {"type": "Feature", "geometry": {"type": "Point", "coordinates": [-80.1142033187951, 21.55511095]}, "properties": {"locales": {"default": {"name": "Cuba", "address": {"country": "Cuba"}}}, "rank": 2}}
C0000000001C4CA7 {"type": "Feature", "geometry": {"type": "Point", "coordinates": [-78.7260117405499, 21.74300205]}, "properties": {"locales": {"default": {"name": "Ciego de Ávila", "address": {"region": "Ciego de Ávila", "country": "Cuba"}}}, "rank": 4}}
@ -319,6 +319,23 @@ UNIT_TEST(Geocoder_LocalityBuilding)
TestGeocoder(geocoder, "Zelenograd 2", {{building2, 1.0}});
}
//--------------------------------------------------------------------------------------------------
UNIT_TEST(Geocoder_LocalityAndStreetBuildingsRank)
{
string const kData = R"#(
10 {"properties": {"locales": {"default": {"address": {"locality": "Zelenograd"}}}}}
22 {"properties": {"locales": {"default": {"address": {"building": "2", "locality": "Zelenograd"}}}}}
31 {"properties": {"locales": {"default": {"address": {"street": "Krymskaya", "locality": "Zelenograd"}}}}}
32 {"properties": {"locales": {"default": {"address": {"building": "2", "street": "Krymskaya", "locality": "Zelenograd"}}}}}
)#";
Geocoder geocoder;
ScopedFile const regionsJsonFile("regions.jsonl", kData);
geocoder.LoadFromJsonl(regionsJsonFile.GetFullPath());
TestGeocoder(geocoder, "Zelenograd, Krymskaya 2", {{Id{0x32}, 1.0}, {Id{0x22}, 0.7560}});
}
// Geocoder_Subregion* -----------------------------------------------------------------------------
UNIT_TEST(Geocoder_SubregionInLocality)
{