forked from organicmaps/organicmaps
Improve search results ranking
This commit is contained in:
parent
05cfea194d
commit
a3d9b6b30b
3 changed files with 60 additions and 9 deletions
|
@ -61,6 +61,8 @@ public:
|
|||
/// Read and fill needed info for ranking and getting final results.
|
||||
class PreResult2
|
||||
{
|
||||
friend class PreResult2Maker;
|
||||
|
||||
void CalcParams(m2::RectD const & viewport, m2::PointD const & pos);
|
||||
|
||||
public:
|
||||
|
@ -163,7 +165,7 @@ private:
|
|||
|
||||
double m_distance, m_distanceFromViewportCenter;
|
||||
ResultType m_resultType;
|
||||
uint8_t m_rank;
|
||||
uint16_t m_rank;
|
||||
uint8_t m_viewportDistance;
|
||||
feature::EGeomType m_geomType;
|
||||
};
|
||||
|
|
|
@ -178,6 +178,24 @@ void Query::SetViewportByIndex(MWMVectorT const & mwmInfo, m2::RectD const & vie
|
|||
}
|
||||
}
|
||||
|
||||
void Query::SetPosition(m2::PointD const & pos)
|
||||
{
|
||||
if (!m2::AlmostEqual(pos, m_position))
|
||||
{
|
||||
storage::CountryInfo ci;
|
||||
m_pInfoGetter->GetRegionInfo(pos, ci);
|
||||
m_region.swap(ci.m_name);
|
||||
}
|
||||
|
||||
m_position = pos;
|
||||
}
|
||||
|
||||
void Query::NullPosition()
|
||||
{
|
||||
m_position = m2::PointD(empty_pos_value, empty_pos_value);
|
||||
m_region.clear();
|
||||
}
|
||||
|
||||
void Query::SetPreferredLanguage(string const & lang)
|
||||
{
|
||||
int8_t const code = StringUtf8Multilang::GetLangIndex(lang);
|
||||
|
@ -537,9 +555,38 @@ namespace impl
|
|||
LoadFeature(res.GetID(), feature, name, country);
|
||||
|
||||
Query::ViewportID const viewportID = static_cast<Query::ViewportID>(res.GetViewportID());
|
||||
return new impl::PreResult2(feature, &res,
|
||||
m_query.GetViewport(viewportID), m_query.GetPosition(viewportID),
|
||||
name, country);
|
||||
impl::PreResult2 * res2 = new impl::PreResult2(feature, &res,
|
||||
m_query.GetViewport(viewportID), m_query.GetPosition(viewportID),
|
||||
name, country);
|
||||
|
||||
/// @todo: add exluding of states (without USA states), continents
|
||||
using namespace ftypes;
|
||||
Type const tp = IsLocalityChecker::Instance().GetType(res2->m_types);
|
||||
switch (tp)
|
||||
{
|
||||
case COUNTRY:
|
||||
res2->m_rank /= 1.5;
|
||||
break;
|
||||
case CITY:
|
||||
case TOWN:
|
||||
if (m_query.GetViewport(Query::CURRENT_V).IsPointInside(res2->GetCenter()))
|
||||
res2->m_rank *= 2;
|
||||
else
|
||||
{
|
||||
storage::CountryInfo ci;
|
||||
res2->m_region.GetRegion(m_query.m_pInfoGetter, ci);
|
||||
if (ci.m_name == m_query.GetPositionRegion())
|
||||
res2->m_rank *= 1.7;
|
||||
}
|
||||
break;
|
||||
case VILLAGE:
|
||||
res2->m_rank /= 1.5;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return res2;
|
||||
}
|
||||
|
||||
impl::PreResult2 * operator() (FeatureID const & id)
|
||||
|
@ -664,11 +711,11 @@ void Query::FlushHouses(Results & res, bool allMWMs, vector<FeatureID> const & s
|
|||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
House const * h = houses[i].m_house;
|
||||
storage::CountryInfo countryInfo;
|
||||
m_pInfoGetter->GetRegionInfo(h->GetPosition(), countryInfo);
|
||||
storage::CountryInfo ci;
|
||||
m_pInfoGetter->GetRegionInfo(h->GetPosition(), ci);
|
||||
|
||||
Result r(h->GetPosition(), h->GetNumber() + ", " + houses[i].m_street->GetName(),
|
||||
countryInfo.m_name, string(), IsValidPosition() ? h->GetPosition().Length(m_position) : -1.0);
|
||||
ci.m_name, string(), IsValidPosition() ? h->GetPosition().Length(m_position) : -1.0);
|
||||
|
||||
MakeResultHighlight(r);
|
||||
#ifdef FIND_LOCALITY_TEST
|
||||
|
|
|
@ -84,8 +84,9 @@ public:
|
|||
void SetViewport(m2::RectD viewport[], size_t count);
|
||||
|
||||
static const int empty_pos_value = -1000;
|
||||
inline void SetPosition(m2::PointD const & pos) { m_position = pos; }
|
||||
inline void NullPosition() { m_position = m2::PointD(empty_pos_value, empty_pos_value); }
|
||||
void SetPosition(m2::PointD const & pos);
|
||||
void NullPosition();
|
||||
inline string const & GetPositionRegion() const { return m_region; }
|
||||
|
||||
inline void SetSearchInWorld(bool b) { m_worldSearch = b; }
|
||||
inline void SetSortByViewport(bool b) { m_sortByViewport = b; }
|
||||
|
@ -220,6 +221,7 @@ private:
|
|||
|
||||
volatile bool m_cancel;
|
||||
|
||||
string m_region;
|
||||
string const * m_query;
|
||||
buffer_vector<strings::UniString, 32> m_tokens;
|
||||
strings::UniString m_prefix;
|
||||
|
|
Loading…
Add table
Reference in a new issue