From cff487e9c3642cd74baead27cc5acc5930d933f1 Mon Sep 17 00:00:00 2001 From: vng Date: Sat, 5 Apr 2014 13:53:41 +0300 Subject: [PATCH] [search] Strict address match routine. --- search/house_detector.cpp | 57 ++++++++++++++++++++++++++++++++++++++- search/house_detector.hpp | 1 + search/search_query.cpp | 14 +++++----- 3 files changed, 64 insertions(+), 8 deletions(-) diff --git a/search/house_detector.cpp b/search/house_detector.cpp index cfd6701151..4eb485ae42 100644 --- a/search/house_detector.cpp +++ b/search/house_detector.cpp @@ -511,6 +511,11 @@ int HouseDetector::LoadStreets(vector const & ids) "Common =", count, "Cache =", m_id2st.size(), "Input =", ids.size())); ClearCaches(); } + else if (m_id2st.size() > ids.size() * 1.2) + { + LOG(LDEBUG, ("Clear unused")); + ClearUnusedStreets(ids); + } } // Load streets. @@ -865,7 +870,7 @@ void HouseDetector::ReadAllHouses(double offsetMeters) void HouseDetector::ClearCaches() { - for (StreetMapT::iterator it = m_id2st.begin(); it != m_id2st.end();++it) + for (StreetMapT::iterator it = m_id2st.begin(); it != m_id2st.end(); ++it) delete it->second; m_id2st.clear(); @@ -879,6 +884,56 @@ void HouseDetector::ClearCaches() m_streets.clear(); } +namespace +{ + +class HasSecond +{ + set const & m_streets; +public: + HasSecond(set const & streets) : m_streets(streets) {} + template bool operator() (T const & t) const + { + return m_streets.count(t.second) > 0; + } +}; + +class HasStreet +{ + set const & m_streets; +public: + HasStreet(set const & streets) : m_streets(streets) {} + bool operator() (MergedStreet const & st) const + { + for (size_t i = 0; i < st.m_cont.size(); ++i) + if (m_streets.count(st.m_cont[i]) > 0) + return true; + return false; + } +}; + +} + +void HouseDetector::ClearUnusedStreets(vector const & ids) +{ + set streets; + for (StreetMapT::iterator it = m_id2st.begin(); it != m_id2st.end();) + { + if (!binary_search(ids.begin(), ids.end(), it->first)) + { + streets.insert(it->second); + m_id2st.erase(it++); + } + else + ++it; + } + + m_end2st.erase(remove_if(m_end2st.begin(), m_end2st.end(), HasSecond(streets)), m_end2st.end()); + m_streets.erase(remove_if(m_streets.begin(), m_streets.end(), HasStreet(streets)), m_streets.end()); + + for_each(streets.begin(), streets.end(), DeleteFunctor()); +} + string DebugPrint(HouseProjection const & p) { return p.m_house->GetNumber(); diff --git a/search/house_detector.hpp b/search/house_detector.hpp index 25cbb8975c..4cd679049b 100644 --- a/search/house_detector.hpp +++ b/search/house_detector.hpp @@ -268,6 +268,7 @@ public: void GetHouseForName(string const & houseNumber, vector & res); void ClearCaches(); + void ClearUnusedStreets(vector const & ids); }; } diff --git a/search/search_query.cpp b/search/search_query.cpp index e65b06e3de..2d8a7f44a1 100644 --- a/search/search_query.cpp +++ b/search/search_query.cpp @@ -517,7 +517,7 @@ namespace impl class HouseCompFactory { - Query & m_query; + Query const & m_query; bool LessViewport(HouseResult const & r1, HouseResult const & r2) const { @@ -541,14 +541,14 @@ namespace impl } public: - HouseCompFactory(Query & q) : m_query(q) {} + HouseCompFactory(Query const & q) : m_query(q) {} struct CompT { - HouseCompFactory * m_parent; + HouseCompFactory const * m_parent; size_t m_alg; - CompT(HouseCompFactory * parent, size_t alg) : m_parent(parent), m_alg(alg) {} + CompT(HouseCompFactory const * parent, size_t alg) : m_parent(parent), m_alg(alg) {} bool operator() (HouseResult const & r1, HouseResult const & r2) const { if (m_alg == 0) @@ -601,6 +601,8 @@ void Query::FlushResults(Results & res, bool allMWMs, size_t resCount) if (indV.empty()) return; + RemoveDuplicatingLinear(indV); + void (Results::*addFn)(Result const &) = allMWMs ? &Results::AddResultCheckExisting : &Results::AddResult; @@ -621,7 +623,7 @@ void Query::FlushResults(Results & res, bool allMWMs, size_t resCount) // Limit address results when searching in first pass (position, viewport, locality). size_t count = houses.size(); if (!allMWMs) - count = min(count, size_t(3)); + count = min(count, size_t(5)); for (size_t i = 0; i < count; ++i) { @@ -633,8 +635,6 @@ void Query::FlushResults(Results & res, bool allMWMs, size_t resCount) } #endif - RemoveDuplicatingLinear(indV); - SortByIndexedValue(indV, CompFactory2()); // get preffered types to show in results