forked from organicmaps/organicmaps
[search] Fixed search in viewport.
This commit is contained in:
parent
b9958d6e06
commit
6a8bfe7973
4 changed files with 81 additions and 27 deletions
|
@ -76,12 +76,7 @@ void SearchAPI::OnViewportChanged(m2::RectD const & viewport)
|
|||
|
||||
bool SearchAPI::SearchEverywhere(EverywhereSearchParams const & params)
|
||||
{
|
||||
// TODO: delete me after Cian project is finished.
|
||||
if (IsCianMode(params.m_query))
|
||||
m_sponsoredMode = SponsoredMode::Cian;
|
||||
|
||||
if (!params.m_bookingFilterParams.IsEmpty())
|
||||
m_sponsoredMode = SponsoredMode::Booking;
|
||||
UpdateSponsoredMode(params.m_query, params.m_bookingFilterParams);
|
||||
|
||||
SearchParams p;
|
||||
p.m_query = params.m_query;
|
||||
|
@ -115,12 +110,7 @@ bool SearchAPI::SearchEverywhere(EverywhereSearchParams const & params)
|
|||
|
||||
bool SearchAPI::SearchInViewport(ViewportSearchParams const & params)
|
||||
{
|
||||
// TODO: delete me after Cian project is finished.
|
||||
if (IsCianMode(params.m_query))
|
||||
m_sponsoredMode = SponsoredMode::Cian;
|
||||
|
||||
if (!params.m_bookingFilterParams.IsEmpty())
|
||||
m_sponsoredMode = SponsoredMode::Booking;
|
||||
UpdateSponsoredMode(params.m_query, params.m_bookingFilterParams);
|
||||
|
||||
SearchParams p;
|
||||
p.m_query = params.m_query;
|
||||
|
@ -157,6 +147,8 @@ bool SearchAPI::SearchInViewport(ViewportSearchParams const & params)
|
|||
|
||||
bool SearchAPI::SearchInDownloader(storage::DownloaderSearchParams const & params)
|
||||
{
|
||||
m_sponsoredMode = SponsoredMode::None;
|
||||
|
||||
SearchParams p;
|
||||
p.m_query = params.m_query;
|
||||
p.m_inputLocale = params.m_inputLocale;
|
||||
|
@ -305,3 +297,25 @@ bool SearchAPI::QueryMayBeSkipped(SearchParams const & prevParams,
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SearchAPI::UpdateSponsoredMode(std::string const & query,
|
||||
booking::filter::availability::Params const & params)
|
||||
{
|
||||
m_sponsoredMode = SponsoredMode::None;
|
||||
// TODO: delete me after Cian project is finished.
|
||||
if (IsCianMode(query))
|
||||
m_sponsoredMode = SponsoredMode::Cian;
|
||||
if (!params.IsEmpty())
|
||||
m_sponsoredMode = SponsoredMode::Booking;
|
||||
}
|
||||
|
||||
string DebugPrint(SearchAPI::SponsoredMode mode) {
|
||||
switch (mode) {
|
||||
case SearchAPI::SponsoredMode::None:
|
||||
return "None";
|
||||
case SearchAPI::SponsoredMode::Cian:
|
||||
return "Cian";
|
||||
case SearchAPI::SponsoredMode::Booking:
|
||||
return "Booking";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
|
@ -139,6 +140,9 @@ private:
|
|||
bool QueryMayBeSkipped(search::SearchParams const & prevParams,
|
||||
search::SearchParams const & currParams) const;
|
||||
|
||||
void UpdateSponsoredMode(std::string const & query,
|
||||
booking::filter::availability::Params const & params);
|
||||
|
||||
Index & m_index;
|
||||
storage::Storage const & m_storage;
|
||||
storage::CountryInfoGetter const & m_infoGetter;
|
||||
|
@ -156,3 +160,5 @@ private:
|
|||
|
||||
SponsoredMode m_sponsoredMode = SponsoredMode::None;
|
||||
};
|
||||
|
||||
std::string DebugPrint(SearchAPI::SponsoredMode mode);
|
||||
|
|
|
@ -15,28 +15,43 @@ namespace search
|
|||
{
|
||||
namespace
|
||||
{
|
||||
struct Stats
|
||||
{
|
||||
size_t m_shownResults = 0;
|
||||
bool m_mode = false;
|
||||
};
|
||||
|
||||
class TestDelegate : public ViewportSearchCallback::Delegate
|
||||
{
|
||||
public:
|
||||
TestDelegate(bool & mode) : m_mode(mode) {}
|
||||
explicit TestDelegate(Stats & stats) : m_stats(stats) {}
|
||||
|
||||
~TestDelegate() override = default;
|
||||
|
||||
// ViewportSearchCallback::Delegate overrides:
|
||||
void RunUITask(function<void()> /* fn */) override {}
|
||||
void SetHotelDisplacementMode() override { m_mode = true; }
|
||||
void RunUITask(function<void()> fn) override { fn(); }
|
||||
|
||||
void SetHotelDisplacementMode() override { m_stats.m_mode = true; }
|
||||
|
||||
bool IsViewportSearchActive() const override { return true; }
|
||||
void ShowViewportSearchResults(Results const & /* results */) override {}
|
||||
void ClearViewportSearchResults() override {}
|
||||
|
||||
void ShowViewportSearchResults(Results const & results) override
|
||||
{
|
||||
m_stats.m_shownResults = results.GetCount();
|
||||
}
|
||||
|
||||
void ClearViewportSearchResults() override { m_stats.m_shownResults = 0; }
|
||||
|
||||
private:
|
||||
bool & m_mode;
|
||||
Stats & m_stats;
|
||||
};
|
||||
|
||||
class InteractiveSearchRequest : public TestDelegate, public TestSearchRequest
|
||||
{
|
||||
public:
|
||||
InteractiveSearchRequest(TestSearchEngine & engine, string const & query,
|
||||
m2::RectD const & viewport, bool & mode)
|
||||
: TestDelegate(mode)
|
||||
m2::RectD const & viewport, Stats & stats)
|
||||
: TestDelegate(stats)
|
||||
, TestSearchRequest(engine, query, "en" /* locale */, Mode::Viewport, viewport)
|
||||
{
|
||||
SetCustomOnResults(
|
||||
|
@ -75,28 +90,30 @@ UNIT_CLASS_TEST(InteractiveSearchTest, Smoke)
|
|||
});
|
||||
|
||||
{
|
||||
bool mode = false;
|
||||
Stats stats;
|
||||
InteractiveSearchRequest request(
|
||||
m_engine, "cafe", m2::RectD(m2::PointD(-1.5, -1.5), m2::PointD(-0.5, -0.5)), mode);
|
||||
m_engine, "cafe", m2::RectD(m2::PointD(-1.5, -1.5), m2::PointD(-0.5, -0.5)), stats);
|
||||
request.Run();
|
||||
|
||||
TRules const rules = {ExactMatch(id, cafes[0]), ExactMatch(id, cafes[1]),
|
||||
ExactMatch(id, cafes[2]), ExactMatch(id, cafes[3])};
|
||||
|
||||
TEST(!mode, ());
|
||||
TEST(!stats.m_mode, ());
|
||||
TEST_EQUAL(stats.m_shownResults, 4, ());
|
||||
TEST(MatchResults(m_index, rules, request.Results()), ());
|
||||
}
|
||||
|
||||
{
|
||||
bool mode = false;
|
||||
Stats stats;
|
||||
InteractiveSearchRequest request(m_engine, "hotel",
|
||||
m2::RectD(m2::PointD(0.5, 0.5), m2::PointD(1.5, 1.5)), mode);
|
||||
m2::RectD(m2::PointD(0.5, 0.5), m2::PointD(1.5, 1.5)), stats);
|
||||
request.Run();
|
||||
|
||||
TRules const rules = {ExactMatch(id, hotels[0]), ExactMatch(id, hotels[1]),
|
||||
ExactMatch(id, hotels[2]), ExactMatch(id, hotels[3])};
|
||||
|
||||
TEST(mode, ());
|
||||
TEST(stats.m_mode, ());
|
||||
TEST_EQUAL(stats.m_shownResults, 4, ());
|
||||
TEST(MatchResults(m_index, rules, request.Results()), ());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,24 @@ void ViewportSearchCallback::operator()(Results const & results)
|
|||
m_hotelsModeSet = true;
|
||||
}
|
||||
|
||||
if (!results.IsEndMarker())
|
||||
// We need to clear old results and show a new bunch of results when
|
||||
// the search is completed normally (note that there may be empty
|
||||
// set of results), or when the search is not completed and there is
|
||||
// something in results.
|
||||
//
|
||||
// We don't need to clear old results or show current results if the
|
||||
// search is cancelled, because:
|
||||
|
||||
// * current request is cancelled because of the next
|
||||
// search-in-viewport request - in this case it is the
|
||||
// responsibility of the next search request to clean up old results
|
||||
// and there is no need to clean up current results. We don't want
|
||||
// to show blinking results.
|
||||
//
|
||||
// * search in viewport may be cancelled completely - it is the
|
||||
// responsibility of the user of this class to handle this case and
|
||||
// clean up results.
|
||||
if (results.IsEndedNormal() || (!results.IsEndMarker() && results.GetCount() != 0))
|
||||
{
|
||||
auto & delegate = m_delegate;
|
||||
bool const firstCall = m_firstCall;
|
||||
|
|
Loading…
Add table
Reference in a new issue