[search] Added "category" bit to trace parses.

This commit is contained in:
Yuri Gorshenin 2017-11-14 16:06:31 +03:00 committed by burivuh
parent 3a3124df69
commit b26255d196
7 changed files with 64 additions and 18 deletions

View file

@ -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.
//

View file

@ -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<hotels_filter::Rule> m_hotelsFilter;
bool m_cianMode = false;
set<uint32_t> 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;

View file

@ -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<my::Cancellable const &>(*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<my::Cancellable const &>(*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;

View file

@ -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"

View file

@ -53,9 +53,10 @@ UNIT_CLASS_TEST(TracerTest, Smoke)
auto const actual = tracer->GetUniqueParses();
vector<Tracer::Parse> 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, ());
}

View file

@ -10,7 +10,7 @@ using namespace std;
namespace search
{
// Tracer::Parse -----------------------------------------------------------------------------------
Tracer::Parse::Parse(vector<TokenType> const & types)
Tracer::Parse::Parse(vector<TokenType> const & types, bool category) : m_category(category)
{
size_t i = 0;
while (i != types.size())
@ -24,7 +24,8 @@ Tracer::Parse::Parse(vector<TokenType> const & types)
}
}
Tracer::Parse::Parse(vector<pair<TokenType, TokenRange>> const & ranges)
Tracer::Parse::Parse(vector<pair<TokenType, TokenRange>> 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();
}

View file

@ -17,13 +17,24 @@ public:
{
using TokenType = BaseContext::TokenType;
explicit Parse(std::vector<TokenType> const & types);
explicit Parse(std::vector<std::pair<TokenType, TokenRange>> const & ranges);
explicit Parse(std::vector<TokenType> const & types, bool category = false);
explicit Parse(std::vector<std::pair<TokenType, TokenRange>> 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<TokenRange, TokenType::TOKEN_TYPE_COUNT> m_ranges;
bool m_category = false;
};
template <typename ...Args>