[search] Result feature type string in 'human' format (using categories).

This commit is contained in:
vng 2012-01-26 18:50:55 +03:00 committed by Alex Zolotarev
parent 2888a79f86
commit 668213d39e
6 changed files with 47 additions and 40 deletions

View file

@ -129,7 +129,7 @@ void SearchPanel::OnSearchResult(ResultsT * res, int queryId)
if (e.GetResultType() == ResultT::RESULT_FEATURE)
{
m_pTable->setItem(rowCount, 0,
create_item(QString::fromUtf8(e.GetFetureTypeAsString().c_str())));
create_item(QString::fromUtf8(e.GetFeatureType())));
string strDist;
bool const drawDir = MeasurementUtils::FormatDistance(e.GetDistanceFromCenter(), strDist);

View file

@ -117,7 +117,9 @@ bool IntermediateResult::LessViewportDistance(IntermediateResult const & r1, Int
*/
}
Result IntermediateResult::GenerateFinalResult(storage::CountryInfoGetter const * pInfo) const
Result IntermediateResult::GenerateFinalResult(
storage::CountryInfoGetter const * pInfo,
CategoriesT const * pCat) const
{
storage::CountryInfo info;
m_region.GetRegion(pInfo, info);
@ -129,10 +131,12 @@ Result IntermediateResult::GenerateFinalResult(storage::CountryInfoGetter const
#ifdef DEBUG
+ ' ' + strings::to_string(static_cast<int>(m_searchRank))
#endif
, info.m_name, info.m_flag, m_type, m_rect, m_distance, m_direction);
, info.m_name, info.m_flag, GetFeatureType(pCat),
m_type, m_rect, m_distance, m_direction);
case RESULT_LATLON:
return Result(m_str, info.m_name, info.m_flag, 0, m_rect, m_distance, m_direction);
return Result(m_str, info.m_name, info.m_flag, GetFeatureType(pCat),
0, m_rect, m_distance, m_direction);
default:
ASSERT_EQUAL ( m_resultType, RESULT_CATEGORY, () );
@ -262,6 +266,28 @@ string IntermediateResult::DebugPrint() const
return res;
}
string IntermediateResult::GetFeatureType(CategoriesT const * pCat) const
{
if (pCat)
{
for (CategoriesT::const_iterator i = pCat->begin(); i != pCat->end(); ++i)
{
if (i->second == m_type)
return strings::ToUtf8(i->first);
}
}
string s = classif().GetFullObjectName(m_type);
// remove ending dummy symbol
ASSERT ( !s.empty(), () );
s.resize(s.size()-1);
// replace separator
replace(s.begin(), s.end(), '|', '-');
return s;
}
void IntermediateResult::RegionInfo::GetRegion(
storage::CountryInfoGetter const * pInfo, storage::CountryInfo & info) const
{

View file

@ -1,7 +1,10 @@
#pragma once
#include "result.hpp"
#include "../base/string_utils.hpp"
#include "../std/shared_ptr.hpp"
#include "../std/map.hpp"
class FeatureType;
@ -40,7 +43,9 @@ public:
// For RESULT_CATEGORY.
IntermediateResult(string const & name, int penalty);
Result GenerateFinalResult(storage::CountryInfoGetter const * pInfo) const;
typedef multimap<strings::UniString, uint32_t> CategoriesT;
Result GenerateFinalResult(storage::CountryInfoGetter const * pInfo,
CategoriesT const * pCat) const;
/// Results order functor.
/*
@ -85,6 +90,8 @@ private:
m2::PointD const & featureCenter);
static int ViewportDistance(m2::RectD const & viewport, m2::PointD const & p);
string GetFeatureType(CategoriesT const * pCat) const;
string m_str, m_completionString;
class RegionInfo

View file

@ -1,16 +1,15 @@
#include "result.hpp"
#include "../indexer/classificator.hpp"
namespace search
{
Result::Result(string const & str, string const & region, string const & flag,
Result::Result(string const & str, string const & region,
string const & flag, string const & type,
uint32_t featureType, m2::RectD const & featureRect,
double distanceFromCenter, double directionFromCenter)
: m_str(str), m_region(region), m_flag(flag), m_featureRect(featureRect),
m_featureType(featureType),
: m_str(str), m_region(region), m_flag(flag), m_type(type),
m_featureRect(featureRect), m_featureType(featureType),
m_distanceFromCenter(distanceFromCenter), m_directionFromCenter(directionFromCenter)
{
}
@ -39,29 +38,6 @@ m2::PointD Result::GetFeatureCenter() const
return m_featureRect.Center();
}
uint32_t Result::GetFetureType() const
{
ASSERT_EQUAL(GetResultType(), RESULT_FEATURE, ());
return m_featureType;
}
string Result::GetFetureTypeAsString() const
{
ASSERT_EQUAL(GetResultType(), RESULT_FEATURE, ());
ClassifObject const * p = classif().GetRoot();
uint8_t i = 0;
uint8_t v;
while (ftype::GetValue(m_featureType, i, v) && i < 2)
{
p = p->GetObject(v);
++i;
}
return p->GetName();
}
double Result::GetDistanceFromCenter() const
{
ASSERT_EQUAL(GetResultType(), RESULT_FEATURE, ());

View file

@ -16,7 +16,8 @@ public:
RESULT_SUGGESTION
};
Result(string const & str, string const & region, string const & flag,
Result(string const & str, string const & region,
string const & flag, string const & type,
uint32_t featureType, m2::RectD const & featureRect,
double distanceFromCenter, double directionFromCenter);
Result(string const & str, string const & suggestionStr);
@ -25,6 +26,7 @@ public:
char const * GetString() const { return m_str.c_str(); }
char const * GetRegionString() const { return m_region.c_str(); }
char const * GetRegionFlag() const { return m_flag.c_str(); }
char const * GetFeatureType() const { return m_type.c_str(); }
// Type of the result.
ResultType GetResultType() const;
@ -35,10 +37,6 @@ public:
// Center point of a feature, if GetResultType() == RESULT_FEATURE.
m2::PointD GetFeatureCenter() const;
// Type of a feature, if GetResultType() == RESULT_FEATURE.
uint32_t GetFetureType() const;
string GetFetureTypeAsString() const;
// Distance from the center of the screen, if GetResultType() == RESULT_FEATURE.
double GetDistanceFromCenter() const;
@ -49,7 +47,7 @@ public:
char const * GetSuggestionString() const;
private:
string m_str, m_region, m_flag;
string m_str, m_region, m_flag, m_type;
m2::RectD m_featureRect;
uint32_t m_featureType;
double m_distanceFromCenter;

View file

@ -348,7 +348,7 @@ void Query::FlushResults(Results & res)
for (size_t i = 0; i < indV.size(); ++i)
{
LOG(LDEBUG, (indV[i]));
res.AddResult(indV[i].get()->GenerateFinalResult(m_pInfoGetter));
res.AddResult(indV[i].get()->GenerateFinalResult(m_pInfoGetter, m_pCategories));
}
}