[search] Add GetCategoryTypes helper for Discovery

This commit is contained in:
tatiana-yan 2018-07-17 17:26:34 +03:00 committed by mpimenov
parent be9d13f61b
commit cffa89885a
3 changed files with 26 additions and 3 deletions

View file

@ -503,7 +503,7 @@ void Processor::InitParams(QueryParams & params) const
params.GetTypeIndices(i).push_back(index);
};
auto const tokenSlice = QuerySliceOnRawStrings<decltype(m_tokens)>(m_tokens, m_prefix);
vector<uint32_t> types;
set<uint32_t> types;
bool const isCategorialRequest =
FillCategories(tokenSlice, GetCategoryLocales(), m_categories, types);
params.SetCategorialRequest(isCategorialRequest);

View file

@ -48,6 +48,24 @@ strings::LevenshteinDFA BuildLevenshteinDFA(strings::UniString const & s)
return strings::LevenshteinDFA(s, 1 /* prefixSize */, kAllowedMisprints, GetMaxErrorsForToken(s));
}
set<uint32_t> GetCategoryTypes(string const & name, string const & locale,
CategoriesHolder const & categories)
{
set<uint32_t> types;
int8_t const code = CategoriesHolder::MapLocaleToInteger(locale);
Locales locales;
locales.Insert(static_cast<uint64_t>(code));
vector<strings::UniString> tokens;
SplitUniString(search::NormalizeAndSimplifyString(name), MakeBackInsertFunctor(tokens),
search::Delimiters());
FillCategories(QuerySliceOnRawStrings<vector<strings::UniString>>(tokens, {} /* prefix */),
locales, categories, types);
return types;
}
MwmSet::MwmHandle FindWorld(DataSource const & dataSource,
vector<shared_ptr<MwmInfo>> const & infos)
{

View file

@ -88,7 +88,7 @@ void ForEachCategoryTypeFuzzy(StringSliceBase const & slice, Locales const & loc
// and a space after it means that no errors were made.
template <typename T>
bool FillCategories(QuerySliceOnRawStrings<T> const & slice, Locales const & locales,
CategoriesHolder const & catHolder, std::vector<uint32_t> & types)
CategoriesHolder const & catHolder, std::set<uint32_t> & types)
{
types.clear();
if (slice.HasPrefixToken())
@ -112,12 +112,17 @@ bool FillCategories(QuerySliceOnRawStrings<T> const & slice, Locales const & loc
return;
}
types.push_back(type);
types.insert(type);
});
return !types.empty();
}
// Returns set of classificator types for category with |name| and |locale|. For metacategories
// like "Hotel" returns all subcategories types.
std::set<uint32_t> GetCategoryTypes(std::string const & name, std::string const & locale,
CategoriesHolder const & categories);
MwmSet::MwmHandle FindWorld(DataSource const & dataSource,
std::vector<std::shared_ptr<MwmInfo>> const & infos);
MwmSet::MwmHandle FindWorld(DataSource const & dataSource);