[search] Don't output results without scoring.

This commit is contained in:
Yury Melnichek 2011-06-18 17:43:08 +02:00 committed by Alex Zolotarev
parent 6b10823f98
commit 60ed615cfe
3 changed files with 38 additions and 14 deletions

View file

@ -16,7 +16,7 @@ IntermediateResult::IntermediateResult(m2::RectD const & viewportRect,
int matchPenalty,
int minVisibleScale)
: m_str(displayName), m_rect(feature::GetFeatureViewport(feature)), m_matchPenalty(matchPenalty),
m_minVisibleScale(minVisibleScale)
m_minVisibleScale(minVisibleScale), m_resultType(RESULT_FEATURE)
{
FeatureType::GetTypesFn types;
feature.ForEachTypeRef(types);
@ -26,8 +26,24 @@ IntermediateResult::IntermediateResult(m2::RectD const & viewportRect,
m_direction = ResultDirection(viewportRect.Center(), m_rect.Center());
}
IntermediateResult::IntermediateResult(m2::RectD const & viewportRect,
double lat, double lon, double precision)
: m_str("(" + strings::to_string(lat) + ", " + strings::to_string(lon) + ")"),
m_rect(MercatorBounds::LonToX(lon - precision), MercatorBounds::LatToY(lat - precision),
MercatorBounds::LonToX(lon + precision), MercatorBounds::LatToY(lat + precision)),
m_type(0), m_matchPenalty(0), m_minVisibleScale(0), m_resultType(RESULT_LATLON)
{
m_distance = ResultDistance(viewportRect.Center(), m_rect.Center());
m_direction = ResultDirection(viewportRect.Center(), m_rect.Center());
}
{
}
bool IntermediateResult::operator < (IntermediateResult const & o) const
{
if (m_resultType != o.m_resultType)
return m_resultType < o.m_resultType;
if (m_matchPenalty != o.m_matchPenalty)
return m_matchPenalty < o.m_matchPenalty;
if (m_minVisibleScale != o.m_minVisibleScale)
@ -44,9 +60,15 @@ Result IntermediateResult::GenerateFinalResult() const
// + ' ' + strings::to_string(m_matchPenalty)
// + ' ' + strings::to_string(m_minVisibleScale),
//#else
return Result(m_str,
//#endif
m_type, m_rect, m_distance, m_direction);
switch (m_resultType)
{
case RESULT_FEATURE:
return Result(m_str, m_type, m_rect, m_distance, m_direction);
case RESULT_LATLON:
return Result(m_str, 0, m_rect, m_distance, m_direction);
default:
ASSERT(false, ());
}
}
double IntermediateResult::ResultDistance(m2::PointD const & a, m2::PointD const & b)

View file

@ -10,23 +10,32 @@ namespace impl
class IntermediateResult
{
public:
enum ResultType
{
RESULT_LATLON,
RESULT_FEATURE
};
// For RESULT_FEATURE.
IntermediateResult(m2::RectD const & viewportRect,
FeatureType const & feature,
string const & displayName,
int matchPenalty,
int minVisibleScale);
// For RESULT_LATLON.
IntermediateResult(m2::RectD const & viewportRect, double lat, double lon, double precision);
bool operator < (IntermediateResult const & o) const;
Result GenerateFinalResult() const;
private:
static double ResultDistance(m2::PointD const & viewportCenter,
m2::PointD const & featureCenter);
static double ResultDirection(m2::PointD const & viewportCenter,
m2::PointD const & featureCenter);
private:
string m_str;
m2::RectD m_rect;
uint32_t m_type;
@ -34,6 +43,7 @@ private:
int m_minVisibleScale;
double m_distance;
double m_direction;
ResultType m_resultType;
};
} // namespace search::impl

View file

@ -3,7 +3,6 @@
#include "latlon_match.hpp"
#include "string_match.hpp"
#include "../indexer/feature_visibility.hpp"
#include "../indexer/mercator.hpp"
#include "../base/exception.hpp"
#include "../base/stl_add.hpp"
#include "../std/scoped_ptr.hpp"
@ -123,14 +122,7 @@ void Query::Search(function<void (Result const &)> const & f)
if (search::MatchLatLon(m_queryText, lat, lon, latPrec, lonPrec))
{
double const precision = 5.0 * max(0.0001, min(latPrec, lonPrec)); // Min 55 meters
m2::RectD const rect(MercatorBounds::LonToX(lon - precision),
MercatorBounds::LatToY(lat - precision),
MercatorBounds::LonToX(lon + precision),
MercatorBounds::LatToY(lat + precision));
f(Result("(" + strings::to_string(lat) + ", " + strings::to_string(lon) + ")",
0, rect,
IntermediateResult::ResultDistance(m_viewport.Center(), rect.Center()),
IntermediateResult::ResultDirection(m_viewport.Center(), rect.Center())));
AddResult(IntermediateResult(m_viewport, lat, lon, precision));
}
}