diff --git a/geocoder/geocoder_cli/geocoder_cli.cpp b/geocoder/geocoder_cli/geocoder_cli.cpp index 629d830cfe..bf7da7b589 100644 --- a/geocoder/geocoder_cli/geocoder_cli.cpp +++ b/geocoder/geocoder_cli/geocoder_cli.cpp @@ -1,6 +1,7 @@ #include "geocoder/geocoder.hpp" #include "geocoder/result.hpp" +#include "base/internal/message.hpp" #include "base/string_utils.hpp" #include @@ -17,7 +18,7 @@ DEFINE_string(hierarchy_path, "", "Path to the hierarchy file for the geocoder") DEFINE_string(queries_path, "", "Path to the file with queries"); DEFINE_int32(top, 5, "Number of top results to show for every query, -1 to show all results"); -void PrintResults(vector const & results) +void PrintResults(Hierarchy const & hierarchy, vector const & results) { cout << "Found results: " << results.size() << endl; if (results.empty()) @@ -27,7 +28,11 @@ void PrintResults(vector const & results) { if (FLAGS_top >= 0 && i >= FLAGS_top) break; - cout << " " << DebugPrint(results[i]) << endl; + Hierarchy::Entry const * e = hierarchy.GetEntryForOsmId(results[i].m_osmId); + cout << " " << DebugPrint(results[i]); + if (e != nullptr) + cout << " " << DebugPrint(e->m_address); + cout << endl; } } @@ -48,7 +53,7 @@ void ProcessQueriesFromFile(string const & path) cout << s << endl; geocoder.ProcessQuery(s, results); - PrintResults(results); + PrintResults(geocoder.GetHierarchy(), results); cout << endl; } } @@ -67,7 +72,7 @@ void ProcessQueriesFromCommandLine() if (query == "q" || query == ":q" || query == "quit") break; geocoder.ProcessQuery(query, results); - PrintResults(results); + PrintResults(geocoder.GetHierarchy(), results); } } diff --git a/geocoder/hierarchy.cpp b/geocoder/hierarchy.cpp index 0a92899221..bf8c43ecab 100644 --- a/geocoder/hierarchy.cpp +++ b/geocoder/hierarchy.cpp @@ -9,6 +9,7 @@ #include "base/stl_helpers.hpp" #include "base/string_utils.hpp" +#include #include #include @@ -149,6 +150,12 @@ Hierarchy::Hierarchy(string const & pathToJsonHierarchy) m_entriesStorage.emplace_back(move(entry)); } + if (stats.m_numLoaded % kLogBatch != 0) + LOG(LINFO, ("Read", stats.m_numLoaded, "entries")); + + LOG(LINFO, ("Sorting entries...")); + sort(m_entriesStorage.begin(), m_entriesStorage.end()); + LOG(LINFO, ("Indexing entries...")); IndexEntries(); LOG(LINFO, ("Indexing houses...")); @@ -175,6 +182,20 @@ vector const * const Hierarchy::GetEntries(Tokens const & to return &it->second; } +Hierarchy::Entry const * Hierarchy::GetEntryForOsmId(base::GeoObjectId const & osmId) const +{ + auto const cmp = [](Hierarchy::Entry const & e, base::GeoObjectId const & id) { + return e.m_osmId < id; + }; + + auto it = lower_bound(m_entriesStorage.begin(), m_entriesStorage.end(), osmId, cmp); + + if (it == m_entriesStorage.end() || it->m_osmId != osmId) + return nullptr; + + return &(*it); +} + void Hierarchy::IndexEntries() { size_t numIndexed = 0; @@ -203,6 +224,9 @@ void Hierarchy::IndexEntries() if (numIndexed % kLogBatch == 0) LOG(LINFO, ("Indexed", numIndexed, "entries")); } + + if (numIndexed % kLogBatch != 0) + LOG(LINFO, ("Indexed", numIndexed, "entries")); } void Hierarchy::IndexStreet(Entry & e) @@ -245,5 +269,8 @@ void Hierarchy::IndexHouses() if (numIndexed % kLogBatch == 0) LOG(LINFO, ("Indexed", numIndexed, "houses")); } + + if (numIndexed % kLogBatch != 0) + LOG(LINFO, ("Indexed", numIndexed, "houses")); } } // namespace geocoder diff --git a/geocoder/hierarchy.hpp b/geocoder/hierarchy.hpp index 8880b5460b..0197279d4e 100644 --- a/geocoder/hierarchy.hpp +++ b/geocoder/hierarchy.hpp @@ -59,6 +59,8 @@ public: // Checks whether this entry is a parent of |e|. bool IsParentTo(Entry const & e) const; + bool operator<(Entry const & rhs) const { return m_osmId < rhs.m_osmId; } + base::GeoObjectId m_osmId = base::GeoObjectId(base::GeoObjectId::kInvalid); // Original name of the entry. Useful for debugging. @@ -86,6 +88,8 @@ public: // be implemented to perform this type of queries. std::vector const * const GetEntries(Tokens const & tokens) const; + Entry const * GetEntryForOsmId(base::GeoObjectId const & osmId) const; + private: // Adds address information of entries to the index. void IndexEntries();