diff --git a/generator/search_index_builder.cpp b/generator/search_index_builder.cpp index aafbcef201..8c4a5af87a 100644 --- a/generator/search_index_builder.cpp +++ b/generator/search_index_builder.cpp @@ -104,7 +104,8 @@ void GetCategoryTypes(CategoriesHolder const & categories, pair const for (uint32_t t : types) { // Leave only 2 levels of types - for example, do not distinguish: - // highway-primary-bridge or amenity-parking-fee. + // highway-primary-bridge and highway-primary-tunnel + // or amenity-parking-fee and amenity-parking-underground-fee. ftype::TruncValue(t, 2); // Only categorized types will be added to index. @@ -130,11 +131,9 @@ struct FeatureNameInserter bool m_hasStreetType; FeatureNameInserter(SynonymsHolder * synonyms, vector> & keyValuePairs, - vector const & categoryTypes) - : m_synonyms(synonyms), m_keyValuePairs(keyValuePairs) + bool hasStreetType) + : m_synonyms(synonyms), m_keyValuePairs(keyValuePairs), m_hasStreetType(hasStreetType) { - auto const & streetChecker = ftypes::IsStreetChecker::Instance(); - m_hasStreetType = streetChecker(categoryTypes); } void AddToken(signed char lang, strings::UniString const & s) const @@ -178,22 +177,22 @@ public: // "street" in the categories branch of the search index. // However, we still add it when there are two or more street tokens // ("industrial st", "улица набережная"). - size_t numStreets = 0; + size_t numStreetTokens = 0; vector isStreet(tokens.size()); for (size_t i = 0; i < tokens.size(); ++i) { - if (search::IsStreetSynonym(strings::ToUtf8(tokens[i]))) + if (search::IsStreetSynonym(tokens[i])) { isStreet[i] = true; - ++numStreets; + ++numStreetTokens; } } for (size_t i = 0; i < tokens.size(); ++i) { - if (numStreets == 1 && isStreet[i] && m_hasStreetType) + if (numStreetTokens == 1 && isStreet[i] && m_hasStreetType) { - LOG(LDEBUG, ("skipping street:", name)); + LOG(LDEBUG, ("skipping token:", tokens[i], "in", name)); continue; } AddToken(lang, tokens[i]); @@ -268,13 +267,13 @@ public: if (types.Empty()) return; - vector categoryTypes; - GetCategoryTypes(m_categories, m_scales, types, categoryTypes); + auto const & streetChecker = ftypes::IsStreetChecker::Instance(); + bool hasStreetType = streetChecker(types); // Init inserter with serialized value. // Insert synonyms only for countries and states (maybe will add cities in future). FeatureNameInserter inserter( - skipIndex.IsCountryOrState(types) ? m_synonyms : nullptr, m_keyValuePairs, categoryTypes); + skipIndex.IsCountryOrState(types) ? m_synonyms : nullptr, m_keyValuePairs, hasStreetType); m_valueBuilder.MakeValue(f, types, index, inserter.m_val); // Skip types for features without names. @@ -285,7 +284,7 @@ public: Classificator const & c = classif(); - categoryTypes.clear(); + vector categoryTypes; GetCategoryTypes(m_categories, m_scales, types, categoryTypes); // add names of categories of the feature diff --git a/search/search_integration_tests/search_query_v2_test.cpp b/search/search_integration_tests/search_query_v2_test.cpp index f699f98031..964ba0ab02 100644 --- a/search/search_integration_tests/search_query_v2_test.cpp +++ b/search/search_integration_tests/search_query_v2_test.cpp @@ -49,6 +49,8 @@ class TestSearchQueryFactory : public search::SearchQueryFactory UNIT_TEST(SearchQueryV2_Smoke) { + my::g_LogLevel = LDEBUG; + classificator::Load(); Platform & platform = GetPlatform(); platform::LocalCountryFile wonderland(platform.WritableDir(), platform::CountryFile("wonderland"), diff --git a/search/search_string_utils.cpp b/search/search_string_utils.cpp index f063db0651..67aed4beba 100644 --- a/search/search_string_utils.cpp +++ b/search/search_string_utils.cpp @@ -5,13 +5,7 @@ #include "base/macros.hpp" -namespace -{ -string NormalizeAndSimplifyRawString(char const * s) -{ - return strings::ToUtf8(search::NormalizeAndSimplifyString(s)); -} -} // namespace +char const * STREET_TOKENS_SEPARATOR = "\t -,."; strings::UniString search::FeatureTypeToString(uint32_t type) { @@ -19,9 +13,6 @@ strings::UniString search::FeatureTypeToString(uint32_t type) return strings::UniString(s.begin(), s.end()); } - -char const * STREET_TOKENS_SEPARATOR = "\t -,."; - /// @todo Move prefixes, suffixes into separate file (autogenerated). /// "Набережная" улица встречается в городах @@ -114,10 +105,10 @@ void search::GetStreetNameAsKey(string const & name, string & res) GetStreetName(iter, res); } -bool search::IsStreetSynonym(string const & s) +bool search::IsStreetSynonym(strings::UniString const & s) { - static unordered_set const kSynonyms( - make_transform_iterator(affics, &NormalizeAndSimplifyRawString), - make_transform_iterator(affics + ARRAY_SIZE(affics), &NormalizeAndSimplifyRawString)); + static set const kSynonyms( + make_transform_iterator(affics, &search::NormalizeAndSimplifyString), + make_transform_iterator(affics + ARRAY_SIZE(affics), &search::NormalizeAndSimplifyString)); return kSynonyms.count(s) != 0; } diff --git a/search/search_string_utils.hpp b/search/search_string_utils.hpp index 6cd9b6faf1..a79851a92f 100644 --- a/search/search_string_utils.hpp +++ b/search/search_string_utils.hpp @@ -114,5 +114,5 @@ bool TokenizeStringAndCheckIfLastTokenIsPrefix(string const & s, void GetStreetName(strings::SimpleTokenizer iter, string & streetName); void GetStreetNameAsKey(string const & name, string & res); -bool IsStreetSynonym(string const & s); +bool IsStreetSynonym(strings::UniString const & s); } // namespace search diff --git a/search/v2/geocoder.cpp b/search/v2/geocoder.cpp index 07adfe7659..41d33659f5 100644 --- a/search/v2/geocoder.cpp +++ b/search/v2/geocoder.cpp @@ -430,7 +430,7 @@ void Geocoder::GreedilyMatchStreets() size_t curToken = startToken; for (; curToken < m_numTokens && !m_usedTokens[curToken]; ++curToken) { - if (IsStreetSynonym(strings::ToUtf8(m_params.GetTokens(curToken).front()))) + if (IsStreetSynonym(m_params.GetTokens(curToken).front())) continue; if (startToken == curToken || coding::CompressedBitVector::IsEmpty(allFeatures)) {