forked from organicmaps/organicmaps
[search] Move viewport to search params.
This commit is contained in:
parent
04681c216d
commit
f6f53abfb3
18 changed files with 59 additions and 54 deletions
|
@ -295,7 +295,10 @@ void Framework::OnViewportChanged(ScreenBase const & screen)
|
|||
{
|
||||
auto & intent = m_searchIntents[i];
|
||||
if (intent.m_isDelayed)
|
||||
{
|
||||
intent.m_params.m_viewport = GetCurrentViewport();
|
||||
Search(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1339,6 +1342,8 @@ bool Framework::SearchEverywhere(search::EverywhereSearchParams const & params)
|
|||
p.m_query = params.m_query;
|
||||
p.m_inputLocale = params.m_inputLocale;
|
||||
p.m_mode = search::Mode::Everywhere;
|
||||
if (m_isViewportInitialized)
|
||||
p.m_viewport = GetCurrentViewport();
|
||||
p.m_forceSearch = true;
|
||||
p.m_suggestsEnabled = true;
|
||||
p.m_hotelsFilter = params.m_hotelsFilter;
|
||||
|
@ -1364,6 +1369,8 @@ bool Framework::SearchInViewport(search::ViewportSearchParams const & params)
|
|||
search::SearchParams p;
|
||||
p.m_query = params.m_query;
|
||||
p.m_inputLocale = params.m_inputLocale;
|
||||
if (m_isViewportInitialized)
|
||||
p.m_viewport = GetCurrentViewport();
|
||||
p.m_mode = search::Mode::Viewport;
|
||||
p.m_forceSearch = false;
|
||||
p.m_suggestsEnabled = false;
|
||||
|
@ -1391,6 +1398,8 @@ bool Framework::SearchInDownloader(DownloaderSearchParams const & params)
|
|||
search::SearchParams p;
|
||||
p.m_query = params.m_query;
|
||||
p.m_inputLocale = params.m_inputLocale;
|
||||
if (m_isViewportInitialized)
|
||||
p.m_viewport = GetCurrentViewport();
|
||||
p.m_mode = search::Mode::Downloader;
|
||||
p.m_forceSearch = true;
|
||||
p.m_suggestsEnabled = false;
|
||||
|
@ -1624,7 +1633,7 @@ bool Framework::Search(search::SearchParams const & params)
|
|||
if (ParseEditorDebugCommand(params))
|
||||
return true;
|
||||
|
||||
if (QueryMayBeSkipped(intent, rParams, GetCurrentViewport()))
|
||||
if (QueryMayBeSkipped(intent, rParams))
|
||||
return false;
|
||||
|
||||
intent.m_params = rParams;
|
||||
|
@ -1647,8 +1656,7 @@ void Framework::Search(SearchIntent & intent) const
|
|||
return;
|
||||
}
|
||||
|
||||
intent.m_viewport = GetCurrentViewport();
|
||||
intent.m_handle = m_searchEngine->Search(intent.m_params, intent.m_viewport);
|
||||
intent.m_handle = m_searchEngine->Search(intent.m_params);
|
||||
intent.m_isDelayed = false;
|
||||
}
|
||||
|
||||
|
@ -1660,11 +1668,13 @@ void Framework::SetCurrentPositionIfPossible(search::SearchParams & params)
|
|||
params.SetPosition(ms::LatLon(lat, lon));
|
||||
}
|
||||
|
||||
bool Framework::QueryMayBeSkipped(SearchIntent const & intent, search::SearchParams const & params,
|
||||
m2::RectD const & viewport) const
|
||||
bool Framework::QueryMayBeSkipped(SearchIntent const & intent,
|
||||
search::SearchParams const & params) const
|
||||
{
|
||||
auto const & lastParams = intent.m_params;
|
||||
auto const & lastViewport = intent.m_viewport;
|
||||
auto const & lastViewport = lastParams.m_viewport;
|
||||
|
||||
auto const & viewport = params.m_viewport;
|
||||
|
||||
if (params.m_forceSearch)
|
||||
return false;
|
||||
|
|
|
@ -519,7 +519,6 @@ private:
|
|||
{
|
||||
search::SearchParams m_params;
|
||||
weak_ptr<search::ProcessorHandle> m_handle;
|
||||
m2::RectD m_viewport;
|
||||
bool m_isDelayed = false;
|
||||
};
|
||||
|
||||
|
@ -546,10 +545,9 @@ private:
|
|||
bool Search(search::SearchParams const & params);
|
||||
void Search(SearchIntent & intent) const;
|
||||
|
||||
// Returns true when |params| and |viewport| are almost the same as
|
||||
// the latest search query's params and viewport in the |intent|.
|
||||
bool QueryMayBeSkipped(SearchIntent const & intent, search::SearchParams const & params,
|
||||
m2::RectD const & viewport) const;
|
||||
// Returns true when |params| is almost the same as the latest
|
||||
// search query params in |intent|.
|
||||
bool QueryMayBeSkipped(SearchIntent const & intent, search::SearchParams const & params) const;
|
||||
|
||||
void OnUpdateGpsTrackPointsCallback(vector<pair<size_t, location::GpsTrackInfo>> && toAdd,
|
||||
pair<size_t, size_t> const & toRemove);
|
||||
|
|
|
@ -124,12 +124,12 @@ Engine::~Engine()
|
|||
thread.join();
|
||||
}
|
||||
|
||||
weak_ptr<ProcessorHandle> Engine::Search(SearchParams const & params, m2::RectD const & viewport)
|
||||
weak_ptr<ProcessorHandle> Engine::Search(SearchParams const & params)
|
||||
{
|
||||
shared_ptr<ProcessorHandle> handle(new ProcessorHandle());
|
||||
PostMessage(Message::TYPE_TASK, [this, params, viewport, handle](Processor & processor)
|
||||
PostMessage(Message::TYPE_TASK, [this, params, handle](Processor & processor)
|
||||
{
|
||||
DoSearch(params, viewport, handle, processor);
|
||||
DoSearch(params, handle, processor);
|
||||
});
|
||||
return handle;
|
||||
}
|
||||
|
@ -222,8 +222,8 @@ void Engine::PostMessage(TArgs &&... args)
|
|||
m_cv.notify_one();
|
||||
}
|
||||
|
||||
void Engine::DoSearch(SearchParams const & params, m2::RectD const & viewport,
|
||||
shared_ptr<ProcessorHandle> handle, Processor & processor)
|
||||
void Engine::DoSearch(SearchParams const & params, shared_ptr<ProcessorHandle> handle,
|
||||
Processor & processor)
|
||||
{
|
||||
bool const viewportSearch = params.m_mode == Mode::Viewport;
|
||||
|
||||
|
@ -235,6 +235,6 @@ void Engine::DoSearch(SearchParams const & params, m2::RectD const & viewport,
|
|||
handle->Detach();
|
||||
});
|
||||
|
||||
processor.Search(params, viewport);
|
||||
processor.Search(params);
|
||||
}
|
||||
} // namespace search
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
|
||||
#include "indexer/categories_holder.hpp"
|
||||
|
||||
#include "geometry/rect2d.hpp"
|
||||
|
||||
#include "coding/reader.hpp"
|
||||
|
||||
#include "base/macros.hpp"
|
||||
|
@ -98,7 +96,7 @@ public:
|
|||
~Engine();
|
||||
|
||||
// Posts search request to the queue and returns its handle.
|
||||
weak_ptr<ProcessorHandle> Search(SearchParams const & params, m2::RectD const & viewport);
|
||||
weak_ptr<ProcessorHandle> Search(SearchParams const & params);
|
||||
|
||||
// Sets default locale on all query processors.
|
||||
void SetLocale(string const & locale);
|
||||
|
@ -154,8 +152,8 @@ private:
|
|||
template <typename... TArgs>
|
||||
void PostMessage(TArgs &&... args);
|
||||
|
||||
void DoSearch(SearchParams const & params, m2::RectD const & viewport,
|
||||
shared_ptr<ProcessorHandle> handle, Processor & processor);
|
||||
void DoSearch(SearchParams const & params, shared_ptr<ProcessorHandle> handle,
|
||||
Processor & processor);
|
||||
|
||||
vector<Suggest> m_suggests;
|
||||
|
||||
|
|
|
@ -428,7 +428,7 @@ void Processor::ForEachCategoryTypeFuzzy(StringSliceBase const & slice, ToDo &&
|
|||
forward<ToDo>(toDo));
|
||||
}
|
||||
|
||||
void Processor::Search(SearchParams const & params, m2::RectD const & viewport)
|
||||
void Processor::Search(SearchParams const & params)
|
||||
{
|
||||
if (params.m_onStarted)
|
||||
params.m_onStarted();
|
||||
|
@ -449,6 +449,7 @@ void Processor::Search(SearchParams const & params, m2::RectD const & viewport)
|
|||
bool const viewportSearch = m_mode == Mode::Viewport;
|
||||
|
||||
bool rankPivotIsSet = false;
|
||||
auto const & viewport = params.m_viewport;
|
||||
if (!viewportSearch && params.IsValidPosition())
|
||||
{
|
||||
m2::PointD const pos = params.GetPositionMercator();
|
||||
|
|
|
@ -91,7 +91,7 @@ public:
|
|||
int8_t m_inputLocaleCode, m_currentLocaleCode;
|
||||
|
||||
inline bool IsEmptyQuery() const { return (m_prefix.empty() && m_tokens.empty()); }
|
||||
void Search(SearchParams const & params, m2::RectD const & viewport);
|
||||
void Search(SearchParams const & params);
|
||||
|
||||
// Tries to generate a (lat, lon) result from |m_query|.
|
||||
void SearchCoordinates();
|
||||
|
|
|
@ -106,7 +106,7 @@ class DownloaderSearchRequest : public TestSearchRequest, public TestDelegate
|
|||
{
|
||||
public:
|
||||
DownloaderSearchRequest(TestSearchEngine & engine, string const & query)
|
||||
: TestSearchRequest(engine, MakeSearchParams(query), m2::RectD(0, 0, 1, 1) /* viewport */)
|
||||
: TestSearchRequest(engine, MakeSearchParams(query))
|
||||
, m_storage(kCountriesTxt, make_unique<TestMapFilesDownloader>())
|
||||
, m_downloaderCallback(static_cast<DownloaderSearchCallback::Delegate &>(*this),
|
||||
m_engine /* index */, m_engine.GetCountryInfoGetter(), m_storage,
|
||||
|
@ -129,6 +129,7 @@ private:
|
|||
search::SearchParams p;
|
||||
p.m_query = query;
|
||||
p.m_inputLocale = "en";
|
||||
p.m_viewport = m2::RectD(0, 0, 1, 1);
|
||||
p.m_mode = search::Mode::Downloader;
|
||||
p.m_forceSearch = true;
|
||||
p.m_suggestsEnabled = false;
|
||||
|
|
|
@ -74,7 +74,7 @@ bool SearchTest::ResultsMatch(vector<search::Result> const & results, TRules con
|
|||
|
||||
bool SearchTest::ResultsMatch(SearchParams const & params, TRules const & rules)
|
||||
{
|
||||
tests_support::TestSearchRequest request(m_engine, params, m_viewport);
|
||||
tests_support::TestSearchRequest request(m_engine, params);
|
||||
request.Run();
|
||||
return ResultsMatch(request.Results(), rules);
|
||||
}
|
||||
|
@ -90,10 +90,11 @@ unique_ptr<tests_support::TestSearchRequest> SearchTest::MakeRequest(
|
|||
SearchParams params;
|
||||
params.m_query = query;
|
||||
params.m_inputLocale = locale;
|
||||
params.m_viewport = m_viewport;
|
||||
params.m_mode = Mode::Everywhere;
|
||||
params.m_suggestsEnabled = false;
|
||||
|
||||
auto request = make_unique<tests_support::TestSearchRequest>(m_engine, params, m_viewport);
|
||||
auto request = make_unique<tests_support::TestSearchRequest>(m_engine, params);
|
||||
request->Run();
|
||||
return request;
|
||||
}
|
||||
|
|
|
@ -138,16 +138,15 @@ UNIT_CLASS_TEST(InteractiveSearchTest, NearbyFeaturesInViewport)
|
|||
|
||||
SearchParams params;
|
||||
params.m_query = "cafe";
|
||||
params.m_mode = Mode::Viewport;
|
||||
params.m_inputLocale = "en";
|
||||
params.m_viewport = m2::RectD(m2::PointD(-0.5, -0.5), m2::PointD(0.5, 0.5));
|
||||
params.m_mode = Mode::Viewport;
|
||||
params.m_minDistanceOnMapBetweenResults = 0.5;
|
||||
params.m_forceSearch = true;
|
||||
params.m_suggestsEnabled = false;
|
||||
|
||||
m2::RectD const viewport(m2::PointD(-0.5, -0.5), m2::PointD(0.5, 0.5));
|
||||
|
||||
{
|
||||
TestSearchRequest request(m_engine, params, viewport);
|
||||
TestSearchRequest request(m_engine, params);
|
||||
request.Run();
|
||||
|
||||
TEST(MatchResults(m_engine, TRules{ExactMatch(id, cafe1), ExactMatch(id, cafe2),
|
||||
|
@ -159,7 +158,7 @@ UNIT_CLASS_TEST(InteractiveSearchTest, NearbyFeaturesInViewport)
|
|||
params.m_minDistanceOnMapBetweenResults = 1.0;
|
||||
|
||||
{
|
||||
TestSearchRequest request(m_engine, params, viewport);
|
||||
TestSearchRequest request(m_engine, params);
|
||||
request.Run();
|
||||
|
||||
auto const & results = request.Results();
|
||||
|
|
|
@ -311,15 +311,15 @@ UNIT_CLASS_TEST(ProcessorTest, DisableSuggests)
|
|||
builder.Add(london2);
|
||||
});
|
||||
|
||||
SetViewport(m2::RectD(m2::PointD(0.5, 0.5), m2::PointD(1.5, 1.5)));
|
||||
{
|
||||
SearchParams params;
|
||||
params.m_query = "londo";
|
||||
params.m_inputLocale = "en";
|
||||
params.m_viewport = m2::RectD(m2::PointD(0.5, 0.5), m2::PointD(1.5, 1.5));
|
||||
params.m_mode = Mode::Downloader;
|
||||
params.m_suggestsEnabled = false;
|
||||
|
||||
TestSearchRequest request(m_engine, params, m_viewport);
|
||||
TestSearchRequest request(m_engine, params);
|
||||
request.Run();
|
||||
TRules rules = {ExactMatch(worldId, london1), ExactMatch(worldId, london2)};
|
||||
|
||||
|
@ -839,10 +839,10 @@ UNIT_CLASS_TEST(ProcessorTest, HotelsFiltering)
|
|||
SearchParams params;
|
||||
params.m_query = "hotel";
|
||||
params.m_inputLocale = "en";
|
||||
params.m_viewport = m2::RectD(m2::PointD(-1, -1), m2::PointD(2, 2));
|
||||
params.m_mode = Mode::Everywhere;
|
||||
params.m_suggestsEnabled = false;
|
||||
|
||||
SetViewport(m2::RectD(m2::PointD(-1, -1), m2::PointD(2, 2)));
|
||||
{
|
||||
TRules rules = {ExactMatch(id, h1), ExactMatch(id, h2), ExactMatch(id, h3), ExactMatch(id, h4)};
|
||||
TEST(ResultsMatch(params, rules), ());
|
||||
|
@ -1078,11 +1078,10 @@ UNIT_CLASS_TEST(ProcessorTest, Cian)
|
|||
builder.Add(nonameBuilding);
|
||||
});
|
||||
|
||||
SetViewport(m2::RectD(m2::PointD(-1.0, -1.0), m2::PointD(1.0, 1.0)));
|
||||
|
||||
SearchParams params;
|
||||
params.m_query = "cian";
|
||||
params.m_inputLocale = "en";
|
||||
params.m_viewport = m2::RectD(m2::PointD(-1.0, -1.0), m2::PointD(1.0, 1.0));
|
||||
params.m_mode = Mode::Everywhere;
|
||||
params.m_suggestsEnabled = false;
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ struct SearchParams
|
|||
std::string m_inputLocale;
|
||||
|
||||
boost::optional<ms::LatLon> m_position;
|
||||
m2::RectD m_viewport;
|
||||
|
||||
// A minimum distance between search results in meters, needed for
|
||||
// pre-ranking of viewport search results.
|
||||
|
|
|
@ -169,7 +169,7 @@ void MainModel::OnSampleSelected(int index)
|
|||
relevances, goldenMatching, actualMatching));
|
||||
};
|
||||
|
||||
m_queryHandle = engine.Search(params, sample.m_viewport);
|
||||
m_queryHandle = engine.Search(params);
|
||||
m_view->OnSearchStarted();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -178,7 +178,7 @@ int main(int argc, char * argv[])
|
|||
|
||||
search::SearchParams params;
|
||||
sample.FillSearchParams(params);
|
||||
TestSearchRequest request(engine, params, sample.m_viewport);
|
||||
TestSearchRequest request(engine, params);
|
||||
request.Run();
|
||||
|
||||
auto const & results = request.Results();
|
||||
|
|
|
@ -190,6 +190,7 @@ void Sample::FillSearchParams(search::SearchParams & params) const
|
|||
{
|
||||
params.m_query = strings::ToUtf8(m_query);
|
||||
params.m_inputLocale = m_locale;
|
||||
params.m_viewport = m_viewport;
|
||||
params.m_mode = Mode::Everywhere;
|
||||
if (m_posAvailable)
|
||||
params.SetPosition(MercatorBounds::ToLatLon(m_pos));
|
||||
|
|
|
@ -27,10 +27,9 @@ TestSearchEngine::TestSearchEngine(unique_ptr<::search::ProcessorFactory> factor
|
|||
|
||||
TestSearchEngine::~TestSearchEngine() {}
|
||||
|
||||
weak_ptr<::search::ProcessorHandle> TestSearchEngine::Search(::search::SearchParams const & params,
|
||||
m2::RectD const & viewport)
|
||||
weak_ptr<::search::ProcessorHandle> TestSearchEngine::Search(::search::SearchParams const & params)
|
||||
{
|
||||
return m_engine.Search(params, viewport);
|
||||
return m_engine.Search(params);
|
||||
}
|
||||
} // namespace tests_support
|
||||
} // namespace search
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
#include "indexer/index.hpp"
|
||||
|
||||
#include "geometry/rect2d.hpp"
|
||||
|
||||
#include "search/engine.hpp"
|
||||
|
||||
#include "std/string.hpp"
|
||||
|
@ -35,8 +33,7 @@ public:
|
|||
|
||||
void LoadCitiesBoundaries() { m_engine.LoadCitiesBoundaries(); }
|
||||
|
||||
weak_ptr<search::ProcessorHandle> Search(search::SearchParams const & params,
|
||||
m2::RectD const & viewport);
|
||||
weak_ptr<search::ProcessorHandle> Search(search::SearchParams const & params);
|
||||
|
||||
storage::CountryInfoGetter & GetCountryInfoGetter() { return *m_infoGetter; }
|
||||
|
||||
|
|
|
@ -13,17 +13,17 @@ namespace tests_support
|
|||
{
|
||||
TestSearchRequest::TestSearchRequest(TestSearchEngine & engine, string const & query,
|
||||
string const & locale, Mode mode, m2::RectD const & viewport)
|
||||
: m_engine(engine), m_viewport(viewport)
|
||||
: m_engine(engine)
|
||||
{
|
||||
m_params.m_query = query;
|
||||
m_params.m_inputLocale = locale;
|
||||
m_params.m_viewport = viewport;
|
||||
m_params.m_mode = mode;
|
||||
SetUpCallbacks();
|
||||
}
|
||||
|
||||
TestSearchRequest::TestSearchRequest(TestSearchEngine & engine, SearchParams params,
|
||||
m2::RectD const & viewport)
|
||||
: m_engine(engine), m_params(params), m_viewport(viewport)
|
||||
TestSearchRequest::TestSearchRequest(TestSearchEngine & engine, SearchParams const & params)
|
||||
: m_engine(engine), m_params(params)
|
||||
{
|
||||
SetUpCallbacks();
|
||||
}
|
||||
|
@ -32,10 +32,11 @@ TestSearchRequest::TestSearchRequest(TestSearchEngine & engine, string const & q
|
|||
string const & locale, Mode mode, m2::RectD const & viewport,
|
||||
SearchParams::OnStarted const & onStarted,
|
||||
SearchParams::OnResults const & onResults)
|
||||
: m_engine(engine), m_viewport(viewport)
|
||||
: m_engine(engine)
|
||||
{
|
||||
m_params.m_query = query;
|
||||
m_params.m_inputLocale = locale;
|
||||
m_params.m_viewport = viewport;
|
||||
m_params.m_mode = mode;
|
||||
m_params.m_onStarted = onStarted;
|
||||
m_params.m_onResults = onResults;
|
||||
|
@ -63,7 +64,7 @@ vector<search::Result> const & TestSearchRequest::Results() const
|
|||
|
||||
void TestSearchRequest::Start()
|
||||
{
|
||||
m_engine.Search(m_params, m_viewport);
|
||||
m_engine.Search(m_params);
|
||||
}
|
||||
|
||||
void TestSearchRequest::Wait()
|
||||
|
|
|
@ -26,7 +26,7 @@ class TestSearchRequest
|
|||
public:
|
||||
TestSearchRequest(TestSearchEngine & engine, string const & query, string const & locale,
|
||||
Mode mode, m2::RectD const & viewport);
|
||||
TestSearchRequest(TestSearchEngine & engine, SearchParams params, m2::RectD const & viewport);
|
||||
TestSearchRequest(TestSearchEngine & engine, SearchParams const & params);
|
||||
|
||||
// Initiates the search and waits for it to finish.
|
||||
void Run();
|
||||
|
@ -67,7 +67,6 @@ protected:
|
|||
|
||||
TestSearchEngine & m_engine;
|
||||
SearchParams m_params;
|
||||
m2::RectD m_viewport;
|
||||
};
|
||||
} // namespace tests_support
|
||||
} // namespace search
|
||||
|
|
Loading…
Add table
Reference in a new issue