forked from organicmaps/organicmaps
[search] Fixed search in world only.
This commit is contained in:
parent
31bea55870
commit
0d32476783
18 changed files with 103 additions and 50 deletions
|
@ -886,8 +886,7 @@ void Framework::StartInteractiveSearch(search::SearchParams const & params)
|
|||
|
||||
m_lastInteractiveSearchParams = params;
|
||||
m_lastInteractiveSearchParams.SetForceSearch(false);
|
||||
m_lastInteractiveSearchParams.SetSearchMode(SearchParams::IN_VIEWPORT_ONLY |
|
||||
SearchParams::SEARCH_WORLD);
|
||||
m_lastInteractiveSearchParams.SetMode(Mode::Viewport);
|
||||
m_lastInteractiveSearchParams.m_callback = [this](Results const & results)
|
||||
{
|
||||
if (!results.IsEndMarker())
|
||||
|
|
15
search/mode.cpp
Normal file
15
search/mode.cpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include "search/mode.hpp"
|
||||
|
||||
namespace search
|
||||
{
|
||||
string DebugPrint(Mode mode)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case Mode::Viewport: return "Viewport";
|
||||
case Mode::Everywhere: return "Everywhere";
|
||||
case Mode::World: return "World";
|
||||
}
|
||||
return "Unknown";
|
||||
}
|
||||
} // namespace search
|
15
search/mode.hpp
Normal file
15
search/mode.hpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include "std/string.hpp"
|
||||
|
||||
namespace search
|
||||
{
|
||||
enum class Mode
|
||||
{
|
||||
Viewport,
|
||||
Everywhere,
|
||||
World
|
||||
};
|
||||
|
||||
string DebugPrint(Mode mode);
|
||||
} // namespace search
|
|
@ -7,10 +7,8 @@
|
|||
|
||||
namespace search
|
||||
{
|
||||
|
||||
SearchParams::SearchParams()
|
||||
: m_searchRadiusM(-1.0), m_searchMode(ALL),
|
||||
m_forceSearch(false), m_validPos(false)
|
||||
: m_searchRadiusM(-1.0), m_mode(Mode::Everywhere), m_forceSearch(false), m_validPos(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -36,17 +34,15 @@ bool SearchParams::IsEqualCommon(SearchParams const & rhs) const
|
|||
return (m_query == rhs.m_query &&
|
||||
m_inputLocale == rhs.m_inputLocale &&
|
||||
m_validPos == rhs.m_validPos &&
|
||||
m_searchMode == rhs.m_searchMode &&
|
||||
m_mode == rhs.m_mode &&
|
||||
m_searchRadiusM == rhs.m_searchRadiusM);
|
||||
}
|
||||
|
||||
string DebugPrint(SearchParams const & params)
|
||||
{
|
||||
ostringstream ss;
|
||||
ss << "{ SearchParams: Query = " << params.m_query <<
|
||||
", Locale = " << params.m_inputLocale <<
|
||||
", Mode = " << params.m_searchMode << " }";
|
||||
ss << "{ SearchParams: Query = " << params.m_query << ", Locale = " << params.m_inputLocale
|
||||
<< ", Mode = " << DebugPrint(params.m_mode) << " }";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
} // namespace search
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "search/mode.hpp"
|
||||
|
||||
#include "geometry/point2d.hpp"
|
||||
#include "geometry/rect2d.hpp"
|
||||
|
||||
|
@ -23,19 +25,8 @@ namespace search
|
|||
bool IsForceSearch() const { return m_forceSearch; }
|
||||
//@}
|
||||
|
||||
/// @name Search modes.
|
||||
//@{
|
||||
enum SearchModeT
|
||||
{
|
||||
IN_VIEWPORT_ONLY = 1,
|
||||
SEARCH_WORLD = 2,
|
||||
SEARCH_ADDRESS = 4,
|
||||
ALL = SEARCH_WORLD | SEARCH_ADDRESS
|
||||
};
|
||||
|
||||
inline void SetSearchMode(int mode) { m_searchMode = mode; }
|
||||
inline bool HasSearchMode(SearchModeT mode) const { return ((m_searchMode & mode) != 0); }
|
||||
//@}
|
||||
inline void SetMode(Mode mode) { m_mode = mode; }
|
||||
inline Mode GetMode() const { return m_mode; }
|
||||
|
||||
void SetPosition(double lat, double lon);
|
||||
bool IsValidPosition() const { return m_validPos; }
|
||||
|
@ -66,8 +57,7 @@ namespace search
|
|||
|
||||
private:
|
||||
double m_searchRadiusM;
|
||||
int m_searchMode;
|
||||
Mode m_mode;
|
||||
bool m_forceSearch, m_validPos;
|
||||
};
|
||||
|
||||
} // namespace search
|
||||
|
|
|
@ -25,6 +25,7 @@ HEADERS += \
|
|||
latlon_match.hpp \
|
||||
locality.hpp \
|
||||
locality_finder.hpp \
|
||||
mode.hpp \
|
||||
params.hpp \
|
||||
projection_on_street.hpp \
|
||||
query_saver.hpp \
|
||||
|
@ -72,6 +73,7 @@ SOURCES += \
|
|||
latlon_match.cpp \
|
||||
locality.cpp \
|
||||
locality_finder.cpp \
|
||||
mode.cpp \
|
||||
params.cpp \
|
||||
projection_on_street.cpp \
|
||||
query_saver.cpp \
|
||||
|
|
|
@ -221,7 +221,7 @@ void Engine::PostTask(function<void()> && task)
|
|||
void Engine::DoSearch(SearchParams const & params, m2::RectD const & viewport,
|
||||
shared_ptr<QueryHandle> handle)
|
||||
{
|
||||
bool const viewportSearch = params.HasSearchMode(SearchParams::IN_VIEWPORT_ONLY);
|
||||
bool const viewportSearch = params.GetMode() == Mode::Viewport;
|
||||
|
||||
// Initialize query.
|
||||
m_query->Init(viewportSearch);
|
||||
|
@ -242,7 +242,12 @@ void Engine::DoSearch(SearchParams const & params, m2::RectD const & viewport,
|
|||
else
|
||||
m_query->SetPosition(viewport.Center());
|
||||
|
||||
m_query->SetSearchInWorld(params.HasSearchMode(SearchParams::SEARCH_WORLD));
|
||||
m_query->SetMode(params.GetMode());
|
||||
|
||||
// This flag is needed for consistency with old search algorithm
|
||||
// only. It will gone away when we will remove old search code.
|
||||
m_query->SetSearchInWorld(true);
|
||||
|
||||
m_query->SetInputLocale(params.m_inputLocale);
|
||||
|
||||
ASSERT(!params.m_query.empty(), ());
|
||||
|
|
|
@ -384,7 +384,7 @@ UNIT_TEST(Retrieval_CafeMTV)
|
|||
auto const testWorldId = engine.GetMwmIdByCountryFile(testWorld.GetCountryFile());
|
||||
|
||||
{
|
||||
TestSearchRequest request(engine, "Moscow ", "en", search::SearchParams::ALL, mskViewport);
|
||||
TestSearchRequest request(engine, "Moscow ", "en", search::Mode::Everywhere, mskViewport);
|
||||
request.Wait();
|
||||
|
||||
initializer_list<shared_ptr<MatchingRule>> mskCityAlts = {
|
||||
|
@ -395,7 +395,7 @@ UNIT_TEST(Retrieval_CafeMTV)
|
|||
}
|
||||
|
||||
{
|
||||
TestSearchRequest request(engine, "MTV ", "en", search::SearchParams::ALL, mtvViewport);
|
||||
TestSearchRequest request(engine, "MTV ", "en", search::Mode::Everywhere, mtvViewport);
|
||||
request.Wait();
|
||||
|
||||
initializer_list<shared_ptr<MatchingRule>> mtvCityAlts = {
|
||||
|
@ -406,7 +406,7 @@ UNIT_TEST(Retrieval_CafeMTV)
|
|||
}
|
||||
|
||||
{
|
||||
TestSearchRequest request(engine, "Moscow MTV ", "en", search::SearchParams::ALL, mtvViewport);
|
||||
TestSearchRequest request(engine, "Moscow MTV ", "en", search::Mode::Everywhere, mtvViewport);
|
||||
request.Wait();
|
||||
|
||||
initializer_list<shared_ptr<MatchingRule>> alternatives = {
|
||||
|
|
|
@ -94,7 +94,14 @@ public:
|
|||
|
||||
bool ResultsMatch(string const & query, vector<shared_ptr<MatchingRule>> const & rules)
|
||||
{
|
||||
TestSearchRequest request(m_engine, query, "en", search::SearchParams::ALL, m_viewport);
|
||||
TestSearchRequest request(m_engine, query, "en", search::Mode::Everywhere, m_viewport);
|
||||
request.Wait();
|
||||
return MatchResults(m_engine, rules, request.Results());
|
||||
}
|
||||
|
||||
bool ResultsMatch(string const & query, search::Mode mode, vector<shared_ptr<MatchingRule>> const & rules)
|
||||
{
|
||||
TestSearchRequest request(m_engine, query, "en", mode, m_viewport);
|
||||
request.Wait();
|
||||
return MatchResults(m_engine, rules, request.Results());
|
||||
}
|
||||
|
@ -299,22 +306,37 @@ UNIT_CLASS_TEST(SearchQueryV2Test, SearchByName)
|
|||
TestPark hydePark(vector<m2::PointD>{m2::PointD(0.5, 0.5), m2::PointD(1.5, 0.5),
|
||||
m2::PointD(1.5, 1.5), m2::PointD(0.5, 1.5)},
|
||||
"Hyde Park", "en");
|
||||
TestPOI cafe(m2::PointD(1.0, 1.0), "London Cafe", "en");
|
||||
|
||||
BuildMwm("testWorld", feature::DataHeader::world, [&](TestMwmBuilder & builder)
|
||||
{
|
||||
builder.Add(london);
|
||||
});
|
||||
auto worldId = BuildMwm("testWorld", feature::DataHeader::world, [&](TestMwmBuilder & builder)
|
||||
{
|
||||
builder.Add(london);
|
||||
});
|
||||
auto wonderlandId = BuildMwm("wonderland", feature::DataHeader::country,
|
||||
[&](TestMwmBuilder & builder)
|
||||
{
|
||||
builder.Add(hydePark);
|
||||
builder.Add(cafe);
|
||||
});
|
||||
RegisterCountry("Wonderland", m2::RectD(m2::PointD(0, 0), m2::PointD(2, 2)));
|
||||
|
||||
SetViewport(m2::RectD(m2::PointD(-1.0, -1.0), m2::PointD(-0.9, -0.9)));
|
||||
|
||||
TRules rules = {make_shared<ExactMatch>(wonderlandId, hydePark)};
|
||||
TEST(ResultsMatch("hyde park", rules), ());
|
||||
TEST(ResultsMatch("london hyde park", rules), ());
|
||||
TEST(ResultsMatch("hyde london park", TRules()), ());
|
||||
{
|
||||
TRules rules = {make_shared<ExactMatch>(wonderlandId, hydePark)};
|
||||
TEST(ResultsMatch("hyde park", rules), ());
|
||||
TEST(ResultsMatch("london hyde park", rules), ());
|
||||
TEST(ResultsMatch("hyde london park", TRules()), ());
|
||||
}
|
||||
|
||||
SetViewport(m2::RectD(m2::PointD(0.5, 0.5), m2::PointD(1.5, 1.5)));
|
||||
{
|
||||
TRules rules = {make_shared<ExactMatch>(worldId, london)};
|
||||
TEST(ResultsMatch("london", search::Mode::World, rules), ());
|
||||
}
|
||||
{
|
||||
TRules rules = {make_shared<ExactMatch>(worldId, london),
|
||||
make_shared<ExactMatch>(wonderlandId, cafe)};
|
||||
TEST(ResultsMatch("london", search::Mode::Everywhere, rules), ());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,14 +80,14 @@ UNIT_TEST(GenerateTestMwm_Smoke)
|
|||
TestFeaturesCount(engine, m2::RectD(m2::PointD(-0.5, -0.5), m2::PointD(0.5, 1.5)), 2);
|
||||
|
||||
{
|
||||
TestSearchRequest request(engine, "wine ", "en", search::SearchParams::IN_VIEWPORT_ONLY,
|
||||
TestSearchRequest request(engine, "wine ", "en", search::Mode::Viewport,
|
||||
m2::RectD(m2::PointD(0, 0), m2::PointD(100, 100)));
|
||||
request.Wait();
|
||||
TEST_EQUAL(1, request.Results().size(), ());
|
||||
}
|
||||
|
||||
{
|
||||
TestSearchRequest request(engine, "shop ", "en", search::SearchParams::IN_VIEWPORT_ONLY,
|
||||
TestSearchRequest request(engine, "shop ", "en", search::Mode::Viewport,
|
||||
m2::RectD(m2::PointD(0, 0), m2::PointD(100, 100)));
|
||||
request.Wait();
|
||||
TEST_EQUAL(4, request.Results().size(), ());
|
||||
|
@ -119,19 +119,19 @@ UNIT_TEST(GenerateTestMwm_NotPrefixFreeNames)
|
|||
TestFeaturesCount(engine, m2::RectD(m2::PointD(0, 0), m2::PointD(2, 2)), 6);
|
||||
|
||||
{
|
||||
TestSearchRequest request(engine, "a ", "en", search::SearchParams::IN_VIEWPORT_ONLY,
|
||||
TestSearchRequest request(engine, "a ", "en", search::Mode::Viewport,
|
||||
m2::RectD(m2::PointD(0, 0), m2::PointD(100, 100)));
|
||||
request.Wait();
|
||||
TEST_EQUAL(1, request.Results().size(), ());
|
||||
}
|
||||
{
|
||||
TestSearchRequest request(engine, "aa ", "en", search::SearchParams::IN_VIEWPORT_ONLY,
|
||||
TestSearchRequest request(engine, "aa ", "en", search::Mode::Viewport,
|
||||
m2::RectD(m2::PointD(0, 0), m2::PointD(100, 100)));
|
||||
request.Wait();
|
||||
TEST_EQUAL(2, request.Results().size(), ());
|
||||
}
|
||||
{
|
||||
TestSearchRequest request(engine, "aaa ", "en", search::SearchParams::IN_VIEWPORT_ONLY,
|
||||
TestSearchRequest request(engine, "aaa ", "en", search::Mode::Viewport,
|
||||
m2::RectD(m2::PointD(0, 0), m2::PointD(100, 100)));
|
||||
request.Wait();
|
||||
TEST_EQUAL(3, request.Results().size(), ());
|
||||
|
|
|
@ -231,7 +231,7 @@ int main(int argc, char * argv[])
|
|||
string const & query = queries[i] + " ";
|
||||
my::Timer timer;
|
||||
// todo(@m) Viewport and position should belong to the query info.
|
||||
TestSearchRequest request(engine, query, FLAGS_locale, search::SearchParams::ALL, viewport);
|
||||
TestSearchRequest request(engine, query, FLAGS_locale, search::Mode::Everywhere, viewport);
|
||||
request.Wait();
|
||||
|
||||
responseTimes[i] = timer.ElapsedSeconds();
|
||||
|
|
|
@ -202,6 +202,7 @@ Query::Query(Index & index, CategoriesHolder const & categories, vector<Suggest>
|
|||
, m_locality(&index)
|
||||
#endif
|
||||
, m_position(0, 0)
|
||||
, m_mode(Mode::Everywhere)
|
||||
, m_worldSearch(true)
|
||||
, m_keepHouseNumberInQuery(false)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include "search/intermediate_result.hpp"
|
||||
#include "search/keyword_lang_matcher.hpp"
|
||||
#include "search/mode.hpp"
|
||||
#include "search/retrieval.hpp"
|
||||
#include "search/search_trie.hpp"
|
||||
#include "search/suggest.hpp"
|
||||
|
@ -87,6 +88,7 @@ public:
|
|||
inline string const & GetPivotRegion() const { return m_region; }
|
||||
inline void SetPosition(m2::PointD const & position) { m_position = position; }
|
||||
|
||||
inline void SetMode(Mode mode) { m_mode = mode; }
|
||||
inline void SetSearchInWorld(bool b) { m_worldSearch = b; }
|
||||
|
||||
/// Suggestions language code, not the same as we use in mwm data
|
||||
|
@ -238,6 +240,7 @@ protected:
|
|||
m2::RectD m_viewport[COUNT_V];
|
||||
m2::PointD m_pivot;
|
||||
m2::PointD m_position;
|
||||
Mode m_mode;
|
||||
bool m_worldSearch;
|
||||
Retrieval m_retrieval;
|
||||
|
||||
|
|
|
@ -10,8 +10,7 @@ namespace search
|
|||
namespace tests_support
|
||||
{
|
||||
TestSearchRequest::TestSearchRequest(TestSearchEngine & engine, string const & query,
|
||||
string const & locale, search::SearchParams::SearchModeT mode,
|
||||
m2::RectD const & viewport)
|
||||
string const & locale, Mode mode, m2::RectD const & viewport)
|
||||
: m_done(false)
|
||||
{
|
||||
search::SearchParams params;
|
||||
|
@ -21,7 +20,7 @@ TestSearchRequest::TestSearchRequest(TestSearchEngine & engine, string const & q
|
|||
{
|
||||
Done(results);
|
||||
};
|
||||
params.SetSearchMode(mode);
|
||||
params.SetMode(mode);
|
||||
engine.Search(params, viewport);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ class TestSearchRequest
|
|||
{
|
||||
public:
|
||||
TestSearchRequest(TestSearchEngine & engine, string const & query, string const & locale,
|
||||
search::SearchParams::SearchModeT mode, m2::RectD const & viewport);
|
||||
Mode mode, m2::RectD const & viewport);
|
||||
|
||||
void Wait();
|
||||
|
||||
|
|
|
@ -361,7 +361,7 @@ void UniteCBVs(vector<unique_ptr<coding::CompressedBitVector>> & cbvs)
|
|||
} // namespace
|
||||
|
||||
// Geocoder::Params --------------------------------------------------------------------------------
|
||||
Geocoder::Params::Params() : m_position(0, 0), m_maxNumResults(0) {}
|
||||
Geocoder::Params::Params() : m_mode(Mode::Everywhere), m_position(0, 0), m_maxNumResults(0) {}
|
||||
|
||||
// Geocoder::Geocoder ------------------------------------------------------------------------------
|
||||
Geocoder::Geocoder(Index & index, storage::CountryInfoGetter const & infoGetter)
|
||||
|
@ -795,6 +795,9 @@ void Geocoder::ForEachCountry(vector<shared_ptr<MwmInfo>> const & infos, TFn &&
|
|||
auto const & info = infos[i];
|
||||
if (info->GetType() != MwmInfo::COUNTRY && info->GetType() != MwmInfo::WORLD)
|
||||
continue;
|
||||
if (info->GetType() == MwmInfo::COUNTRY && m_params.m_mode == Mode::World)
|
||||
continue;
|
||||
|
||||
auto handle = m_index.GetMwmHandleById(MwmSet::MwmId(info));
|
||||
if (!handle.IsAlive())
|
||||
continue;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "search/cancel_exception.hpp"
|
||||
#include "search/mode.hpp"
|
||||
#include "search/search_query_params.hpp"
|
||||
#include "search/v2/features_layer.hpp"
|
||||
#include "search/v2/features_layer_path_finder.hpp"
|
||||
|
@ -69,6 +70,7 @@ public:
|
|||
{
|
||||
Params();
|
||||
|
||||
Mode m_mode;
|
||||
m2::RectD m_viewport;
|
||||
/// User's position or viewport center if there is no valid position.
|
||||
m2::PointD m_position;
|
||||
|
|
|
@ -37,6 +37,7 @@ void SearchQueryV2::Search(Results & res, size_t resCount)
|
|||
|
||||
Geocoder::Params params;
|
||||
InitParams(false /* localitySearch */, params);
|
||||
params.m_mode = m_mode;
|
||||
params.m_viewport = m_viewport[CURRENT_V];
|
||||
params.m_position = m_position;
|
||||
params.m_maxNumResults = max(resCount, kPreResultsCount);
|
||||
|
|
Loading…
Add table
Reference in a new issue