From 60ed615cfe5bcfdade85409dd92f68a25857fc10 Mon Sep 17 00:00:00 2001 From: Yury Melnichek Date: Sat, 18 Jun 2011 17:43:08 +0200 Subject: [PATCH] [search] Don't output results without scoring. --- search/intermediate_result.cpp | 30 ++++++++++++++++++++++++++---- search/intermediate_result.hpp | 12 +++++++++++- search/query.cpp | 10 +--------- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/search/intermediate_result.cpp b/search/intermediate_result.cpp index b5afe469ab..16d9836616 100644 --- a/search/intermediate_result.cpp +++ b/search/intermediate_result.cpp @@ -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) diff --git a/search/intermediate_result.hpp b/search/intermediate_result.hpp index 01a1617e95..360248d3ba 100644 --- a/search/intermediate_result.hpp +++ b/search/intermediate_result.hpp @@ -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 diff --git a/search/query.cpp b/search/query.cpp index de776c5e35..1698ef9676 100644 --- a/search/query.cpp +++ b/search/query.cpp @@ -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 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)); } }