diff options
author | Yuri Gorshenin <y@maps.me> | 2016-06-21 10:54:15 +0300 |
---|---|---|
committer | Yuri Gorshenin <y@maps.me> | 2016-06-21 16:27:11 +0300 |
commit | 0d12ff44368782c058f75d350c0825f55fa9e40e (patch) | |
tree | 4546448daaf1a3df9b8adc5abbe68ed2d54a6924 /search | |
parent | 0a8760da49f39a487a7ee961dde3e9abd57a5b82 (diff) |
[search] Fixed streets matching by postcodes.
Diffstat (limited to 'search')
-rw-r--r-- | search/geocoder.cpp | 18 | ||||
-rw-r--r-- | search/geocoder.hpp | 2 | ||||
-rw-r--r-- | search/search_integration_tests/processor_test.cpp | 26 |
3 files changed, 39 insertions, 7 deletions
diff --git a/search/geocoder.cpp b/search/geocoder.cpp index 5db6ec2b62..a1fc829e04 100644 --- a/search/geocoder.cpp +++ b/search/geocoder.cpp @@ -1213,7 +1213,23 @@ void Geocoder::MatchPOIsAndBuildings(size_t curToken) // If there're only one street layer but user also entered a // postcode, we need to emit all features matching to postcode on - // the given street. + // the given street, including the street itself. + + // Following code emits streets matched by postcodes, because + // GreedilyMatchStreets() doesn't (and shouldn't) perform + // postcodes matching. + { + for (auto const & id : *m_layers.back().m_sortedFeatures) + { + if (!m_postcodes.Has(id)) + continue; + EmitResult(m_context->GetId(), id, SearchModel::SEARCH_TYPE_STREET, + m_layers.back().m_startToken, m_layers.back().m_endToken); + } + } + + // Following code creates a fake layer with buildings and + // intersects it with the streets layer. m_layers.emplace_back(); MY_SCOPE_GUARD(cleanupGuard, bind(&vector<FeaturesLayer>::pop_back, &m_layers)); diff --git a/search/geocoder.hpp b/search/geocoder.hpp index db8e905b98..7f4ce6d623 100644 --- a/search/geocoder.hpp +++ b/search/geocoder.hpp @@ -178,6 +178,8 @@ private: m_features.reset(); } + inline bool Has(uint64_t id) const { return m_features->GetBit(id); } + inline bool IsEmpty() const { return coding::CompressedBitVector::IsEmpty(m_features); } size_t m_startToken = 0; diff --git a/search/search_integration_tests/processor_test.cpp b/search/search_integration_tests/processor_test.cpp index ce6a50045d..557e7e07be 100644 --- a/search/search_integration_tests/processor_test.cpp +++ b/search/search_integration_tests/processor_test.cpp @@ -454,14 +454,21 @@ UNIT_CLASS_TEST(ProcessorTest, TestPostcodes) TestStreet street( vector<m2::PointD>{m2::PointD(-0.5, 0.0), m2::PointD(0, 0), m2::PointD(0.5, 0.0)}, "Первомайская", "ru"); + street.SetPostcode("141701"); + TestBuilding building28(m2::PointD(0.0, 0.00001), "", "28а", street, "ru"); building28.SetPostcode("141701"); TestBuilding building29(m2::PointD(0.0, -0.00001), "", "29", street, "ru"); building29.SetPostcode("141701"); - TestBuilding building30(m2::PointD(0.00001, 0.00001), "", "30", street, "ru"); - building30.SetPostcode("141702"); + TestPOI building30(m2::PointD(0.00002, 0.00002), "", "en"); + building30.SetHouseNumber("30"); + building30.SetPostcode("141701"); + building30.SetTypes({{"building", "address"}}); + + TestBuilding building31(m2::PointD(0.00001, 0.00001), "", "31", street, "ru"); + building31.SetPostcode("141702"); TestBuilding building1(m2::PointD(10, 10), "", "1", "en"); building1.SetPostcode("WC2H 7BX"); @@ -477,6 +484,7 @@ UNIT_CLASS_TEST(ProcessorTest, TestPostcodes) builder.Add(building28); builder.Add(building29); builder.Add(building30); + builder.Add(building31); builder.Add(building1); }); @@ -503,7 +511,7 @@ UNIT_CLASS_TEST(ProcessorTest, TestPostcodes) FeatureType ft; loader.GetFeatureByIndex(index, ft); - auto rule = ExactMatch(countryId, building30); + auto rule = ExactMatch(countryId, building31); TEST(rule->Matches(ft), ()); } @@ -516,15 +524,21 @@ UNIT_CLASS_TEST(ProcessorTest, TestPostcodes) TEST(ResultsMatch("Долгопрудный первомайская 28а, 141701", "ru", rules), ()); } { - TRules rules{ExactMatch(countryId, building28), ExactMatch(countryId, building29)}; + TRules rules{ExactMatch(countryId, building28), ExactMatch(countryId, building29), + ExactMatch(countryId, building30), ExactMatch(countryId, street)}; TEST(ResultsMatch("Долгопрудный первомайская 141701", "ru", rules), ()); } { - TRules rules{ExactMatch(countryId, building28), ExactMatch(countryId, building29)}; + TRules rules{ExactMatch(countryId, building31)}; + TEST(ResultsMatch("Долгопрудный первомайская 141702", "ru", rules), ()); + } + { + TRules rules{ExactMatch(countryId, building28), ExactMatch(countryId, building29), + ExactMatch(countryId, building30), ExactMatch(countryId, street)}; TEST(ResultsMatch("Долгопрудный 141701", "ru", rules), ()); } { - TRules rules{ExactMatch(countryId, building30)}; + TRules rules{ExactMatch(countryId, building31)}; TEST(ResultsMatch("Долгопрудный 141702", "ru", rules), ()); } |