diff --git a/indexer/search_index_builder.cpp b/indexer/search_index_builder.cpp index b6b7f443a3..d88336ee4a 100644 --- a/indexer/search_index_builder.cpp +++ b/indexer/search_index_builder.cpp @@ -227,8 +227,8 @@ public: // 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 : 0, - m_names); + FeatureNameInserter inserter( + skipIndex.IsCountryOrState(types) ? m_synonyms : nullptr, m_names); m_valueBuilder.MakeValue(f, types, index, inserter.m_val); // Skip types for features without names. diff --git a/indexer/types_skipper.cpp b/indexer/types_skipper.cpp index f04173250d..f9403bad38 100644 --- a/indexer/types_skipper.cpp +++ b/indexer/types_skipper.cpp @@ -4,6 +4,7 @@ #include "indexer/feature_data.hpp" #include "indexer/ftypes_matcher.hpp" +#include "std/algorithm.hpp" #include "std/initializer_list.hpp" namespace search @@ -12,21 +13,17 @@ TypesSkipper::TypesSkipper() { Classificator const & c = classif(); - // Fill types that always! should be skipped. for (auto const & e : (StringIL[]){{"entrance"}}) - m_skipF[0].push_back(c.GetTypeByPath(e)); - + m_skipAlways[0].push_back(c.GetTypeByPath(e)); for (auto const & e : (StringIL[]){{"building", "address"}}) - m_skipF[1].push_back(c.GetTypeByPath(e)); + m_skipAlways[1].push_back(c.GetTypeByPath(e)); - // Fill types that never! will be skipped. for (auto const & e : (StringIL[]){{"highway", "bus_stop"}, {"highway", "speed_camera"}}) - m_dontSkipEn.push_back(c.GetTypeByPath(e)); + m_dontSkipIfEmptyName.push_back(c.GetTypeByPath(e)); - // Fill types that will be skipped if feature's name is empty! for (auto const & e : (StringIL[]){{"building"}, {"highway"}, {"natural"}, {"waterway"}, {"landuse"}}) - m_skipEn[0].push_back(c.GetTypeByPath(e)); + m_skipIfEmptyName[0].push_back(c.GetTypeByPath(e)); for (auto const & e : (StringIL[]){{"place", "country"}, {"place", "state"}, @@ -36,7 +33,7 @@ TypesSkipper::TypesSkipper() {"place", "town"}, {"railway", "rail"}}) { - m_skipEn[1].push_back(c.GetTypeByPath(e)); + m_skipIfEmptyName[1].push_back(c.GetTypeByPath(e)); } m_country = c.GetTypeByPath({"place", "country"}); @@ -45,41 +42,41 @@ TypesSkipper::TypesSkipper() void TypesSkipper::SkipTypes(feature::TypesHolder & types) const { - types.RemoveIf([this](uint32_t type) - { - ftype::TruncValue(type, 2); + auto shouldBeRemoved = [this](uint32_t type) + { + ftype::TruncValue(type, 2); + if (HasType(m_skipAlways[1], type)) + return true; - if (HasType(m_skipF[1], type)) - return true; + ftype::TruncValue(type, 1); + if (HasType(m_skipAlways[0], type)) + return true; - ftype::TruncValue(type, 1); + return false; + }; - if (HasType(m_skipF[0], type)) - return true; - - return false; - }); + types.RemoveIf(shouldBeRemoved); } void TypesSkipper::SkipEmptyNameTypes(feature::TypesHolder & types) const { - types.RemoveIf([this](uint32_t type) - { - ftype::TruncValue(type, 2); + auto shouldBeRemoved = [this](uint32_t type) + { + ftype::TruncValue(type, 2); + if (HasType(m_dontSkipIfEmptyName, type)) + return false; - if (HasType(m_dontSkipEn, type)) - return false; + if (HasType(m_skipIfEmptyName[1], type)) + return true; - if (HasType(m_skipEn[1], type)) - return true; + ftype::TruncValue(type, 1); + if (HasType(m_skipIfEmptyName[0], type)) + return true; - ftype::TruncValue(type, 1); + return false; + }; - if (HasType(m_skipEn[0], type)) - return true; - - return false; - }); + types.RemoveIf(shouldBeRemoved); } bool TypesSkipper::IsCountryOrState(feature::TypesHolder const & types) const diff --git a/indexer/types_skipper.hpp b/indexer/types_skipper.hpp index f0dbe26d2a..a4ae75a7a9 100644 --- a/indexer/types_skipper.hpp +++ b/indexer/types_skipper.hpp @@ -9,10 +9,9 @@ class TypesHolder; namespace search { -/// There are 3 different ways of search index skipping: -/// - skip features in any case (m_skipFeatures) -/// - skip features with empty names (m_enFeature) -/// - skip specified types for features with empty names (m_enTypes) +// There are 2 different ways of search index skipping: +// 1. Skip some feature's types. +// 2. Skip some feature's types when feature name is empty. class TypesSkipper { public: @@ -30,9 +29,13 @@ private: static bool HasType(TCont const & v, uint32_t t); // Array index (0, 1) means type level for checking (1, 2). - TCont m_skipEn[2]; - TCont m_skipF[2]; - TCont m_dontSkipEn; + // m_skipAlways is used in the case 1 described above. + TCont m_skipAlways[2]; + + // m_skipIfEmptyName and m_dontSkipIfEmptyName are used in the case 2 described above. + TCont m_skipIfEmptyName[2]; + TCont m_dontSkipIfEmptyName; + uint32_t m_country, m_state; }; } // namespace search