diff --git a/geocoder/geocoder.cpp b/geocoder/geocoder.cpp index e312798..00ec4cf 100644 --- a/geocoder/geocoder.cpp +++ b/geocoder/geocoder.cpp @@ -29,6 +29,7 @@ #include #include #include +#include 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, diff --git a/geocoder/geocoder_tests/geocoder_tests.cpp b/geocoder/geocoder_tests/geocoder_tests.cpp index f0498ed..760f226 100644 --- a/geocoder/geocoder_tests/geocoder_tests.cpp +++ b/geocoder/geocoder_tests/geocoder_tests.cpp @@ -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) {