From 70ecaf1e1eaf53baf9da3102304a2347fc937a87 Mon Sep 17 00:00:00 2001 From: Anatoly Serdtcev Date: Thu, 7 Mar 2019 15:28:47 +0300 Subject: [PATCH 1/2] [geocoder] Optimize CPU: no index street synonym only --- geocoder/index.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/geocoder/index.cpp b/geocoder/index.cpp index 21b30be043..cdd4ff2b70 100644 --- a/geocoder/index.cpp +++ b/geocoder/index.cpp @@ -83,11 +83,25 @@ void Index::AddStreet(DocId const & docId, Index::Doc const & doc) { CHECK_EQUAL(doc.m_type, Type::Street, ()); size_t const t = static_cast(doc.m_type); + + auto isStreetSuffix = [] (std::string const & s) { + return search::IsStreetSynonym(strings::MakeUniString(s)); + }; + + if (all_of(begin(doc.m_address[t]), end(doc.m_address[t]), isStreetSuffix)) + { + LOG(LDEBUG, ("Undefined proper name in tokens ", doc.m_address[t], "of street entry", + doc.m_osmId, "(", doc.m_address, ")")); + if (doc.m_address[t].size() > 1) + m_docIdsByTokens[MakeIndexKey(doc.m_address[t])].emplace_back(docId); + return; + } + m_docIdsByTokens[MakeIndexKey(doc.m_address[t])].emplace_back(docId); for (size_t i = 0; i < doc.m_address[t].size(); ++i) { - if (!search::IsStreetSynonym(strings::MakeUniString(doc.m_address[t][i]))) + if (!isStreetSuffix(doc.m_address[t][i])) continue; auto addr = doc.m_address[t]; addr.erase(addr.begin() + i); From 334baf3f3d27b4320446daefa446cff959450299 Mon Sep 17 00:00:00 2001 From: Anatoly Serdtcev Date: Thu, 7 Mar 2019 16:20:37 +0300 Subject: [PATCH 2/2] [geocoder] Fix for review --- geocoder/index.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/geocoder/index.cpp b/geocoder/index.cpp index cdd4ff2b70..e6e5f91bbd 100644 --- a/geocoder/index.cpp +++ b/geocoder/index.cpp @@ -84,13 +84,13 @@ void Index::AddStreet(DocId const & docId, Index::Doc const & doc) CHECK_EQUAL(doc.m_type, Type::Street, ()); size_t const t = static_cast(doc.m_type); - auto isStreetSuffix = [] (std::string const & s) { + auto isStreetSynonym = [] (string const & s) { return search::IsStreetSynonym(strings::MakeUniString(s)); }; - if (all_of(begin(doc.m_address[t]), end(doc.m_address[t]), isStreetSuffix)) + if (all_of(begin(doc.m_address[t]), end(doc.m_address[t]), isStreetSynonym)) { - LOG(LDEBUG, ("Undefined proper name in tokens ", doc.m_address[t], "of street entry", + LOG(LDEBUG, ("Undefined proper name in tokens", doc.m_address[t], "of street entry", doc.m_osmId, "(", doc.m_address, ")")); if (doc.m_address[t].size() > 1) m_docIdsByTokens[MakeIndexKey(doc.m_address[t])].emplace_back(docId); @@ -101,7 +101,7 @@ void Index::AddStreet(DocId const & docId, Index::Doc const & doc) for (size_t i = 0; i < doc.m_address[t].size(); ++i) { - if (!isStreetSuffix(doc.m_address[t][i])) + if (!isStreetSynonym(doc.m_address[t][i])) continue; auto addr = doc.m_address[t]; addr.erase(addr.begin() + i);