Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/search
diff options
context:
space:
mode:
authorYuri Gorshenin <y@maps.me>2016-08-03 13:53:12 +0300
committerYuri Gorshenin <y@maps.me>2016-08-12 18:35:01 +0300
commitb72a10679c823feab5a1789deaabd05618f050ed (patch)
tree86f8167b3ac2af31f506121dcc6dd4918dd9bec5 /search
parentca03f82cad913422aaf67fb97b85c5fc542c0f07 (diff)
[search] Refactored search API.
Diffstat (limited to 'search')
-rw-r--r--search/engine.cpp2
-rw-r--r--search/engine.hpp8
-rw-r--r--search/everywhere_search_params.hpp16
-rw-r--r--search/geocoder.cpp3
-rw-r--r--search/interactive_search_callback.cpp25
-rw-r--r--search/interactive_search_callback.hpp32
-rw-r--r--search/mode.cpp5
-rw-r--r--search/mode.hpp5
-rw-r--r--search/params.hpp70
-rw-r--r--search/processor.hpp8
-rw-r--r--search/processor_factory.hpp2
-rw-r--r--search/ranker.hpp4
-rw-r--r--search/result.cpp6
-rw-r--r--search/result.hpp16
-rw-r--r--search/search.pro10
-rw-r--r--search/search_integration_tests/interactive_search_test.cpp27
-rw-r--r--search/search_integration_tests/processor_test.cpp4
-rw-r--r--search/search_params.cpp (renamed from search/params.cpp)11
-rw-r--r--search/search_params.hpp61
-rw-r--r--search/search_quality/search_quality_tool/search_quality_tool.cpp2
-rw-r--r--search/search_tests_support/test_search_request.cpp5
-rw-r--r--search/search_tests_support/test_search_request.hpp6
-rw-r--r--search/viewport_search_callback.cpp43
-rw-r--r--search/viewport_search_callback.hpp44
-rw-r--r--search/viewport_search_params.hpp19
25 files changed, 253 insertions, 181 deletions
diff --git a/search/engine.cpp b/search/engine.cpp
index 97b63a2ea2..0f8c129a77 100644
--- a/search/engine.cpp
+++ b/search/engine.cpp
@@ -1,8 +1,8 @@
#include "search/engine.hpp"
#include "search/geometry_utils.hpp"
-#include "search/params.hpp"
#include "search/processor.hpp"
+#include "search/search_params.hpp"
#include "storage/country_info_getter.hpp"
diff --git a/search/engine.hpp b/search/engine.hpp
index 4760d9ba68..d46faa5a7e 100644
--- a/search/engine.hpp
+++ b/search/engine.hpp
@@ -1,9 +1,9 @@
#pragma once
-#include "params.hpp"
-#include "processor_factory.hpp"
-#include "result.hpp"
-#include "suggest.hpp"
+#include "search/processor_factory.hpp"
+#include "search/result.hpp"
+#include "search/search_params.hpp"
+#include "search/suggest.hpp"
#include "indexer/categories_holder.hpp"
diff --git a/search/everywhere_search_params.hpp b/search/everywhere_search_params.hpp
new file mode 100644
index 0000000000..f3df639644
--- /dev/null
+++ b/search/everywhere_search_params.hpp
@@ -0,0 +1,16 @@
+#pragma once
+
+#include "search/search_params.hpp"
+
+#include "std/string.hpp"
+
+namespace search
+{
+struct EverywhereSearchParams
+{
+ string m_query;
+ string m_inputLocale;
+
+ SearchParams::TOnResults m_onResults;
+};
+} // namespace search
diff --git a/search/geocoder.cpp b/search/geocoder.cpp
index 8ff1add25c..cea3c3f4f9 100644
--- a/search/geocoder.cpp
+++ b/search/geocoder.cpp
@@ -411,6 +411,7 @@ void UniteCBVs(vector<CBV> & cbvs)
// Geocoder::Params --------------------------------------------------------------------------------
Geocoder::Params::Params() : m_mode(Mode::Everywhere) {}
+
// Geocoder::Geocoder ------------------------------------------------------------------------------
Geocoder::Geocoder(Index const & index, storage::CountryInfoGetter const & infoGetter,
PreRanker & preRanker, my::Cancellable const & cancellable)
@@ -850,7 +851,7 @@ 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)
+ if (info->GetType() == MwmInfo::COUNTRY && m_params.m_mode == Mode::Downloader)
continue;
auto handle = m_index.GetMwmHandleById(MwmSet::MwmId(info));
diff --git a/search/interactive_search_callback.cpp b/search/interactive_search_callback.cpp
deleted file mode 100644
index d7981bab4d..0000000000
--- a/search/interactive_search_callback.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#include "search/interactive_search_callback.hpp"
-
-#include "search/result.hpp"
-
-namespace search
-{
-InteractiveSearchCallback::InteractiveSearchCallback(TSetDisplacementMode && setMode,
- TOnResults && onResults)
- : m_setMode(move(setMode)), m_onResults(move(onResults)), m_hotelsModeSet(false)
-{
-}
-
-void InteractiveSearchCallback::operator()(search::Results const & results)
-{
- m_hotelsClassif.AddBatch(results);
-
- if (!m_hotelsModeSet && m_hotelsClassif.IsHotelQuery())
- {
- m_setMode();
- m_hotelsModeSet = true;
- }
-
- m_onResults(results);
-}
-} // namespace search
diff --git a/search/interactive_search_callback.hpp b/search/interactive_search_callback.hpp
deleted file mode 100644
index 8d42f537a0..0000000000
--- a/search/interactive_search_callback.hpp
+++ /dev/null
@@ -1,32 +0,0 @@
-#pragma once
-
-#include "search/hotels_classifier.hpp"
-#include "search/params.hpp"
-
-#include "std/function.hpp"
-
-namespace search
-{
-class Results;
-
-// An on-results-callback that should be used for interactive search.
-//
-// *NOTE* the class is NOT thread safe.
-class InteractiveSearchCallback
-{
-public:
- using TSetDisplacementMode = function<void()>;
- using TOnResults = search::TOnResults;
-
- InteractiveSearchCallback(TSetDisplacementMode && setMode, TOnResults && onResults);
-
- void operator()(search::Results const & results);
-
-private:
- TSetDisplacementMode m_setMode;
- TOnResults m_onResults;
-
- search::HotelsClassifier m_hotelsClassif;
- bool m_hotelsModeSet;
-};
-} // namespace search
diff --git a/search/mode.cpp b/search/mode.cpp
index 59c7eb751b..bd2bdc8c81 100644
--- a/search/mode.cpp
+++ b/search/mode.cpp
@@ -6,9 +6,10 @@ string DebugPrint(Mode mode)
{
switch (mode)
{
- case Mode::Viewport: return "Viewport";
case Mode::Everywhere: return "Everywhere";
- case Mode::World: return "World";
+ case Mode::Viewport: return "Viewport";
+ case Mode::Downloader: return "Downloader";
+ case Mode::Count: return "Count";
}
return "Unknown";
}
diff --git a/search/mode.hpp b/search/mode.hpp
index 0b3b00cfbe..d5e6dabf10 100644
--- a/search/mode.hpp
+++ b/search/mode.hpp
@@ -6,9 +6,10 @@ namespace search
{
enum class Mode
{
- Viewport,
Everywhere,
- World
+ Viewport,
+ Downloader,
+ Count
};
string DebugPrint(Mode mode);
diff --git a/search/params.hpp b/search/params.hpp
deleted file mode 100644
index 0c688a1e3b..0000000000
--- a/search/params.hpp
+++ /dev/null
@@ -1,70 +0,0 @@
-#pragma once
-
-#include "search/mode.hpp"
-
-#include "geometry/point2d.hpp"
-#include "geometry/rect2d.hpp"
-
-#include "std/function.hpp"
-#include "std/string.hpp"
-
-
-namespace search
-{
- class Results;
-
- using TOnStarted = function<void()>;
- using TOnResults = function<void (Results const &)>;
-
- class SearchParams
- {
- public:
- SearchParams();
-
- /// @name Force run search without comparing with previous search params.
- //@{
- void SetForceSearch(bool b) { m_forceSearch = b; }
- bool IsForceSearch() const { return m_forceSearch; }
- //@}
-
- inline void SetMode(Mode mode) { m_mode = mode; }
- inline Mode GetMode() const { return m_mode; }
-
- void SetPosition(double lat, double lon);
- inline bool IsValidPosition() const { return m_validPos; }
- inline bool IsSearchAroundPosition() const
- {
- return (m_searchRadiusM > 0 && IsValidPosition());
- }
-
- inline void SetSearchRadiusMeters(double radiusM) { m_searchRadiusM = radiusM; }
- bool GetSearchRect(m2::RectD & rect) const;
-
- /// @param[in] locale can be "fr", "en-US", "ru_RU" etc.
- inline void SetInputLocale(string const & locale) { m_inputLocale = locale; }
-
- inline void SetSuggestsEnabled(bool enabled) { m_suggestsEnabled = enabled; }
- inline bool GetSuggestsEnabled() const { return m_suggestsEnabled; }
-
- bool IsEqualCommon(SearchParams const & rhs) const;
-
- inline void Clear() { m_query.clear(); }
-
- TOnStarted m_onStarted;
- TOnResults m_onResults;
-
- string m_query;
- string m_inputLocale;
-
- double m_lat, m_lon;
-
- friend string DebugPrint(SearchParams const & params);
-
- private:
- double m_searchRadiusM;
- Mode m_mode;
- bool m_forceSearch;
- bool m_validPos;
- bool m_suggestsEnabled;
- };
-} // namespace search
diff --git a/search/processor.hpp b/search/processor.hpp
index ddc340556e..d28c43c4ab 100644
--- a/search/processor.hpp
+++ b/search/processor.hpp
@@ -1,10 +1,10 @@
#pragma once
#include "search/geocoder.hpp"
#include "search/mode.hpp"
-#include "search/params.hpp"
#include "search/pre_ranker.hpp"
-#include "search/ranker.hpp"
#include "search/rank_table_cache.hpp"
+#include "search/ranker.hpp"
+#include "search/search_params.hpp"
#include "search/search_trie.hpp"
#include "search/suggest.hpp"
#include "search/token_slice.hpp"
@@ -84,7 +84,7 @@ public:
inline void SetMode(Mode mode) { m_mode = mode; }
inline void SetSuggestsEnabled(bool enabled) { m_suggestsEnabled = enabled; }
inline void SetPosition(m2::PointD const & position) { m_position = position; }
- inline void SetOnResults(TOnResults const & onResults) { m_onResults = onResults; }
+ inline void SetOnResults(SearchParams::TOnResults const & onResults) { m_onResults = onResults; }
inline string const & GetPivotRegion() const { return m_region; }
inline m2::PointD const & GetPosition() const { return m_position; }
@@ -152,7 +152,7 @@ protected:
m2::PointD m_position;
Mode m_mode;
bool m_suggestsEnabled;
- TOnResults m_onResults;
+ SearchParams::TOnResults m_onResults;
/// @name Get ranking params.
//@{
diff --git a/search/processor_factory.hpp b/search/processor_factory.hpp
index 4eeb8cec74..b8946f6d23 100644
--- a/search/processor_factory.hpp
+++ b/search/processor_factory.hpp
@@ -1,7 +1,7 @@
#pragma once
-#include "search/params.hpp"
#include "search/processor.hpp"
+#include "search/search_params.hpp"
#include "search/suggest.hpp"
#include "std/unique_ptr.hpp"
diff --git a/search/ranker.hpp b/search/ranker.hpp
index fbea55b50c..9f81147177 100644
--- a/search/ranker.hpp
+++ b/search/ranker.hpp
@@ -6,9 +6,9 @@
#include "search/keyword_lang_matcher.hpp"
#include "search/locality_finder.hpp"
#include "search/mode.hpp"
-#include "search/params.hpp"
#include "search/result.hpp"
#include "search/reverse_geocoder.hpp"
+#include "search/search_params.hpp"
#include "search/suggest.hpp"
#include "indexer/categories_holder.hpp"
@@ -62,7 +62,7 @@ public:
TLocales m_categoryLocales;
size_t m_limit = 0;
- TOnResults m_onResults;
+ SearchParams::TOnResults m_onResults;
};
static size_t const kBatchSize;
diff --git a/search/result.cpp b/search/result.cpp
index 0fad1be9e5..6a9a00f3cc 100644
--- a/search/result.cpp
+++ b/search/result.cpp
@@ -319,10 +319,10 @@ string DebugPrint(AddressInfo const & info)
return info.FormatNameAndAddress();
}
-string DebugPrint(Result const & r)
+string DebugPrint(Result const & result)
{
- return "Result { Name: " + r.GetString() + "; Type: " + r.GetFeatureType() +
- "; Info: " + DebugPrint(r.GetRankingInfo()) + " }";
+ return "Result { Name: " + result.GetString() + "; Type: " + result.GetFeatureType() +
+ "; Info: " + DebugPrint(result.GetRankingInfo()) + " }";
}
} // namespace search
diff --git a/search/result.hpp b/search/result.hpp
index e541c9b1f4..916d28726d 100644
--- a/search/result.hpp
+++ b/search/result.hpp
@@ -15,7 +15,6 @@
namespace search
{
-
// Search result. Search returns a list of them, ordered by score.
class Result
{
@@ -152,14 +151,14 @@ class Results
public:
Results() : m_status(NONE) {}
- /// @name To implement end of search notification.
- //@{
static Results GetEndMarker(bool isCancelled) { return Results(isCancelled); }
+
bool IsEndMarker() const { return (m_status != NONE); }
bool IsEndedNormal() const { return (m_status == ENDED); }
- //@}
+ bool IsEndedCancelled() const { return m_status == ENDED_CANCELLED; }
bool AddResult(Result && res);
+
/// Fast function that don't do any duplicates checks.
/// Used in viewport search only.
void AddResultNoChecks(Result && res)
@@ -172,8 +171,6 @@ public:
inline void Clear() { m_vec.clear(); }
typedef vector<Result>::const_iterator IterT;
- inline IterT Begin() const { return m_vec.begin(); }
- inline IterT End() const { return m_vec.end(); }
inline IterT begin() const { return m_vec.begin(); }
inline IterT end() const { return m_vec.end(); }
@@ -221,11 +218,10 @@ struct AddressInfo
// Caroline, 7 vulica Frunze, Minsk, Belarus
string FormatNameAndAddress(AddressType type = DEFAULT) const;
- friend string DebugPrint(AddressInfo const & info);
-
void Clear();
-};
-string DebugPrint(search::Result const &);
+ friend string DebugPrint(AddressInfo const & info);
+};
+string DebugPrint(search::Result const & result);
} // namespace search
diff --git a/search/search.pro b/search/search.pro
index 3f50c1dadf..6827455004 100644
--- a/search/search.pro
+++ b/search/search.pro
@@ -16,6 +16,7 @@ HEADERS += \
common.hpp \
dummy_rank_table.hpp \
engine.hpp \
+ everywhere_search_params.hpp \
feature_offset_match.hpp \
features_filter.hpp \
features_layer.hpp \
@@ -29,7 +30,6 @@ HEADERS += \
house_detector.hpp \
house_numbers_matcher.hpp \
house_to_street_table.hpp \
- interactive_search_callback.hpp \
intermediate_result.hpp \
intersection_result.hpp \
interval_set.hpp \
@@ -44,7 +44,6 @@ HEADERS += \
model.hpp \
mwm_context.hpp \
nested_rects_cache.hpp \
- params.hpp \
pre_ranker.hpp \
pre_ranking_info.hpp \
processor.hpp \
@@ -61,6 +60,7 @@ HEADERS += \
retrieval.hpp \
reverse_geocoder.hpp \
search_index_values.hpp \
+ search_params.hpp \
search_trie.hpp \
stats_cache.hpp \
street_vicinity_loader.hpp \
@@ -70,6 +70,8 @@ HEADERS += \
token_slice.hpp \
types_skipper.hpp \
utils.hpp \
+ viewport_search_callback.hpp \
+ viewport_search_params.hpp
SOURCES += \
approximate_string_match.cpp \
@@ -88,7 +90,6 @@ SOURCES += \
house_detector.cpp \
house_numbers_matcher.cpp \
house_to_street_table.cpp \
- interactive_search_callback.cpp \
intermediate_result.cpp \
intersection_result.cpp \
keyword_lang_matcher.cpp \
@@ -102,7 +103,6 @@ SOURCES += \
model.cpp \
mwm_context.cpp \
nested_rects_cache.cpp \
- params.cpp \
pre_ranker.cpp \
pre_ranking_info.cpp \
processor.cpp \
@@ -117,7 +117,9 @@ SOURCES += \
result.cpp \
retrieval.cpp \
reverse_geocoder.cpp \
+ search_params.cpp \
street_vicinity_loader.cpp \
streets_matcher.cpp \
token_slice.cpp \
types_skipper.cpp \
+ viewport_search_callback.cpp
diff --git a/search/search_integration_tests/interactive_search_test.cpp b/search/search_integration_tests/interactive_search_test.cpp
index d7b28ac138..f344973861 100644
--- a/search/search_integration_tests/interactive_search_test.cpp
+++ b/search/search_integration_tests/interactive_search_test.cpp
@@ -2,7 +2,7 @@
#include "generator/generator_tests_support/test_feature.hpp"
-#include "search/interactive_search_callback.hpp"
+#include "search/viewport_search_callback.hpp"
#include "search/mode.hpp"
#include "search/search_integration_tests/helpers.hpp"
#include "search/search_tests_support/test_results_matching.hpp"
@@ -37,16 +37,33 @@ public:
}
};
-class InteractiveSearchRequest : public TestSearchRequest
+class TestDelegate : public ViewportSearchCallback::Delegate
+{
+public:
+ TestDelegate(bool & mode) : m_mode(mode) {}
+
+ // ViewportSearchCallback::Delegate overrides:
+ void RunUITask(function<void()> /* fn */) override {}
+ void SetHotelDisplacementMode() override { m_mode = true; }
+ bool IsViewportSearchActive() const override { return true; }
+ void ShowViewportSearchResults(Results const & /* results */) override {}
+ void ClearViewportSearchResults() override {}
+
+ private:
+ bool & m_mode;
+};
+
+class InteractiveSearchRequest : public TestDelegate, public TestSearchRequest
{
public:
InteractiveSearchRequest(TestSearchEngine & engine, string const & query,
m2::RectD const & viewport, bool & mode)
- : TestSearchRequest(
+ : TestDelegate(mode)
+ , TestSearchRequest(
engine, query, "en" /* locale */, Mode::Viewport, viewport,
bind(&InteractiveSearchRequest::OnStarted, this),
- InteractiveSearchCallback([&mode]() { mode = true; },
- bind(&InteractiveSearchRequest::OnResults, this, _1)))
+ ViewportSearchCallback(static_cast<ViewportSearchCallback::Delegate &>(*this),
+ bind(&InteractiveSearchRequest::OnResults, this, _1)))
{
}
};
diff --git a/search/search_integration_tests/processor_test.cpp b/search/search_integration_tests/processor_test.cpp
index 93d979cfa0..1797aa81bc 100644
--- a/search/search_integration_tests/processor_test.cpp
+++ b/search/search_integration_tests/processor_test.cpp
@@ -267,7 +267,7 @@ UNIT_CLASS_TEST(ProcessorTest, SearchByName)
SetViewport(m2::RectD(m2::PointD(0.5, 0.5), m2::PointD(1.5, 1.5)));
{
TRules rules = {ExactMatch(worldId, london)};
- TEST(ResultsMatch("london", Mode::World, rules), ());
+ TEST(ResultsMatch("london", Mode::Downloader, rules), ());
}
{
TRules rules = {ExactMatch(worldId, london), ExactMatch(wonderlandId, cafe)};
@@ -291,7 +291,7 @@ UNIT_CLASS_TEST(ProcessorTest, DisableSuggests)
SearchParams params;
params.m_query = "londo";
params.m_inputLocale = "en";
- params.SetMode(Mode::World);
+ params.SetMode(Mode::Downloader);
params.SetSuggestsEnabled(false);
TestSearchRequest request(m_engine, params, m_viewport);
diff --git a/search/params.cpp b/search/search_params.cpp
index fa47eb86c7..aa8d490dd9 100644
--- a/search/params.cpp
+++ b/search/search_params.cpp
@@ -1,10 +1,9 @@
-#include "params.hpp"
+#include "search/search_params.hpp"
#include "geometry/mercator.hpp"
#include "coding/multilang_utf8_string.hpp"
-
namespace search
{
SearchParams::SearchParams()
@@ -37,10 +36,8 @@ bool SearchParams::GetSearchRect(m2::RectD & rect) const
bool SearchParams::IsEqualCommon(SearchParams const & rhs) const
{
- return (m_query == rhs.m_query &&
- m_inputLocale == rhs.m_inputLocale &&
- m_validPos == rhs.m_validPos &&
- m_mode == rhs.m_mode &&
+ return (m_query == rhs.m_query && m_inputLocale == rhs.m_inputLocale &&
+ m_validPos == rhs.m_validPos && m_mode == rhs.m_mode &&
m_searchRadiusM == rhs.m_searchRadiusM);
}
@@ -51,4 +48,4 @@ string DebugPrint(SearchParams const & params)
<< ", Mode = " << DebugPrint(params.m_mode) << " }";
return ss.str();
}
-} // namespace search
+} // namespace search
diff --git a/search/search_params.hpp b/search/search_params.hpp
new file mode 100644
index 0000000000..d3de882ee9
--- /dev/null
+++ b/search/search_params.hpp
@@ -0,0 +1,61 @@
+#pragma once
+
+#include "search/mode.hpp"
+
+#include "geometry/point2d.hpp"
+#include "geometry/rect2d.hpp"
+
+#include "std/function.hpp"
+#include "std/string.hpp"
+
+namespace search
+{
+class Results;
+
+class SearchParams
+{
+public:
+ using TOnStarted = function<void()>;
+ using TOnResults = function<void(Results const &)>;
+
+ SearchParams();
+
+ /// @name Force run search without comparing with previous search params.
+ //@{
+ void SetForceSearch(bool b) { m_forceSearch = b; }
+ bool IsForceSearch() const { return m_forceSearch; }
+ //@}
+
+ inline void SetMode(Mode mode) { m_mode = mode; }
+ inline Mode GetMode() const { return m_mode; }
+ void SetPosition(double lat, double lon);
+ inline bool IsValidPosition() const { return m_validPos; }
+ inline bool IsSearchAroundPosition() const { return (m_searchRadiusM > 0 && IsValidPosition()); }
+ inline void SetSearchRadiusMeters(double radiusM) { m_searchRadiusM = radiusM; }
+ bool GetSearchRect(m2::RectD & rect) const;
+
+ /// @param[in] locale can be "fr", "en-US", "ru_RU" etc.
+ inline void SetInputLocale(string const & locale) { m_inputLocale = locale; }
+ inline void SetSuggestsEnabled(bool enabled) { m_suggestsEnabled = enabled; }
+ inline bool GetSuggestsEnabled() const { return m_suggestsEnabled; }
+ bool IsEqualCommon(SearchParams const & rhs) const;
+
+ inline void Clear() { m_query.clear(); }
+ TOnStarted m_onStarted;
+ TOnResults m_onResults;
+
+ string m_query;
+ string m_inputLocale;
+
+ double m_lat, m_lon;
+
+ friend string DebugPrint(SearchParams const & params);
+
+private:
+ double m_searchRadiusM;
+ Mode m_mode;
+ bool m_forceSearch;
+ bool m_validPos;
+ bool m_suggestsEnabled;
+};
+} // namespace search
diff --git a/search/search_quality/search_quality_tool/search_quality_tool.cpp b/search/search_quality/search_quality_tool/search_quality_tool.cpp
index 19b06c93e6..5be0d527ea 100644
--- a/search/search_quality/search_quality_tool/search_quality_tool.cpp
+++ b/search/search_quality/search_quality_tool/search_quality_tool.cpp
@@ -1,4 +1,4 @@
-#include "search/params.hpp"
+#include "search/search_params.hpp"
#include "indexer/classificator_loader.hpp"
#include "indexer/data_header.hpp"
diff --git a/search/search_tests_support/test_search_request.cpp b/search/search_tests_support/test_search_request.cpp
index 1c7f50d3ac..fc0b99c90c 100644
--- a/search/search_tests_support/test_search_request.cpp
+++ b/search/search_tests_support/test_search_request.cpp
@@ -31,7 +31,8 @@ TestSearchRequest::TestSearchRequest(TestSearchEngine & engine, SearchParams par
TestSearchRequest::TestSearchRequest(TestSearchEngine & engine, string const & query,
string const & locale, Mode mode, m2::RectD const & viewport,
- TOnStarted onStarted, TOnResults onResults)
+ SearchParams::TOnStarted onStarted,
+ SearchParams::TOnResults onResults)
{
SearchParams params;
params.m_query = query;
@@ -88,7 +89,7 @@ void TestSearchRequest::OnResults(search::Results const & results)
}
else
{
- m_results.assign(results.Begin(), results.End());
+ m_results.assign(results.begin(), results.end());
}
}
} // namespace tests_support
diff --git a/search/search_tests_support/test_search_request.hpp b/search/search_tests_support/test_search_request.hpp
index 4b86d5a3e2..5da71d2336 100644
--- a/search/search_tests_support/test_search_request.hpp
+++ b/search/search_tests_support/test_search_request.hpp
@@ -2,8 +2,8 @@
#include "geometry/rect2d.hpp"
-#include "search/params.hpp"
#include "search/result.hpp"
+#include "search/search_params.hpp"
#include "std/condition_variable.hpp"
#include "std/mutex.hpp"
@@ -36,8 +36,8 @@ public:
protected:
TestSearchRequest(TestSearchEngine & engine, string const & query, string const & locale,
- Mode mode, m2::RectD const & viewport, TOnStarted onStarted,
- TOnResults onResults);
+ Mode mode, m2::RectD const & viewport, SearchParams::TOnStarted onStarted,
+ SearchParams::TOnResults onResults);
void SetUpCallbacks(SearchParams & params);
diff --git a/search/viewport_search_callback.cpp b/search/viewport_search_callback.cpp
new file mode 100644
index 0000000000..6fce48768b
--- /dev/null
+++ b/search/viewport_search_callback.cpp
@@ -0,0 +1,43 @@
+#include "search/viewport_search_callback.hpp"
+
+#include "search/result.hpp"
+
+namespace search
+{
+ViewportSearchCallback::ViewportSearchCallback(Delegate & delegate, TOnResults onResults)
+ : m_delegate(delegate), m_onResults(move(onResults)), m_hotelsModeSet(false), m_firstCall(true)
+{
+}
+
+void ViewportSearchCallback::operator()(Results const & results)
+{
+ m_hotelsClassif.AddBatch(results);
+
+ if (!m_hotelsModeSet && m_hotelsClassif.IsHotelQuery())
+ {
+ m_delegate.SetHotelDisplacementMode();
+ m_hotelsModeSet = true;
+ }
+
+ if (!results.IsEndMarker())
+ {
+ auto & delegate = m_delegate;
+ bool const firstCall = m_firstCall;
+
+ m_delegate.RunUITask([&delegate, firstCall, results]() {
+ if (!delegate.IsViewportSearchActive())
+ return;
+
+ if (firstCall)
+ delegate.ClearViewportSearchResults();
+
+ delegate.ShowViewportSearchResults(results);
+ });
+ }
+
+ if (m_onResults)
+ m_onResults(results);
+
+ m_firstCall = false;
+}
+} // namespace search
diff --git a/search/viewport_search_callback.hpp b/search/viewport_search_callback.hpp
new file mode 100644
index 0000000000..ffc4c25c02
--- /dev/null
+++ b/search/viewport_search_callback.hpp
@@ -0,0 +1,44 @@
+#pragma once
+
+#include "search/hotels_classifier.hpp"
+#include "search/search_params.hpp"
+
+#include "std/function.hpp"
+
+namespace search
+{
+class Results;
+
+// An on-results-callback that should be used for interactive search.
+//
+// *NOTE* the class is NOT thread safe.
+class ViewportSearchCallback
+{
+public:
+ class Delegate
+ {
+ public:
+ virtual ~Delegate() = default;
+
+ virtual void RunUITask(function<void()> fn) = 0;
+ virtual void SetHotelDisplacementMode() = 0;
+ virtual bool IsViewportSearchActive() const = 0;
+ virtual void ShowViewportSearchResults(Results const & results) = 0;
+ virtual void ClearViewportSearchResults() = 0;
+ };
+
+ using TOnResults = SearchParams::TOnResults;
+
+ ViewportSearchCallback(Delegate & delegate, TOnResults onResults);
+
+ void operator()(Results const & results);
+
+private:
+ Delegate & m_delegate;
+ TOnResults m_onResults;
+
+ HotelsClassifier m_hotelsClassif;
+ bool m_hotelsModeSet;
+ bool m_firstCall;
+};
+} // namespace search
diff --git a/search/viewport_search_params.hpp b/search/viewport_search_params.hpp
new file mode 100644
index 0000000000..5067ef5eb4
--- /dev/null
+++ b/search/viewport_search_params.hpp
@@ -0,0 +1,19 @@
+#pragma once
+
+#include "std/function.hpp"
+#include "std/string.hpp"
+
+namespace search
+{
+struct ViewportSearchParams
+{
+ using TOnStarted = function<void()>;
+ using TOnCompleted = function<void()>;
+
+ string m_query;
+ string m_inputLocale;
+
+ TOnStarted m_onStarted;
+ TOnCompleted m_onCompleted;
+};
+} // namespace search