From ddb6fc5115554b69d9ef2440ab605cc67dbf7ac1 Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Thu, 19 Oct 2017 10:16:45 +0300 Subject: [PATCH] [ugc] separate container for excluded types is added --- indexer/ftraits.hpp | 19 +++++++++++++++---- indexer/ftypes_mapping.hpp | 13 +------------ indexer/indexer_tests/ugc_types_test.cpp | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/indexer/ftraits.hpp b/indexer/ftraits.hpp index a7c05c0d42..7900f43afc 100644 --- a/indexer/ftraits.hpp +++ b/indexer/ftraits.hpp @@ -19,13 +19,18 @@ namespace ftraits { -template +template class TraitsBase { public: static Value GetValue(feature::TypesHolder const & types) { static Base instance; + + auto const excluded = instance.m_excluded.Find(types); + if (instance.m_excluded.IsValid(excluded)) + return Base::GetEmptyValue(); + auto const it = instance.m_matcher.Find(types); if (!instance.m_matcher.IsValid(it)) return Base::GetEmptyValue(); @@ -34,7 +39,8 @@ public: } protected: - ftypes::Matcher, allowDuplications> m_matcher; + ftypes::HashMapMatcher m_matcher; + ftypes::HashSetMatcher m_excluded; }; enum UGCType @@ -60,7 +66,7 @@ struct UGCItem UGCRatingCategories m_categories; }; -class UGC : public TraitsBase +class UGC : public TraitsBase { friend class TraitsBase; @@ -77,7 +83,12 @@ class UGC : public TraitsBase ASSERT_EQUAL(row.size(), 5, ()); UGCItem item(ReadMasks(row), ParseByWhitespaces(row[kCategoriesPos])); - m_matcher.AppendType(ParseByWhitespaces(row[kTypePos]), std::move(item)); + auto typePath = ParseByWhitespaces(row[kTypePos]); + + if (IsUGCAvailable(item.m_mask)) + m_matcher.AppendType(std::move(typePath), std::move(item)); + else + m_excluded.AppendType(std::move(typePath)); }); } diff --git a/indexer/ftypes_mapping.hpp b/indexer/ftypes_mapping.hpp index 7b28bf1716..346dd48f51 100644 --- a/indexer/ftypes_mapping.hpp +++ b/indexer/ftypes_mapping.hpp @@ -11,10 +11,7 @@ namespace ftypes { -// When [allowDuplications] is true then we are support duplications in ierarchy, -// for ex. shop and shop-alcohol. shop-alcohol is duplicaton of shop, because shop contains -// shop-alcohol. -template +template class Matcher { public: @@ -50,14 +47,6 @@ public: template void AppendType(Type && type, Args &&... args) { -#if defined(DEBUG) - if (!allowDuplications) - { - feature::TypesHolder holder; - holder.Assign(classif().GetTypeByPath(type)); - ASSERT(Find(holder) == m_mapping.cend(), ("This type already exists", type)); - } -#endif m_mapping.emplace(classif().GetTypeByPath(std::forward(type)), std::forward(args)...); } diff --git a/indexer/indexer_tests/ugc_types_test.cpp b/indexer/indexer_tests/ugc_types_test.cpp index d1016631ec..12e7492809 100644 --- a/indexer/indexer_tests/ugc_types_test.cpp +++ b/indexer/indexer_tests/ugc_types_test.cpp @@ -51,5 +51,21 @@ UNIT_TEST(UgcTypes_Full) TEST(!UGC::IsDetailsAvailable(holder), ()); ftraits::UGCRatingCategories expected = {}; TEST_EQUAL(UGC::GetCategories(holder), expected, ()); + + holder.Assign(c.GetTypeByPath({"sponsored", "booking"})); + holder.Add(c.GetTypeByPath({"amenity", "hospital"})); + TEST(!UGC::IsUGCAvailable(holder), ()); + TEST(!UGC::IsRatingAvailable(holder), ()); + TEST(!UGC::IsReviewsAvailable(holder), ()); + TEST(!UGC::IsDetailsAvailable(holder), ()); + TEST_EQUAL(UGC::GetCategories(holder), expected, ()); + + holder.Assign(c.GetTypeByPath({"amenity", "hospital"})); + holder.Add(c.GetTypeByPath({"sponsored", "booking"})); + TEST(!UGC::IsUGCAvailable(holder), ()); + TEST(!UGC::IsRatingAvailable(holder), ()); + TEST(!UGC::IsReviewsAvailable(holder), ()); + TEST(!UGC::IsDetailsAvailable(holder), ()); + TEST_EQUAL(UGC::GetCategories(holder), expected, ()); } }