[discovery] sort attractions and cafes by popularity

This commit is contained in:
Arsentiy Milchakov 2018-06-29 14:20:41 +03:00 committed by Ilya Zverev
parent 141363f6f1
commit 7464797a41
3 changed files with 26 additions and 2 deletions

View file

@ -42,8 +42,12 @@ search::DiscoverySearchParams Manager::GetSearchParams(Manager::Params const & p
p.m_viewport = params.m_viewport;
p.m_position = params.m_viewportCenter;
p.m_itemsCount = params.m_itemsCount;
using Sorting = search::DiscoverySearchParams::SortingType;
if (type == ItemType::Hotels)
p.m_sortingType = search::DiscoverySearchParams::SortingType::HotelRating;
p.m_sortingType = Sorting::HotelRating;
else if (type == ItemType::Attractions || type == ItemType::Cafes)
p.m_sortingType = Sorting::Popularity;
return p;
}

View file

@ -18,7 +18,8 @@ struct DiscoverySearchParams
enum class SortingType
{
None,
HotelRating
HotelRating,
Popularity
};
struct HotelRatingComparator
@ -29,6 +30,18 @@ struct DiscoverySearchParams
}
};
struct PopularityComparator
{
bool operator()(Result const & lhs, Result const & rhs) const
{
// Move results without names to the end.
if (lhs.GetString().empty())
return false;
return lhs.GetRankingInfo().m_popularity > rhs.GetRankingInfo().m_popularity;
}
};
using OnResults = std::function<void(Results const & results)>;
std::string m_query;

View file

@ -240,6 +240,13 @@ void SearchAPI::SearchForDiscovery(DiscoverySearchParams const & params)
params.m_onResults(r);
break;
}
case DiscoverySearchParams::SortingType::Popularity:
{
Results r(results);
r.SortBy(DiscoverySearchParams::PopularityComparator());
params.m_onResults(r);
break;
}
}
};