search on booking changes

This commit is contained in:
Arsentiy Milchakov 2017-04-14 17:02:40 +03:00
parent 9592ce9b05
commit 50936b3eb5
3 changed files with 25 additions and 30 deletions

View file

@ -179,33 +179,34 @@ 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;
int8_t lang = StringUtf8Multilang::kUnsupportedLanguageCode;
if (editor.GetFeatureStatus(ft.GetID()) == osm::Editor::FeatureStatus::Created)
auto const & info = ft.GetID().m_mwmId.GetInfo();
ASSERT(info, ());
vector<int8_t> mwmLangs;
info->GetRegionData().GetLanguages(mwmLangs);
for (auto mwmLang : mwmLangs)
{
VERIFY(editor.GetEditedFeatureStreet(ft.GetID(), streetName), ("Feature is in editor."));
return streetName;
if (ft.GetName(mwmLang, name))
{
lang = mwmLang;
break;
}
}
search::ReverseGeocoder::Address address;
coder.GetNearbyAddress(feature::GetCenter(ft), address);
return address.GetStreetName();
}
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 (name.empty() && ft.GetName(StringUtf8Multilang::kEnglishCode, name))
lang = StringUtf8Multilang::kEnglishCode;
if (name.empty() && ft.GetName(StringUtf8Multilang::kDefaultCode, name))
lang = StringUtf8Multilang::kDefaultCode;
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);
}
unique_ptr<m4::Tree<NumMwmId>> MakeNumMwmTree(NumMwmIds const & numMwmIds,
@ -948,8 +949,7 @@ 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);
}
auto const mwmInfo = ft.GetID().m_mwmId.GetInfo();

View file

@ -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());

View file

@ -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);