forked from organicmaps/organicmaps
[search] Show best preffered type when matching by category.
This commit is contained in:
parent
a869ba903c
commit
a5f3dfb496
4 changed files with 51 additions and 13 deletions
|
@ -217,7 +217,9 @@ namespace
|
|||
|
||||
Result PreResult2::GenerateFinalResult(
|
||||
storage::CountryInfoGetter const * pInfo,
|
||||
CategoriesHolder const * pCat, int8_t lang) const
|
||||
CategoriesHolder const * pCat,
|
||||
set<uint32_t> const * pTypes,
|
||||
int8_t lang) const
|
||||
{
|
||||
storage::CountryInfo info;
|
||||
|
||||
|
@ -235,7 +237,7 @@ Result PreResult2::GenerateFinalResult(
|
|||
switch (m_resultType)
|
||||
{
|
||||
case RESULT_FEATURE:
|
||||
return Result(m_str, info.m_name, info.m_flag, GetFeatureType(pCat, lang)
|
||||
return Result(m_str, info.m_name, info.m_flag, GetFeatureType(pCat, pTypes, lang)
|
||||
#ifdef DEBUG
|
||||
+ ' ' + strings::to_string(static_cast<int>(m_rank))
|
||||
#endif
|
||||
|
@ -357,20 +359,34 @@ string PreResult2::DebugPrint() const
|
|||
return res;
|
||||
}
|
||||
|
||||
uint32_t PreResult2::GetBestType() const
|
||||
uint32_t PreResult2::GetBestType(set<uint32_t> const * pPrefferedTypes) const
|
||||
{
|
||||
/// @todo Need to process all types.
|
||||
uint32_t t = 0;
|
||||
|
||||
if (pPrefferedTypes)
|
||||
{
|
||||
for (size_t i = 0; i < m_types.Size(); ++i)
|
||||
if (pPrefferedTypes->count(m_types[i]) > 0)
|
||||
{
|
||||
t = m_types[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (t == 0)
|
||||
t = m_types.GetBestType();
|
||||
|
||||
uint32_t t = m_types.GetBestType();
|
||||
ftype::TruncValue(t, 2);
|
||||
return t;
|
||||
}
|
||||
|
||||
string PreResult2::GetFeatureType(CategoriesHolder const * pCat, int8_t lang) const
|
||||
string PreResult2::GetFeatureType(CategoriesHolder const * pCat,
|
||||
set<uint32_t> const * pTypes,
|
||||
int8_t lang) const
|
||||
{
|
||||
ASSERT_EQUAL(m_resultType, RESULT_FEATURE, ());
|
||||
|
||||
uint32_t const type = GetBestType();
|
||||
uint32_t const type = GetBestType(pTypes);
|
||||
ASSERT_NOT_EQUAL(type, 0, ());
|
||||
|
||||
if (pCat)
|
||||
|
|
|
@ -78,8 +78,14 @@ public:
|
|||
// For RESULT_CATEGORY.
|
||||
PreResult2(string const & name, int penalty);
|
||||
|
||||
/// @param[in] pInfo Need to get region for result.
|
||||
/// @param[in] pCat Categories need to display readable type string.
|
||||
/// @param[in] pTypes Set of preffered types that match input tokens by categories.
|
||||
/// @param[in] lang Current system language.
|
||||
Result GenerateFinalResult(storage::CountryInfoGetter const * pInfo,
|
||||
CategoriesHolder const * pCat, int8_t lang) const;
|
||||
CategoriesHolder const * pCat,
|
||||
set<uint32_t> const * pTypes,
|
||||
int8_t lang) const;
|
||||
|
||||
static bool LessRank(PreResult2 const & r1, PreResult2 const & r2);
|
||||
static bool LessDistance(PreResult2 const & r1, PreResult2 const & r2);
|
||||
|
@ -114,11 +120,13 @@ private:
|
|||
template <class T> friend bool LessViewportDistanceT(T const & r1, T const & r2);
|
||||
template <class T> friend bool LessDistanceT(T const & r1, T const & r2);
|
||||
|
||||
string GetFeatureType(CategoriesHolder const * pCat, int8_t lang) const;
|
||||
string GetFeatureType(CategoriesHolder const * pCat,
|
||||
set<uint32_t> const * pTypes,
|
||||
int8_t lang) const;
|
||||
m2::RectD GetFinalViewport() const;
|
||||
|
||||
feature::TypesHolder m_types;
|
||||
uint32_t GetBestType() const;
|
||||
uint32_t GetBestType(set<uint32_t> const * pPrefferedTypes = 0) const;
|
||||
|
||||
string m_str, m_completionString;
|
||||
|
||||
|
|
|
@ -474,6 +474,9 @@ void Query::FlushResults(Results & res, void (Results::*pAddFn)(Result const &))
|
|||
AddPreResult2(maker(*i), indV);
|
||||
}
|
||||
|
||||
if (indV.empty())
|
||||
return;
|
||||
|
||||
RemoveDuplicatingLinear(indV);
|
||||
|
||||
for (size_t i = 0; i < m_qCount; ++i)
|
||||
|
@ -500,6 +503,17 @@ void Query::FlushResults(Results & res, void (Results::*pAddFn)(Result const &))
|
|||
// sort results according to combined criteria
|
||||
sort(indV.begin(), indV.end());
|
||||
|
||||
// get preffered types to show in results
|
||||
set<uint32_t> prefferedTypes;
|
||||
if (m_pCategories)
|
||||
{
|
||||
for (size_t i = 0; i < m_tokens.size(); ++i)
|
||||
m_pCategories->ForEachTypeByName(m_tokens[i], MakeInsertFunctor(prefferedTypes));
|
||||
|
||||
if (!m_prefix.empty())
|
||||
m_pCategories->ForEachTypeByName(m_prefix, MakeInsertFunctor(prefferedTypes));
|
||||
}
|
||||
|
||||
// emit feature results
|
||||
for (size_t i = 0; i < indV.size(); ++i)
|
||||
{
|
||||
|
@ -507,7 +521,7 @@ void Query::FlushResults(Results & res, void (Results::*pAddFn)(Result const &))
|
|||
|
||||
LOG(LDEBUG, (indV[i]));
|
||||
|
||||
(res.*pAddFn)(MakeResult(*(indV[i])));
|
||||
(res.*pAddFn)(MakeResult(*(indV[i]), &prefferedTypes));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -131,9 +131,9 @@ private:
|
|||
|
||||
void GetBestMatchName(FeatureType const & f, uint32_t & penalty, string & name);
|
||||
|
||||
inline Result MakeResult(impl::PreResult2 const & r) const
|
||||
inline Result MakeResult(impl::PreResult2 const & r, set<uint32_t> const * pPrefferedTypes = 0) const
|
||||
{
|
||||
return r.GenerateFinalResult(m_pInfoGetter, m_pCategories, m_currentLang);
|
||||
return r.GenerateFinalResult(m_pInfoGetter, m_pCategories, pPrefferedTypes, m_currentLang);
|
||||
}
|
||||
|
||||
Index const * m_pIndex;
|
||||
|
|
Loading…
Add table
Reference in a new issue