From b26255d19634beb06555f55328e7a456ab0a1cad Mon Sep 17 00:00:00 2001 From: Yuri Gorshenin Date: Tue, 14 Nov 2017 16:06:31 +0300 Subject: [PATCH] [search] Added "category" bit to trace parses. --- search/geocoder.cpp | 30 +++++++++++++++++-- search/geocoder.hpp | 14 +++++---- search/processor.cpp | 3 +- search/processor.hpp | 2 ++ .../search_integration_tests/tracer_tests.cpp | 5 ++-- search/tracer.cpp | 9 ++++-- search/tracer.hpp | 19 +++++++++--- 7 files changed, 64 insertions(+), 18 deletions(-) diff --git a/search/geocoder.cpp b/search/geocoder.cpp index 0d4255bf96..5ad19b3c98 100644 --- a/search/geocoder.cpp +++ b/search/geocoder.cpp @@ -334,10 +334,11 @@ CBV DecimateCianResults(CBV const & cbv) // Geocoder::Geocoder ------------------------------------------------------------------------------ Geocoder::Geocoder(Index const & index, storage::CountryInfoGetter const & infoGetter, - PreRanker & preRanker, VillagesCache & villagesCache, - my::Cancellable const & cancellable) + CategoriesHolder const & categories, PreRanker & preRanker, + VillagesCache & villagesCache, my::Cancellable const & cancellable) : m_index(index) , m_infoGetter(infoGetter) + , m_categories(categories) , m_streetsCache(cancellable) , m_villagesCache(villagesCache) , m_hotelsCache(cancellable) @@ -1279,6 +1280,29 @@ void Geocoder::FindPaths(BaseContext const & ctx) }); } +void Geocoder::TraceResult(Tracer & tracer, BaseContext const & ctx, MwmSet::MwmId const & mwmId, + uint32_t ftId, Model::Type type, TokenRange const & tokenRange) +{ + MY_SCOPE_GUARD(emitParse, [&]() { tracer.EmitParse(ctx.m_tokens); }); + + if (type != Model::TYPE_POI && type != Model::TYPE_BUILDING) + return; + + if (mwmId != m_context->GetId()) + return; + + FeatureType ft; + if (!m_context->GetFeature(ftId, ft)) + return; + + feature::TypesHolder holder(ft); + CategoriesInfo catInfo(holder, TokenSlice(m_params, tokenRange), m_params.m_categoryLocales, + m_categories); + + emitParse.release(); + tracer.EmitParse(ctx.m_tokens, catInfo.IsPureCategories()); +} + void Geocoder::EmitResult(BaseContext const & ctx, MwmSet::MwmId const & mwmId, uint32_t ftId, Model::Type type, TokenRange const & tokenRange, IntersectionResult const * geoParts) @@ -1292,7 +1316,7 @@ void Geocoder::EmitResult(BaseContext const & ctx, MwmSet::MwmId const & mwmId, return; if (m_params.m_tracer) - m_params.m_tracer->EmitParse(ctx.m_tokens); + TraceResult(*m_params.m_tracer, ctx, mwmId, ftId, type, tokenRange); // Distance and rank will be filled at the end, for all results at once. // diff --git a/search/geocoder.hpp b/search/geocoder.hpp index fdd1f19b67..982037ae3e 100644 --- a/search/geocoder.hpp +++ b/search/geocoder.hpp @@ -20,7 +20,6 @@ #include "search/streets_matcher.hpp" #include "search/token_range.hpp" -#include "indexer/index.hpp" #include "indexer/mwm_set.hpp" #include "storage/country_info_getter.hpp" @@ -43,7 +42,8 @@ #include "std/unordered_map.hpp" #include "std/vector.hpp" -class MwmInfo; +class CategoriesHolder; +class Index; class MwmValue; namespace storage @@ -81,6 +81,7 @@ public: { Mode m_mode = Mode::Everywhere; m2::RectD m_pivot; + Locales m_categoryLocales; shared_ptr m_hotelsFilter; bool m_cianMode = false; set m_preferredTypes; @@ -88,8 +89,8 @@ public: }; Geocoder(Index const & index, storage::CountryInfoGetter const & infoGetter, - PreRanker & preRanker, VillagesCache & villagesCache, - my::Cancellable const & cancellable); + CategoriesHolder const & categories, PreRanker & preRanker, + VillagesCache & villagesCache, my::Cancellable const & cancellable); ~Geocoder(); // Sets search query params. @@ -198,6 +199,9 @@ private: // the lowest layer. void FindPaths(BaseContext const & ctx); + void TraceResult(Tracer & tracer, BaseContext const & ctx, MwmSet::MwmId const & mwmId, + uint32_t ftId, Model::Type type, TokenRange const & tokenRange); + // Forms result and feeds it to |m_preRanker|. void EmitResult(BaseContext const & ctx, MwmSet::MwmId const & mwmId, uint32_t ftId, Model::Type type, TokenRange const & tokenRange, @@ -222,8 +226,8 @@ private: Model::Type & type); Index const & m_index; - storage::CountryInfoGetter const & m_infoGetter; + CategoriesHolder const & m_categories; StreetsCache m_streetsCache; VillagesCache & m_villagesCache; diff --git a/search/processor.cpp b/search/processor.cpp index 7eeeea52d4..4288aa1533 100644 --- a/search/processor.cpp +++ b/search/processor.cpp @@ -173,7 +173,7 @@ Processor::Processor(Index const & index, CategoriesHolder const & categories, , m_ranker(index, m_citiesBoundaries, infoGetter, m_keywordsScorer, m_emitter, categories, suggests, m_villagesCache, static_cast(*this)) , m_preRanker(index, m_ranker) - , m_geocoder(index, infoGetter, m_preRanker, m_villagesCache, + , m_geocoder(index, infoGetter, categories, m_preRanker, m_villagesCache, static_cast(*this)) { // Current and input langs are to be set later. @@ -488,6 +488,7 @@ void Processor::InitGeocoder(Geocoder::Params & geocoderParams, SearchParams con geocoderParams.m_mode = searchParams.m_mode; geocoderParams.m_pivot = GetPivotRect(viewportSearch); + geocoderParams.m_categoryLocales = GetCategoryLocales(); geocoderParams.m_hotelsFilter = searchParams.m_hotelsFilter; geocoderParams.m_cianMode = searchParams.m_cianMode; geocoderParams.m_preferredTypes = m_preferredTypes; diff --git a/search/processor.hpp b/search/processor.hpp index 473b8df54e..83a3ea6067 100644 --- a/search/processor.hpp +++ b/search/processor.hpp @@ -1,7 +1,9 @@ #pragma once + #include "search/categories_cache.hpp" #include "search/categories_set.hpp" #include "search/cities_boundaries_table.hpp" +#include "search/common.hpp" #include "search/emitter.hpp" #include "search/geocoder.hpp" #include "search/pre_ranker.hpp" diff --git a/search/search_integration_tests/tracer_tests.cpp b/search/search_integration_tests/tracer_tests.cpp index c2df6857b8..902279e9d7 100644 --- a/search/search_integration_tests/tracer_tests.cpp +++ b/search/search_integration_tests/tracer_tests.cpp @@ -53,9 +53,10 @@ UNIT_CLASS_TEST(TracerTest, Smoke) auto const actual = tracer->GetUniqueParses(); vector const expected{ - Tracer::Parse{{{TokenType::TOKEN_TYPE_POI, TokenRange(0, 2)}}}, + Tracer::Parse{{{TokenType::TOKEN_TYPE_POI, TokenRange(0, 2)}}, false /* category */}, Tracer::Parse{{{TokenType::TOKEN_TYPE_CITY, TokenRange(0, 1)}, - {TokenType::TOKEN_TYPE_POI, TokenRange(1, 2)}}}}; + {TokenType::TOKEN_TYPE_POI, TokenRange(1, 2)}}, + true /* category */}}; TEST_EQUAL(expected, actual, ()); } diff --git a/search/tracer.cpp b/search/tracer.cpp index e9058374ec..07129c16a5 100644 --- a/search/tracer.cpp +++ b/search/tracer.cpp @@ -10,7 +10,7 @@ using namespace std; namespace search { // Tracer::Parse ----------------------------------------------------------------------------------- -Tracer::Parse::Parse(vector const & types) +Tracer::Parse::Parse(vector const & types, bool category) : m_category(category) { size_t i = 0; while (i != types.size()) @@ -24,7 +24,8 @@ Tracer::Parse::Parse(vector const & types) } } -Tracer::Parse::Parse(vector> const & ranges) +Tracer::Parse::Parse(vector> const & ranges, bool category) + : m_category(category) { for (auto const & kv : ranges) m_ranges[kv.first] = kv.second; @@ -35,7 +36,7 @@ string DebugPrint(Tracer::Parse const & parse) using TokenType = Tracer::Parse::TokenType; ostringstream os; - os << "Parse ["; + os << "Parse [parse: "; bool first = true; for (size_t i = 0; i < TokenType::TOKEN_TYPE_COUNT; ++i) @@ -51,7 +52,9 @@ string DebugPrint(Tracer::Parse const & parse) first = false; } + os << ", category: " << ::DebugPrint(parse.m_category); os << "]"; + return os.str(); } diff --git a/search/tracer.hpp b/search/tracer.hpp index 887422014a..f92e7b1037 100644 --- a/search/tracer.hpp +++ b/search/tracer.hpp @@ -17,13 +17,24 @@ public: { using TokenType = BaseContext::TokenType; - explicit Parse(std::vector const & types); - explicit Parse(std::vector> const & ranges); + explicit Parse(std::vector const & types, bool category = false); + explicit Parse(std::vector> const & ranges, + bool category = false); - bool operator==(Parse const & rhs) const { return m_ranges == rhs.m_ranges; } - bool operator<(Parse const & rhs) const { return m_ranges < rhs.m_ranges; } + bool operator==(Parse const & rhs) const + { + return m_ranges == rhs.m_ranges && m_category == rhs.m_category; + } + + bool operator<(Parse const & rhs) const + { + if (m_ranges != rhs.m_ranges) + return m_ranges < rhs.m_ranges; + return m_category < rhs.m_category; + } std::array m_ranges; + bool m_category = false; }; template