forked from organicmaps/organicmaps-tmp
Merge pull request #5838 from milchakov/search_on_booking
Booking search changes
This commit is contained in:
commit
7e593bfc87
6 changed files with 112 additions and 32 deletions
|
@ -286,4 +286,26 @@ void GetReadableName(RegionData const & regionData, StringUtf8Multilang const &
|
|||
|
||||
GetMwmLangName(regionData, src, out);
|
||||
}
|
||||
|
||||
int8_t GetNameForSearchOnBooking(RegionData const & regionData, StringUtf8Multilang const & src,
|
||||
string & name)
|
||||
{
|
||||
if (src.GetString(StringUtf8Multilang::kDefaultCode, name))
|
||||
return StringUtf8Multilang::kDefaultCode;
|
||||
|
||||
vector<int8_t> mwmLangs;
|
||||
regionData.GetLanguages(mwmLangs);
|
||||
|
||||
for (auto mwmLang : mwmLangs)
|
||||
{
|
||||
if (src.GetString(mwmLang, name))
|
||||
return mwmLang;
|
||||
}
|
||||
|
||||
if (src.GetString(StringUtf8Multilang::kEnglishCode, name))
|
||||
return StringUtf8Multilang::kEnglishCode;
|
||||
|
||||
name.clear();
|
||||
return StringUtf8Multilang::kUnsupportedLanguageCode;
|
||||
}
|
||||
} // namespace feature
|
||||
|
|
|
@ -46,4 +46,12 @@ namespace feature
|
|||
/// - country language name.
|
||||
void GetReadableName(RegionData const & regionData, StringUtf8Multilang const & src,
|
||||
int8_t const deviceLang, bool allowTranslit, string & out);
|
||||
|
||||
/// Returns language id as return result and name for search on booking in the @name parameter,
|
||||
/// the priority is the following:
|
||||
/// - default name;
|
||||
/// - country language name;
|
||||
/// - english name.
|
||||
int8_t GetNameForSearchOnBooking(RegionData const & regionData, StringUtf8Multilang const & src,
|
||||
string & name);
|
||||
} // namespace feature
|
||||
|
|
|
@ -313,4 +313,71 @@ UNIT_TEST(GetReadableName)
|
|||
TEST_EQUAL(name, "ko name", ());
|
||||
}
|
||||
}
|
||||
|
||||
UNIT_TEST(GetNameForSearchOnBooking)
|
||||
{
|
||||
{
|
||||
StrUtf8 src;
|
||||
feature::RegionData regionData;
|
||||
string result;
|
||||
auto lang = feature::GetNameForSearchOnBooking(regionData, src, result);
|
||||
TEST_EQUAL(lang, StrUtf8::kUnsupportedLanguageCode, ());
|
||||
TEST(result.empty(), ());
|
||||
}
|
||||
{
|
||||
StrUtf8 src;
|
||||
src.AddString("default", "default name");
|
||||
feature::RegionData regionData;
|
||||
string result;
|
||||
auto lang = feature::GetNameForSearchOnBooking(regionData, src, result);
|
||||
TEST_EQUAL(lang, StrUtf8::kDefaultCode, ());
|
||||
TEST_EQUAL(result, "default name", ());
|
||||
}
|
||||
{
|
||||
StrUtf8 src;
|
||||
src.AddString("default", "default name");
|
||||
src.AddString("ko", "ko name");
|
||||
src.AddString("en", "en name");
|
||||
feature::RegionData regionData;
|
||||
regionData.SetLanguages({"ko", "en"});
|
||||
string result;
|
||||
auto lang = feature::GetNameForSearchOnBooking(regionData, src, result);
|
||||
TEST_EQUAL(lang, StrUtf8::kDefaultCode, ());
|
||||
TEST_EQUAL(result, "default name", ());
|
||||
}
|
||||
{
|
||||
StrUtf8 src;
|
||||
src.AddString("en", "en name");
|
||||
src.AddString("ko", "ko name");
|
||||
feature::RegionData regionData;
|
||||
regionData.SetLanguages({"ko"});
|
||||
string result;
|
||||
auto lang = feature::GetNameForSearchOnBooking(regionData, src, result);
|
||||
TEST_EQUAL(lang, StrUtf8::GetLangIndex("ko"), ());
|
||||
TEST_EQUAL(result, "ko name", ());
|
||||
}
|
||||
{
|
||||
StrUtf8 src;
|
||||
src.AddString("en", "en name");
|
||||
src.AddString("ko", "ko name");
|
||||
src.AddString("de", "de name");
|
||||
feature::RegionData regionData;
|
||||
regionData.SetLanguages({"de", "ko"});
|
||||
string result;
|
||||
auto lang = feature::GetNameForSearchOnBooking(regionData, src, result);
|
||||
TEST_EQUAL(lang, StrUtf8::GetLangIndex("de"), ());
|
||||
TEST_EQUAL(result, "de name", ());
|
||||
}
|
||||
{
|
||||
StrUtf8 src;
|
||||
src.AddString("en", "en name");
|
||||
src.AddString("ko", "ko name");
|
||||
feature::RegionData regionData;
|
||||
regionData.SetLanguages({"de", "fr"});
|
||||
string result;
|
||||
auto lang = feature::GetNameForSearchOnBooking(regionData, src, result);
|
||||
TEST_EQUAL(lang, StrUtf8::GetLangIndex("en"), ());
|
||||
TEST_EQUAL(result, "en name", ());
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
|
|
@ -180,33 +180,21 @@ void CancelQuery(weak_ptr<search::ProcessorHandle> & handle)
|
|||
handle.reset();
|
||||
}
|
||||
|
||||
string GetStreet(search::ReverseGeocoder const & coder, FeatureType const & ft)
|
||||
string MakeSearchBookingUrl(booking::Api const & bookingApi, CityFinder & cityFinder,
|
||||
FeatureType const & ft)
|
||||
{
|
||||
auto const & editor = osm::Editor::Instance();
|
||||
string streetName;
|
||||
string name;
|
||||
auto const & info = ft.GetID().m_mwmId.GetInfo();
|
||||
ASSERT(info, ());
|
||||
|
||||
if (editor.GetFeatureStatus(ft.GetID()) == osm::Editor::FeatureStatus::Created)
|
||||
{
|
||||
VERIFY(editor.GetEditedFeatureStreet(ft.GetID(), streetName), ("Feature is in editor."));
|
||||
return streetName;
|
||||
}
|
||||
search::ReverseGeocoder::Address address;
|
||||
coder.GetNearbyAddress(feature::GetCenter(ft), address);
|
||||
return address.GetStreetName();
|
||||
}
|
||||
int8_t lang = feature::GetNameForSearchOnBooking(info->GetRegionData(), ft.GetNames(), name);
|
||||
|
||||
string MakeSearchBookingUrl(Index const & index, booking::Api const & bookingApi,
|
||||
CityFinder & cityFinder, FeatureType const & ft,
|
||||
string const & localizedType)
|
||||
{
|
||||
search::ReverseGeocoder const coder(index);
|
||||
string hotelName;
|
||||
ft.GetReadableName(false /* allowTranslit */, hotelName);
|
||||
if (lang == StringUtf8Multilang::kUnsupportedLanguageCode)
|
||||
return {};
|
||||
|
||||
auto const lang = StringUtf8Multilang::GetLangIndex(languages::GetCurrentNorm());
|
||||
string city = cityFinder.GetCityName(feature::GetCenter(ft), lang);
|
||||
|
||||
return bookingApi.GetSearchUrl(city, GetStreet(coder, ft), hotelName, localizedType);
|
||||
return bookingApi.GetSearchUrl(city, name);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
@ -936,8 +924,8 @@ void Framework::FillInfoFromFeatureType(FeatureType const & ft, place_page::Info
|
|||
}
|
||||
else if (ftypes::IsHotelChecker::Instance()(ft))
|
||||
{
|
||||
info.m_bookingSearchUrl = MakeSearchBookingUrl(m_model.GetIndex(), *m_bookingApi, *m_cityFinder,
|
||||
ft, info.GetLocalizedType());
|
||||
info.m_bookingSearchUrl = MakeSearchBookingUrl(*m_bookingApi, *m_cityFinder, ft);
|
||||
LOG(LINFO, (info.m_bookingSearchUrl));
|
||||
}
|
||||
|
||||
auto const mwmInfo = ft.GetID().m_mwmId.GetInfo();
|
||||
|
|
|
@ -289,17 +289,13 @@ string Api::GetHotelReviewsUrl(string const & hotelId, string const & baseUrl) c
|
|||
return os.str();
|
||||
}
|
||||
|
||||
string Api::GetSearchUrl(string const & city, string const & street, string const & hotelName,
|
||||
string const & type) const
|
||||
string Api::GetSearchUrl(string const & city, string const & name) const
|
||||
{
|
||||
if (city.empty() || type.empty())
|
||||
if (city.empty() || name.empty())
|
||||
return "";
|
||||
|
||||
ostringstream paramStream;
|
||||
if (!street.empty())
|
||||
paramStream << city << " " << street << " " << type;
|
||||
else if (!hotelName.empty())
|
||||
paramStream << city << " " << hotelName << " " << type;
|
||||
paramStream << city << " " << name;
|
||||
|
||||
auto const urlEncodedParams = UrlEncode(paramStream.str());
|
||||
|
||||
|
|
|
@ -61,8 +61,7 @@ public:
|
|||
string GetBookHotelUrl(string const & baseUrl) const;
|
||||
string GetDescriptionUrl(string const & baseUrl) const;
|
||||
string GetHotelReviewsUrl(string const & hotelId, string const & baseUrl) const;
|
||||
string GetSearchUrl(string const & city, string const & street, string const & hotelName,
|
||||
string const & type) const;
|
||||
string GetSearchUrl(string const & city, string const & name) const;
|
||||
// Real-time information methods (used for retriving rapidly changing information).
|
||||
// These methods send requests directly to Booking.
|
||||
void GetMinPrice(string const & hotelId, string const & currency, GetMinPriceCallback const & fn);
|
||||
|
|
Loading…
Add table
Reference in a new issue