forked from organicmaps/organicmaps
Hotels in discovery manager.
This commit is contained in:
parent
c54f85aa46
commit
2dd27743b6
9 changed files with 107 additions and 25 deletions
|
@ -30,6 +30,7 @@ set(
|
|||
discovery/discovery_client_params.hpp
|
||||
discovery/discovery_manager.cpp
|
||||
discovery/discovery_manager.hpp
|
||||
discovery/discovery_search_params.hpp
|
||||
displacement_mode_manager.cpp
|
||||
displacement_mode_manager.hpp
|
||||
displayed_categories_modifiers.cpp
|
||||
|
|
|
@ -177,7 +177,7 @@ std::vector<std::unique_ptr<Track>> BookmarkCategory::StealTracks()
|
|||
{
|
||||
std::vector<std::unique_ptr<Track>> tracks;
|
||||
std::swap(m_tracks, tracks);
|
||||
return std::move(tracks);
|
||||
return tracks;
|
||||
}
|
||||
|
||||
void BookmarkCategory::AppendTracks(std::vector<std::unique_ptr<Track>> && tracks)
|
||||
|
|
|
@ -27,28 +27,16 @@ Manager::Manager(Index const & index, search::CityFinder & cityFinder, APIs cons
|
|||
}
|
||||
|
||||
// static
|
||||
search::SearchParams Manager::GetSearchParams(Manager::Params const & params, ItemType const type)
|
||||
search::DiscoverySearchParams Manager::GetSearchParams(Manager::Params const & params, ItemType const type)
|
||||
{
|
||||
search::SearchParams p;
|
||||
search::DiscoverySearchParams p;
|
||||
p.m_query = GetQuery(type);
|
||||
p.m_inputLocale = "en";
|
||||
p.m_viewport = params.m_viewport;
|
||||
p.m_position = params.m_viewportCenter;
|
||||
p.m_maxNumResults = params.m_itemsCount;
|
||||
p.m_mode = search::Mode::Viewport;
|
||||
return p;
|
||||
}
|
||||
p.m_itemsCount = params.m_itemsCount;
|
||||
if (type == ItemType::Hotels)
|
||||
p.m_sortingType = search::DiscoverySearchParams::SortingType::HotelRating;
|
||||
|
||||
// static
|
||||
search::SearchParams Manager::GetBookingSearchParamsForTesting()
|
||||
{
|
||||
search::SearchParams p;
|
||||
p.m_query = GetQuery(ItemType::Hotels);
|
||||
p.m_inputLocale = "en";
|
||||
p.m_viewport = {37.568808916849733, 67.451852658402345, 37.632819283150269, 67.515833479171874};
|
||||
p.m_position = {{37.6008141, 67.4838356}};
|
||||
p.m_maxNumResults = 6;
|
||||
p.m_mode = search::Mode::Viewport;
|
||||
return p;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "search/city_finder.hpp"
|
||||
|
||||
#include "map/discovery/discovery_client_params.hpp"
|
||||
#include "map/discovery/discovery_search_params.hpp"
|
||||
#include "map/search_api.hpp"
|
||||
|
||||
#include "partners_api/booking_api.hpp"
|
||||
|
@ -108,17 +109,15 @@ public:
|
|||
case ItemType::Cafes:
|
||||
case ItemType::Hotels:
|
||||
{
|
||||
auto p = type == ItemType::Hotels ? GetBookingSearchParamsForTesting() : GetSearchParams(params, type);
|
||||
auto p = GetSearchParams(params, type);
|
||||
auto const viewportCenter = params.m_viewportCenter;
|
||||
p.m_onResults = [requestId, onResult, type, viewportCenter](search::Results const & results) {
|
||||
if (!results.IsEndMarker())
|
||||
return;
|
||||
GetPlatform().RunTask(Platform::Thread::Gui,
|
||||
[requestId, onResult, type, results, viewportCenter] {
|
||||
onResult(requestId, results, type, viewportCenter);
|
||||
});
|
||||
};
|
||||
m_searchApi.GetEngine().Search(p);
|
||||
m_searchApi.SearchForDiscovery(p);
|
||||
break;
|
||||
}
|
||||
case ItemType::LocalExperts:
|
||||
|
@ -148,9 +147,7 @@ public:
|
|||
std::string GetLocalExpertsUrl(m2::PointD const & point) const;
|
||||
|
||||
private:
|
||||
static search::SearchParams GetSearchParams(Params const & params, ItemType const type);
|
||||
// TODO: Remove this method when real implementation will be ready.
|
||||
static search::SearchParams GetBookingSearchParamsForTesting();
|
||||
static search::DiscoverySearchParams GetSearchParams(Manager::Params const & params, ItemType const type);
|
||||
std::string GetCityViatorId(m2::PointD const & point) const;
|
||||
|
||||
Index const & m_index;
|
||||
|
|
44
map/discovery/discovery_search_params.hpp
Normal file
44
map/discovery/discovery_search_params.hpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
#pragma once
|
||||
|
||||
#include "map/discovery/discovery_client_params.hpp"
|
||||
|
||||
#include "search/result.hpp"
|
||||
|
||||
#include "geometry/point2d.hpp"
|
||||
#include "geometry/rect2d.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
namespace search
|
||||
{
|
||||
struct DiscoverySearchParams
|
||||
{
|
||||
enum class SortingType
|
||||
{
|
||||
None,
|
||||
HotelRating
|
||||
};
|
||||
|
||||
struct HotelRatingComparator
|
||||
{
|
||||
bool operator()(Result const & lhs, Result const & rhs) const
|
||||
{
|
||||
float l = -1, r = -1;
|
||||
UNUSED_VALUE(strings::to_float(lhs.m_metadata.m_hotelRating, l));
|
||||
UNUSED_VALUE(strings::to_float(rhs.m_metadata.m_hotelRating, r));
|
||||
return l > r;
|
||||
}
|
||||
};
|
||||
|
||||
using OnResults = std::function<void(Results const & results)>;
|
||||
|
||||
std::string m_query;
|
||||
size_t m_itemsCount = 0;
|
||||
m2::PointD m_position;
|
||||
m2::RectD m_viewport;
|
||||
SortingType m_sortingType = SortingType::None;
|
||||
OnResults m_onResults = nullptr;
|
||||
};
|
||||
} // namespace search
|
|
@ -1,6 +1,7 @@
|
|||
#include "map/search_api.hpp"
|
||||
|
||||
#include "map/bookmarks_search_params.hpp"
|
||||
#include "map/discovery/discovery_search_params.hpp"
|
||||
#include "map/everywhere_search_params.hpp"
|
||||
#include "map/viewport_search_params.hpp"
|
||||
|
||||
|
@ -222,6 +223,41 @@ bool SearchAPI::SearchInViewport(ViewportSearchParams const & params)
|
|||
return Search(p, false /* forceSearch */);
|
||||
}
|
||||
|
||||
bool SearchAPI::SearchForDiscovery(DiscoverySearchParams const & params)
|
||||
{
|
||||
CHECK(params.m_onResults, ());
|
||||
CHECK(!params.m_query.empty(), ());
|
||||
CHECK_GREATER(params.m_itemsCount, 0, ());
|
||||
|
||||
SearchParams p;
|
||||
p.m_query = params.m_query;
|
||||
p.m_inputLocale = "en";
|
||||
p.m_viewport = params.m_viewport;
|
||||
p.m_position = params.m_position;
|
||||
p.m_maxNumResults = params.m_itemsCount;
|
||||
p.m_mode = search::Mode::Viewport;
|
||||
p.m_onResults = [params](Results const & results) {
|
||||
if (!results.IsEndMarker())
|
||||
return;
|
||||
|
||||
switch (params.m_sortingType)
|
||||
{
|
||||
case DiscoverySearchParams::SortingType::None:
|
||||
params.m_onResults(results);
|
||||
break;
|
||||
case DiscoverySearchParams::SortingType::HotelRating:
|
||||
{
|
||||
Results r(results);
|
||||
r.SortBy(DiscoverySearchParams::HotelRatingComparator());
|
||||
params.m_onResults(r);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return Search(p, false /* forceSearch */);
|
||||
}
|
||||
|
||||
bool SearchAPI::SearchInDownloader(storage::DownloaderSearchParams const & params)
|
||||
{
|
||||
m_sponsoredMode = SponsoredMode::None;
|
||||
|
|
|
@ -29,6 +29,7 @@ namespace search
|
|||
struct BookmarksSearchParams;
|
||||
struct EverywhereSearchParams;
|
||||
struct ViewportSearchParams;
|
||||
struct DiscoverySearchParams;
|
||||
}
|
||||
|
||||
namespace storage
|
||||
|
@ -111,6 +112,8 @@ public:
|
|||
// Search in the viewport.
|
||||
bool SearchInViewport(search::ViewportSearchParams const & params);
|
||||
|
||||
bool SearchForDiscovery(search::DiscoverySearchParams const & params);
|
||||
|
||||
// Search for maps by countries or cities.
|
||||
bool SearchInDownloader(storage::DownloaderSearchParams const & params);
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "base/assert.hpp"
|
||||
#include "base/buffer_vector.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
@ -200,6 +201,14 @@ public:
|
|||
|
||||
void Swap(Results & rhs);
|
||||
|
||||
template <typename Fn>
|
||||
void SortBy(Fn && comparator)
|
||||
{
|
||||
sort(begin(), end(), std::forward<Fn>(comparator));
|
||||
for (int32_t i = 0; i < static_cast<int32_t>(GetCount()); ++i)
|
||||
operator[](i).SetPositionInResults(i);
|
||||
}
|
||||
|
||||
private:
|
||||
enum class Status
|
||||
{
|
||||
|
|
|
@ -132,6 +132,7 @@
|
|||
F63421F81DF9BF9100A96868 /* reachable_by_taxi_checker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F63421F61DF9BF9100A96868 /* reachable_by_taxi_checker.cpp */; };
|
||||
F63421F91DF9BF9100A96868 /* reachable_by_taxi_checker.hpp in Headers */ = {isa = PBXBuildFile; fileRef = F63421F71DF9BF9100A96868 /* reachable_by_taxi_checker.hpp */; };
|
||||
F685EB631E955C45003CA3FF /* libicu.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F685EB621E955C45003CA3FF /* libicu.a */; };
|
||||
F69687C8201B4A3600457650 /* discovery_search_params.hpp in Headers */ = {isa = PBXBuildFile; fileRef = F69687C7201B4A3500457650 /* discovery_search_params.hpp */; };
|
||||
F6B283031C1B03320081957A /* gps_track_collection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6B282FB1C1B03320081957A /* gps_track_collection.cpp */; };
|
||||
F6B283041C1B03320081957A /* gps_track_collection.hpp in Headers */ = {isa = PBXBuildFile; fileRef = F6B282FC1C1B03320081957A /* gps_track_collection.hpp */; };
|
||||
F6B283051C1B03320081957A /* gps_track_filter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6B282FD1C1B03320081957A /* gps_track_filter.cpp */; };
|
||||
|
@ -296,6 +297,7 @@
|
|||
F63421F61DF9BF9100A96868 /* reachable_by_taxi_checker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = reachable_by_taxi_checker.cpp; sourceTree = "<group>"; };
|
||||
F63421F71DF9BF9100A96868 /* reachable_by_taxi_checker.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = reachable_by_taxi_checker.hpp; sourceTree = "<group>"; };
|
||||
F685EB621E955C45003CA3FF /* libicu.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libicu.a; path = "/Users/v.mikhaylenko/mapsme/omim/xcode/icu/../../../omim-build/xcode/Debug/libicu.a"; sourceTree = "<absolute>"; };
|
||||
F69687C7201B4A3500457650 /* discovery_search_params.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = discovery_search_params.hpp; sourceTree = "<group>"; };
|
||||
F6B282FB1C1B03320081957A /* gps_track_collection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = gps_track_collection.cpp; sourceTree = "<group>"; };
|
||||
F6B282FC1C1B03320081957A /* gps_track_collection.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = gps_track_collection.hpp; sourceTree = "<group>"; };
|
||||
F6B282FD1C1B03320081957A /* gps_track_filter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = gps_track_filter.cpp; sourceTree = "<group>"; };
|
||||
|
@ -594,6 +596,7 @@
|
|||
F6FC3CB11FC323420001D929 /* discovery */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
F69687C7201B4A3500457650 /* discovery_search_params.hpp */,
|
||||
F6FC3CB21FC323420001D929 /* discovery_client_params.hpp */,
|
||||
F6FC3CB31FC323420001D929 /* discovery_manager.cpp */,
|
||||
F6FC3CB41FC323420001D929 /* discovery_manager.hpp */,
|
||||
|
@ -617,6 +620,7 @@
|
|||
675346A21A4054E800A0A8C3 /* user_mark.hpp in Headers */,
|
||||
454649F21F2728CE00EF4064 /* local_ads_mark.hpp in Headers */,
|
||||
F6B283061C1B03320081957A /* gps_track_filter.hpp in Headers */,
|
||||
F69687C8201B4A3600457650 /* discovery_search_params.hpp in Headers */,
|
||||
3D4E99831FB462B60025B48C /* viewport_search_params.hpp in Headers */,
|
||||
34583BD01C88556800F94664 /* place_page_info.hpp in Headers */,
|
||||
34921F661BFA0A6900737D6E /* api_mark_point.hpp in Headers */,
|
||||
|
|
Loading…
Add table
Reference in a new issue