diff options
author | Yuri Gorshenin <y@maps.me> | 2016-07-05 21:28:14 +0300 |
---|---|---|
committer | Yuri Gorshenin <y@maps.me> | 2016-07-05 21:43:49 +0300 |
commit | abad74b76c735eca873ee1384de40607993aec32 (patch) | |
tree | 888a078227bc383ced634f6332b3640061586baa /search | |
parent | e7915eb557ff76a913e934da17c601d71f891fe6 (diff) |
[indexer] Fixed FeaturesLoaderGuard.
Diffstat (limited to 'search')
-rw-r--r-- | search/house_detector.cpp | 40 | ||||
-rw-r--r-- | search/house_detector.hpp | 15 | ||||
-rw-r--r-- | search/ranker.cpp | 11 | ||||
-rw-r--r-- | search/search_integration_tests/processor_test.cpp | 4 | ||||
-rw-r--r-- | search/search_quality/features_collector_tool/features_collector_tool.cpp | 8 | ||||
-rw-r--r-- | search/search_tests/house_detector_tests.cpp | 14 |
6 files changed, 44 insertions, 48 deletions
diff --git a/search/house_detector.cpp b/search/house_detector.cpp index a5f33f6b46..8e7dcf95c0 100644 --- a/search/house_detector.cpp +++ b/search/house_detector.cpp @@ -222,41 +222,24 @@ bool House::GetNearbyMatch(ParsedNumber const & number) const return m_number.IsIntersect(number, HN_NEARBY_DISTANCE); } -FeatureLoader::FeatureLoader(Index const * pIndex) - : m_pIndex(pIndex), m_pGuard(0) -{ -} - -FeatureLoader::~FeatureLoader() -{ - Free(); -} +FeatureLoader::FeatureLoader(Index const & index) : m_index(index) {} void FeatureLoader::CreateLoader(MwmSet::MwmId const & mwmId) { - if (m_pGuard == nullptr || mwmId != m_pGuard->GetId()) - { - delete m_pGuard; - m_pGuard = new Index::FeaturesLoaderGuard(*m_pIndex, mwmId); - } + if (!m_guard || mwmId != m_guard->GetId()) + m_guard = make_unique<Index::FeaturesLoaderGuard>(m_index, mwmId); } -void FeatureLoader::Load(FeatureID const & id, FeatureType & f) +bool FeatureLoader::Load(FeatureID const & id, FeatureType & f) { CreateLoader(id.m_mwmId); - m_pGuard->GetFeatureByIndex(id.m_index, f); -} - -void FeatureLoader::Free() -{ - delete m_pGuard; - m_pGuard = 0; + return m_guard->GetFeatureByIndex(id.m_index, f); } template <class ToDo> void FeatureLoader::ForEachInRect(m2::RectD const & rect, ToDo toDo) { - m_pIndex->ForEachInRect(toDo, rect, scales::GetUpperScale()); + m_index.ForEachInRect(toDo, rect, scales::GetUpperScale()); } m2::RectD Street::GetLimitRect(double offsetMeters) const @@ -329,8 +312,8 @@ void Street::SortHousesProjection() sort(m_houses.begin(), m_houses.end(), &LessStreetDistance); } -HouseDetector::HouseDetector(Index const * pIndex) - : m_loader(pIndex), m_streetNum(0) +HouseDetector::HouseDetector(Index const & index) + : m_loader(index), m_streetNum(0) { // default value for conversions SetMetres2Mercator(360.0 / 40.0E06); @@ -463,7 +446,12 @@ int HouseDetector::LoadStreets(vector<FeatureID> const & ids) continue; FeatureType f; - m_loader.Load(ids[i], f); + if (!m_loader.Load(ids[i], f)) + { + LOG(LWARNING, ("Can't read feature from:", ids[i].m_mwmId)); + continue; + } + if (f.GetFeatureType() == feature::GEOM_LINE) { // Use default name as a primary compare key for merging. diff --git a/search/house_detector.hpp b/search/house_detector.hpp index deb30b79b2..d23a4b8264 100644 --- a/search/house_detector.hpp +++ b/search/house_detector.hpp @@ -7,6 +7,8 @@ #include "geometry/point2d.hpp" +#include "base/macros.hpp" + #include "std/string.hpp" #include "std/queue.hpp" @@ -16,17 +18,16 @@ namespace search class FeatureLoader { - Index const * m_pIndex; - Index::FeaturesLoaderGuard * m_pGuard; + Index const & m_index; + unique_ptr<Index::FeaturesLoaderGuard> m_guard; void CreateLoader(MwmSet::MwmId const & mwmId); public: - FeatureLoader(Index const * pIndex); - ~FeatureLoader(); + FeatureLoader(Index const & index); - void Load(FeatureID const & id, FeatureType & f); - void Free(); + WARN_UNUSED_RESULT bool Load(FeatureID const & id, FeatureType & f); + inline void Free() { m_guard.reset(); } template <class ToDo> void ForEachInRect(m2::RectD const & rect, ToDo toDo); }; @@ -251,7 +252,7 @@ class HouseDetector double GetApprLengthMeters(int index) const; public: - HouseDetector(Index const * pIndex); + HouseDetector(Index const & index); ~HouseDetector(); int LoadStreets(vector<FeatureID> const & ids); diff --git a/search/ranker.cpp b/search/ranker.cpp index c2c0d5b3ad..2b06104917 100644 --- a/search/ranker.cpp +++ b/search/ranker.cpp @@ -140,13 +140,15 @@ class PreResult2Maker unique_ptr<Index::FeaturesLoaderGuard> m_pFV; // For the best performance, incoming id's should be sorted by id.first (mwm file id). - void LoadFeature(FeatureID const & id, FeatureType & f, m2::PointD & center, string & name, + bool LoadFeature(FeatureID const & id, FeatureType & f, m2::PointD & center, string & name, string & country) { if (m_pFV.get() == 0 || m_pFV->GetId() != id.m_mwmId) m_pFV.reset(new Index::FeaturesLoaderGuard(m_index, id.m_mwmId)); - m_pFV->GetFeatureByIndex(id.m_index, f); + if (!m_pFV->GetFeatureByIndex(id.m_index, f)) + return false; + f.SetID(id); center = feature::GetCenter(f); @@ -158,6 +160,8 @@ class PreResult2Maker country.clear(); else country = m_pFV->GetCountryFileName(); + + return true; } void InitRankingInfo(FeatureType const & ft, m2::PointD const & center, PreResult1 const & res, @@ -252,7 +256,8 @@ public: string name; string country; - LoadFeature(res1.GetId(), ft, center, name, country); + if (LoadFeature(res1.GetId(), ft, center, name, country)) + return unique_ptr<PreResult2>(); auto res2 = make_unique<PreResult2>(ft, &res1, center, m_ranker.m_params.m_position /* pivot */, name, country); diff --git a/search/search_integration_tests/processor_test.cpp b/search/search_integration_tests/processor_test.cpp index 9ea17b03af..822a53d9c9 100644 --- a/search/search_integration_tests/processor_test.cpp +++ b/search/search_integration_tests/processor_test.cpp @@ -509,7 +509,7 @@ UNIT_CLASS_TEST(ProcessorTest, TestPostcodes) Index::FeaturesLoaderGuard loader(m_engine, countryId); FeatureType ft; - loader.GetFeatureByIndex(index, ft); + TEST(loader.GetFeatureByIndex(index, ft), ()); auto rule = ExactMatch(countryId, building31); TEST(rule->Matches(ft), ()); @@ -606,7 +606,7 @@ UNIT_CLASS_TEST(ProcessorTest, TestCategories) { Index::FeaturesLoaderGuard loader(m_engine, wonderlandId); FeatureType ft; - loader.GetFeatureByIndex(result.GetFeatureID().m_index, ft); + TEST(loader.GetFeatureByIndex(result.GetFeatureID().m_index, ft), ()); auto const & info = result.GetRankingInfo(); diff --git a/search/search_quality/features_collector_tool/features_collector_tool.cpp b/search/search_quality/features_collector_tool/features_collector_tool.cpp index 5d7c071ade..f9ed98d0ef 100644 --- a/search/search_quality/features_collector_tool/features_collector_tool.cpp +++ b/search/search_quality/features_collector_tool/features_collector_tool.cpp @@ -20,6 +20,7 @@ #include "geometry/mercator.hpp" +#include "base/macros.hpp" #include "base/string_utils.hpp" #include "std/fstream.hpp" @@ -54,12 +55,12 @@ struct Context { Context(Index & index) : m_index(index) {} - void GetFeature(FeatureID const & id, FeatureType & ft) + WARN_UNUSED_RESULT bool GetFeature(FeatureID const & id, FeatureType & ft) { auto const & mwmId = id.m_mwmId; if (!m_guard || m_guard->GetId() != mwmId) m_guard = make_unique<Index::FeaturesLoaderGuard>(m_index, mwmId); - m_guard->GetFeatureByIndex(id.m_index, ft); + return m_guard->GetFeatureByIndex(id.m_index, ft); } Index & m_index; @@ -83,7 +84,8 @@ bool Matches(Context & context, Sample::Result const & golden, search::Result co return false; FeatureType ft; - context.GetFeature(actual.GetFeatureID(), ft); + if (!context.GetFeature(actual.GetFeatureID(), ft)) + return false; string name; if (!ft.GetName(FeatureType::DEFAULT_LANG, name)) diff --git a/search/search_tests/house_detector_tests.cpp b/search/search_tests/house_detector_tests.cpp index 0c6f82350f..7d52ea1161 100644 --- a/search/search_tests/house_detector_tests.cpp +++ b/search/search_tests/house_detector_tests.cpp @@ -197,7 +197,7 @@ UNIT_TEST(HS_StreetsMerge) TEST_EQUAL(MwmSet::RegResult::Success, p.second, ()); { - search::HouseDetector houser(&index); + search::HouseDetector houser(index); StreetIDsByName toDo; toDo.streetNames.push_back("улица Володарского"); index.ForEachInScale(toDo, scales::GetUpperScale()); @@ -206,7 +206,7 @@ UNIT_TEST(HS_StreetsMerge) } { - search::HouseDetector houser(&index); + search::HouseDetector houser(index); StreetIDsByName toDo; toDo.streetNames.push_back("Московская улица"); index.ForEachInScale(toDo, scales::GetUpperScale()); @@ -215,7 +215,7 @@ UNIT_TEST(HS_StreetsMerge) } { - search::HouseDetector houser(&index); + search::HouseDetector houser(index); StreetIDsByName toDo; toDo.streetNames.push_back("проспект Независимости"); toDo.streetNames.push_back("Московская улица"); @@ -225,7 +225,7 @@ UNIT_TEST(HS_StreetsMerge) } { - search::HouseDetector houser(&index); + search::HouseDetector houser(index); StreetIDsByName toDo; toDo.streetNames.push_back("проспект Независимости"); toDo.streetNames.push_back("Московская улица"); @@ -238,7 +238,7 @@ UNIT_TEST(HS_StreetsMerge) } { - search::HouseDetector houser(&index); + search::HouseDetector houser(index); StreetIDsByName toDo; toDo.streetNames.push_back("проспект Независимости"); toDo.streetNames.push_back("Московская улица"); @@ -256,7 +256,7 @@ namespace m2::PointD FindHouse(Index & index, vector<string> const & streets, string const & houseName, double offset) { - search::HouseDetector houser(&index); + search::HouseDetector houser(index); StreetIDsByName toDo; toDo.streetNames = streets; @@ -426,7 +426,7 @@ UNIT_TEST(HS_MWMSearch) sort(addresses.begin(), addresses.end()); - search::HouseDetector detector(&index); + search::HouseDetector detector(index); size_t all = 0, matched = 0, notMatched = 0; size_t const percent = max(size_t(1), addresses.size() / 100); |