Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortatiana-yan <tatiana.kondakova@gmail.com>2019-03-14 11:26:12 +0300
committermpimenov <mpimenov@users.noreply.github.com>2019-03-18 22:38:39 +0300
commitaff309fd86bf0195e26b47481a8c08ff02828fa0 (patch)
treedde2cdcbfaac400e580bca6ae7248cfce2453747 /map/discovery
parent2454c2b7af5fcae4af525ed5faa8242c93a48a53 (diff)
[discovery] Do not store FeatureTypes without guard in discovery search.
Diffstat (limited to 'map/discovery')
-rw-r--r--map/discovery/discovery_search.cpp33
1 files changed, 11 insertions, 22 deletions
diff --git a/map/discovery/discovery_search.cpp b/map/discovery/discovery_search.cpp
index 1bd527ece2..305b7b56e4 100644
--- a/map/discovery/discovery_search.cpp
+++ b/map/discovery/discovery_search.cpp
@@ -36,21 +36,9 @@ search::Result MakeResultFromFeatureType(FeatureType & ft)
class GreaterRating
{
public:
- bool operator()(std::unique_ptr<FeatureType> & lhs, std::unique_ptr<FeatureType> & rhs) const
+ bool operator()(search::Result const & lhs, search::Result const & rhs) const
{
- double constexpr kPenaltyRating = -1.0;
- double lhsRating = kPenaltyRating;
- double rhsRating = kPenaltyRating;
-
- if (!strings::to_double(lhs->GetMetadata().Get(feature::Metadata::EType::FMD_RATING),
- lhsRating))
- lhsRating = kPenaltyRating;
-
- if (!strings::to_double(rhs->GetMetadata().Get(feature::Metadata::EType::FMD_RATING),
- rhsRating))
- rhsRating = kPenaltyRating;
-
- return lhsRating > rhsRating;
+ return lhs.m_metadata.m_hotelRating > rhs.m_metadata.m_hotelRating;
}
};
} // namespace
@@ -137,11 +125,15 @@ void SearchHotels::ProcessAccumulated()
search::FeatureLoader loader(GetDataSource());
- std::vector<std::unique_ptr<FeatureType>> sortedByRating;
- sortedByRating.resize(m_featureIds.size());
+ std::vector<search::Result> sortedByRating;
+ sortedByRating.reserve(m_featureIds.size());
- for (size_t i = 0; i < m_featureIds.size(); ++i)
- sortedByRating[i] = loader.Load(m_featureIds[i]);
+ for (auto const featureId : m_featureIds)
+ {
+ auto ft = loader.Load(featureId);
+ CHECK(ft, ("Failed to load feature with id", featureId));
+ sortedByRating.push_back(MakeResultFromFeatureType(*ft));
+ }
auto const size = std::min(sortedByRating.size(), GetParams().m_itemsCount);
@@ -149,10 +141,7 @@ void SearchHotels::ProcessAccumulated()
sortedByRating.end(), GreaterRating());
for (size_t i = 0; i < size; ++i)
- {
- auto result = MakeResultFromFeatureType(*sortedByRating[i]);
- AppendResult(std::move(result));
- }
+ AppendResult(std::move(sortedByRating[i]));
}
SearchPopularPlaces::SearchPopularPlaces(DataSource const & dataSource,