From 0a8877c276055d0e6f9eba05b0ecb8935ce376af Mon Sep 17 00:00:00 2001 From: Yuri Gorshenin Date: Fri, 10 Nov 2017 16:36:12 +0300 Subject: [PATCH] Review fixes. --- search/ranker.cpp | 12 +++++++----- search/ranker.hpp | 34 +++++++++++++++++++--------------- search/ranking_info.cpp | 9 +++++---- search/ranking_info.hpp | 12 ++++++++---- search/ranking_utils.cpp | 1 + search/ranking_utils.hpp | 6 +++--- 6 files changed, 43 insertions(+), 31 deletions(-) diff --git a/search/ranker.cpp b/search/ranker.cpp index e12ec673cb..e99420b16e 100644 --- a/search/ranker.cpp +++ b/search/ranker.cpp @@ -12,12 +12,14 @@ #include "base/logging.hpp" #include "base/string_utils.hpp" -#include "std/algorithm.hpp" -#include "std/iterator.hpp" -#include "std/unique_ptr.hpp" +#include +#include +#include #include +using namespace std; + namespace search { namespace @@ -31,7 +33,7 @@ struct NameScores template void UpdateNameScores(string const & name, TSlice const & slice, NameScores & bestScores) { - bestScores.m_nameScore = std::max(bestScores.m_nameScore, GetNameScore(name, slice)); + bestScores.m_nameScore = max(bestScores.m_nameScore, GetNameScore(name, slice)); bestScores.m_errorsMade = ErrorsMade::Min(bestScores.m_errorsMade, GetErrorsMade(name, slice)); } @@ -39,7 +41,7 @@ template void UpdateNameScores(vector const & tokens, TSlice const & slice, NameScores & bestScores) { - bestScores.m_nameScore = std::max(bestScores.m_nameScore, GetNameScore(tokens, slice)); + bestScores.m_nameScore = max(bestScores.m_nameScore, GetNameScore(tokens, slice)); bestScores.m_errorsMade = ErrorsMade::Min(bestScores.m_errorsMade, GetErrorsMade(tokens, slice)); } diff --git a/search/ranker.hpp b/search/ranker.hpp index 0587a241ae..82ab379ea8 100644 --- a/search/ranker.hpp +++ b/search/ranker.hpp @@ -20,6 +20,7 @@ #include "base/string_utils.hpp" +#include #include #include #include @@ -50,13 +51,13 @@ public: m2::RectD m_viewport; m2::PointD m_position; string m_pivotRegion; - set m_preferredTypes; + std::set m_preferredTypes; bool m_suggestsEnabled = false; bool m_needAddress = false; bool m_needHighlighting = false; bool m_viewportSearch = false; - string m_query; + std::string m_query; QueryTokens m_tokens; // Prefix of the last token in the query. // We need it here to make suggestions. @@ -79,8 +80,9 @@ public: Ranker(Index const & index, CitiesBoundariesTable const & boundariesTable, storage::CountryInfoGetter const & infoGetter, KeywordLangMatcher & keywordsScorer, - Emitter & emitter, CategoriesHolder const & categories, vector const & suggests, - VillagesCache & villagesCache, my::Cancellable const & cancellable); + Emitter & emitter, CategoriesHolder const & categories, + std::vector const & suggests, VillagesCache & villagesCache, + my::Cancellable const & cancellable); virtual ~Ranker() = default; void Init(Params const & params, Geocoder::Params const & geocoderParams); @@ -92,26 +94,28 @@ public: void SuggestStrings(); - virtual void SetPreRankerResults(vector && preRankerResults) + virtual void SetPreRankerResults(std::vector && preRankerResults) { - m_preRankerResults = move(preRankerResults); + m_preRankerResults = std::move(preRankerResults); } + virtual void UpdateResults(bool lastUpdate); void ClearCaches(); - inline void BailIfCancelled() { ::search::BailIfCancelled(m_cancellable); } + void BailIfCancelled() { ::search::BailIfCancelled(m_cancellable); } - inline void SetLocalityLanguage(int8_t code) { m_localityLang = code; } + void SetLocalityLanguage(int8_t code) { m_localityLang = code; } private: friend class RankerResultMaker; - void MakeRankerResults(Geocoder::Params const & params, vector & results); + void MakeRankerResults(Geocoder::Params const & params, std::vector & results); - void GetBestMatchName(FeatureType const & f, string & name) const; - void MatchForSuggestions(strings::UniString const & token, int8_t locale, string const & prolog); - void ProcessSuggestions(vector & vec) const; + void GetBestMatchName(FeatureType const & f, std::string & name) const; + void MatchForSuggestions(strings::UniString const & token, int8_t locale, + std::string const & prolog); + void ProcessSuggestions(std::vector & vec) const; Params m_params; Geocoder::Params m_geocoderParams; @@ -126,9 +130,9 @@ private: storage::CountryInfoGetter const & m_infoGetter; Emitter & m_emitter; CategoriesHolder const & m_categories; - vector const & m_suggests; + std::vector const & m_suggests; - vector m_preRankerResults; - vector m_tentativeResults; + std::vector m_preRankerResults; + std::vector m_tentativeResults; }; } // namespace search diff --git a/search/ranking_info.cpp b/search/ranking_info.cpp index f6812b0daa..704adb71dc 100644 --- a/search/ranking_info.cpp +++ b/search/ranking_info.cpp @@ -1,9 +1,10 @@ #include "search/ranking_info.hpp" -#include "std/cmath.hpp" -#include "std/iomanip.hpp" -#include "std/limits.hpp" -#include "std/sstream.hpp" +#include +#include +#include + +using namespace std; namespace search { diff --git a/search/ranking_info.hpp b/search/ranking_info.hpp index 6edbf8d47a..fb9b261024 100644 --- a/search/ranking_info.hpp +++ b/search/ranking_info.hpp @@ -1,10 +1,14 @@ #pragma once -#include "search/common.hpp" #include "search/model.hpp" #include "search/pre_ranking_info.hpp" #include "search/ranking_utils.hpp" +#include +#include +#include +#include + class FeatureType; namespace search @@ -37,9 +41,9 @@ struct RankingInfo // tokens are categorial ones. bool m_falseCats = false; - static void PrintCSVHeader(ostream & os); + static void PrintCSVHeader(std::ostream & os); - void ToCSV(ostream & os) const; + void ToCSV(std::ostream & os) const; // Returns rank calculated by a linear model. Large values // correspond to important features. @@ -48,5 +52,5 @@ struct RankingInfo size_t GetErrorsMade() const; }; -string DebugPrint(RankingInfo const & info); +std::string DebugPrint(RankingInfo const & info); } // namespace search diff --git a/search/ranking_utils.cpp b/search/ranking_utils.cpp index c9f8e4ce68..0e8d1c8b52 100644 --- a/search/ranking_utils.cpp +++ b/search/ranking_utils.cpp @@ -55,6 +55,7 @@ CategoriesInfo::CategoriesInfo(feature::TypesHolder const & holder, TokenSlice c }); } +// ErrorsMade -------------------------------------------------------------------------------------- string DebugPrint(ErrorsMade const & errorsMade) { ostringstream os; diff --git a/search/ranking_utils.hpp b/search/ranking_utils.hpp index 5631dd99b8..7b22b68e59 100644 --- a/search/ranking_utils.hpp +++ b/search/ranking_utils.hpp @@ -1,8 +1,8 @@ #pragma once +#include "search/common.hpp" #include "search/model.hpp" #include "search/query_params.hpp" -#include "search/utils.hpp" #include "indexer/search_delimiters.hpp" #include "indexer/search_string_utils.hpp" @@ -39,8 +39,8 @@ public: // |holder|. bool IsPureCategories() const { return m_pureCategories; } - // Returns true when all tokens are categories tokens but do not - // correspond to categories in |holder|. + // Returns true when all tokens are categories tokens but none of + // them correspond to categories in |holder|. bool IsFalseCategories() const { return m_falseCategories; } private: