[search] Added m_needAddress and m_needHighlight to SearchParams.

This commit is contained in:
Yuri Gorshenin 2017-10-31 12:19:46 +03:00 committed by mpimenov
parent fa69cb0ab3
commit 6c26f7b97c
16 changed files with 167 additions and 193 deletions

View file

@ -82,6 +82,7 @@
#include "geometry/any_rect2d.hpp"
#include "geometry/distance_on_sphere.hpp"
#include "geometry/latlon.hpp"
#include "geometry/mercator.hpp"
#include "geometry/rect2d.hpp"
#include "geometry/tree4d.hpp"
#include "geometry/triangle2d.hpp"
@ -1343,8 +1344,11 @@ bool Framework::SearchEverywhere(search::EverywhereSearchParams const & params)
p.m_inputLocale = params.m_inputLocale;
p.m_mode = search::Mode::Everywhere;
SetViewportIfPossible(p); // Search request will be delayed if viewport is not available.
p.m_maxNumResults = search::SearchParams::kDefaultNumResultsEverywhere;
p.m_forceSearch = true;
p.m_suggestsEnabled = true;
p.m_needAddress = true;
p.m_needHighlight = true;
p.m_hotelsFilter = params.m_hotelsFilter;
p.m_cianMode = IsCianMode(params.m_query);
@ -1369,9 +1373,12 @@ bool Framework::SearchInViewport(search::ViewportSearchParams const & params)
p.m_query = params.m_query;
p.m_inputLocale = params.m_inputLocale;
SetViewportIfPossible(p); // Search request will be delayed if viewport is not available.
p.m_maxNumResults = search::SearchParams::kDefaultNumResultsInViewport;
p.m_mode = search::Mode::Viewport;
p.m_forceSearch = false;
p.m_suggestsEnabled = false;
p.m_needAddress = false;
p.m_needHighlight = false;
p.m_hotelsFilter = params.m_hotelsFilter;
p.m_cianMode = m_cianSearchMode;
@ -1397,9 +1404,12 @@ bool Framework::SearchInDownloader(DownloaderSearchParams const & params)
p.m_query = params.m_query;
p.m_inputLocale = params.m_inputLocale;
SetViewportIfPossible(p); // Search request will be delayed if viewport is not available.
p.m_maxNumResults = search::SearchParams::kDefaultNumResultsEverywhere;
p.m_mode = search::Mode::Downloader;
p.m_forceSearch = true;
p.m_suggestsEnabled = false;
p.m_needAddress = false;
p.m_needHighlight = false;
p.m_onResults = search::DownloaderSearchCallback(
static_cast<search::DownloaderSearchCallback::Delegate &>(*this), m_model.GetIndex(),
GetCountryInfoGetter(), GetStorage(), params);
@ -1668,7 +1678,7 @@ void Framework::SetCurrentPositionIfPossible(search::SearchParams & params)
double lat;
double lon;
if (GetCurrentPosition(lat, lon))
params.SetPosition(ms::LatLon(lat, lon));
params.m_position = MercatorBounds::FromLatLon(lat, lon);
}
bool Framework::QueryMayBeSkipped(SearchIntent const & intent,
@ -1689,14 +1699,14 @@ bool Framework::QueryMayBeSkipped(SearchIntent const & intent,
return false;
}
if (lastParams.IsValidPosition() && params.IsValidPosition() &&
ms::DistanceOnEarth(lastParams.GetPositionLatLon(), params.GetPositionLatLon()) >
if (lastParams.m_position && params.m_position &&
MercatorBounds::DistanceOnEarth(*lastParams.m_position, *params.m_position) >
kDistEqualQueryMeters)
{
return false;
}
if (lastParams.IsValidPosition() != params.IsValidPosition())
if (static_cast<bool>(lastParams.m_position) != static_cast<bool>(params.m_position))
return false;
if (!search::hotels_filter::Rule::IsIdentical(lastParams.m_hotelsFilter, params.m_hotelsFilter))

View file

@ -225,15 +225,9 @@ void Engine::PostMessage(TArgs &&... args)
void Engine::DoSearch(SearchParams const & params, shared_ptr<ProcessorHandle> handle,
Processor & processor)
{
bool const viewportSearch = params.m_mode == Mode::Viewport;
processor.Reset();
processor.Init(viewportSearch);
handle->Attach(processor);
MY_SCOPE_GUARD(detach, [&handle]
{
handle->Detach();
});
MY_SCOPE_GUARD(detach, [&handle] { handle->Detach(); });
processor.Search(params);
}

View file

@ -2,7 +2,6 @@
#include "search/hotels_filter.hpp"
#include "search/result.hpp"
#include "search/search_params.hpp"
#include <functional>
#include <memory>

View file

@ -41,8 +41,8 @@ void SweepNearbyResults(double eps, vector<PreRankerResult> & results)
}
} // namespace
PreRanker::PreRanker(Index const & index, Ranker & ranker, size_t limit)
: m_index(index), m_ranker(ranker), m_limit(limit), m_pivotFeatures(index)
PreRanker::PreRanker(Index const & index, Ranker & ranker)
: m_index(index), m_ranker(ranker), m_pivotFeatures(index)
{
}
@ -196,7 +196,7 @@ void PreRanker::Filter(bool viewportSearch)
void PreRanker::UpdateResults(bool lastUpdate)
{
FillMissingFieldsInPreResults();
Filter(m_viewportSearch);
Filter(m_params.m_viewportSearch);
m_numSentResults += m_results.size();
m_ranker.SetPreRankerResults(move(m_results));
m_results.clear();

View file

@ -43,18 +43,21 @@ public:
int m_scale = 0;
size_t m_batchSize = 100;
// The maximum total number of results to be emitted in all batches.
size_t m_limit = 0;
bool m_viewportSearch = false;
};
PreRanker(Index const & index, Ranker & ranker, size_t limit);
PreRanker(Index const & index, Ranker & ranker);
void Init(Params const & params);
inline void SetViewportSearch(bool viewportSearch) { m_viewportSearch = viewportSearch; }
template <typename... TArgs>
void Emplace(TArgs &&... args)
{
if (m_numSentResults >= m_limit)
if (m_numSentResults >= Limit())
return;
m_results.emplace_back(forward<TArgs>(args)...);
}
@ -72,7 +75,7 @@ public:
inline size_t Size() const { return m_results.size(); }
inline size_t BatchSize() const { return m_params.m_batchSize; }
inline size_t NumSentResults() const { return m_numSentResults; }
inline size_t Limit() const { return m_limit; }
inline size_t Limit() const { return m_params.m_limit; }
template <typename TFn>
void ForEach(TFn && fn)
@ -88,9 +91,7 @@ private:
Index const & m_index;
Ranker & m_ranker;
vector<PreRankerResult> m_results;
size_t const m_limit;
Params m_params;
bool m_viewportSearch = false;
// Amount of results sent up the pipeline.
size_t m_numSentResults = 0;

View file

@ -5,6 +5,7 @@
#include "search/geometry_utils.hpp"
#include "search/intermediate_result.hpp"
#include "search/latlon_match.hpp"
#include "search/mode.hpp"
#include "search/pre_ranking_info.hpp"
#include "search/query_params.hpp"
#include "search/ranking_info.hpp"
@ -95,9 +96,9 @@ void SendStatistics(SearchParams const & params, m2::RectD const & viewport, Res
resultString.append("\t" + res[i].ToStringForStats());
string posX, posY;
if (params.IsValidPosition())
if (params.m_position)
{
auto const position = params.GetPositionMercator();
auto const position = *params.m_position;
posX = strings::to_string(position.x);
posY = strings::to_string(position.y);
}
@ -156,10 +157,9 @@ void RemoveStopWordsIfNeeded(QueryParams & params)
// static
size_t const Processor::kPreResultsCount = 200;
// static
double const Processor::kMinViewportRadiusM = 5.0 * 1000;
double const Processor::kMaxViewportRadiusM = 50.0 * 1000;
double const Processor::kMinDistanceOnMapBetweenResultsM = 100.0;
Processor::Processor(Index const & index, CategoriesHolder const & categories,
vector<Suggest> const & suggests,
@ -167,16 +167,12 @@ Processor::Processor(Index const & index, CategoriesHolder const & categories,
: m_categories(categories)
, m_infoGetter(infoGetter)
, m_position(0, 0)
, m_minDistanceOnMapBetweenResults(0.0)
, m_mode(Mode::Everywhere)
, m_suggestsEnabled(true)
, m_viewportSearch(false)
, m_villagesCache(static_cast<my::Cancellable const &>(*this))
, m_citiesBoundaries(index)
, m_keywordsScorer(LanguageTier::LANGUAGE_TIER_COUNT)
, m_ranker(index, m_citiesBoundaries, infoGetter, m_keywordsScorer, m_emitter, categories,
suggests, m_villagesCache, static_cast<my::Cancellable const &>(*this))
, m_preRanker(index, m_ranker, kPreResultsCount)
, m_preRanker(index, m_ranker)
, m_geocoder(index, infoGetter, m_preRanker, m_villagesCache,
static_cast<my::Cancellable const &>(*this))
{
@ -190,13 +186,6 @@ Processor::Processor(Index const & index, CategoriesHolder const & categories,
SetPreferredLocale("en");
}
void Processor::Init(bool viewportSearch)
{
m_tokens.clear();
m_prefix.clear();
m_preRanker.SetViewportSearch(viewportSearch);
}
void Processor::SetViewport(m2::RectD const & viewport)
{
ASSERT(viewport.IsValid(), ());
@ -242,10 +231,8 @@ void Processor::SetInputLocale(string const & locale)
void Processor::SetQuery(string const & query)
{
m_query = query;
/// @todo Why Init is separated with SetQuery?
ASSERT(m_tokens.empty(), ());
ASSERT(m_prefix.empty(), ());
m_tokens.clear();
m_prefix.clear();
// Following code splits input query by delimiters except hash tags
// first, and then splits result tokens by hashtags. The goal is to
@ -307,33 +294,34 @@ void Processor::SetQuery(string const & query)
});
}
void Processor::SetRankPivot(m2::PointD const & pivot)
void Processor::SetLanguage(int id, int8_t lang)
{
if (!m2::AlmostEqualULPs(pivot, m_pivot))
{
storage::CountryInfo ci;
m_infoGetter.GetRegionInfo(pivot, ci);
m_region.swap(ci.m_name);
}
m_pivot = pivot;
m_keywordsScorer.SetLanguage(GetLangIndex(id), lang);
}
m2::PointD Processor::GetPivotPoint() const
int8_t Processor::GetLanguage(int id) const
{
bool const viewportSearch = m_mode == Mode::Viewport;
return m_keywordsScorer.GetLanguage(GetLangIndex(id));
}
m2::PointD Processor::GetPivotPoint(bool viewportSearch) const
{
auto const & viewport = GetViewport();
if (viewportSearch || !viewport.IsPointInside(GetPosition()))
return viewport.Center();
return GetPosition();
}
m2::RectD Processor::GetPivotRect() const
m2::RectD Processor::GetPivotRect(bool viewportSearch) const
{
auto const & viewport = GetViewport();
if (viewportSearch)
return viewport;
if (viewport.IsPointInside(GetPosition()))
return GetRectAroundPosition(GetPosition());
return NormalizeViewport(viewport);
}
@ -396,47 +384,26 @@ void Processor::Search(SearchParams const & params)
return;
}
SetMode(params.m_mode);
bool const viewportSearch = m_mode == Mode::Viewport;
bool const viewportSearch = params.m_mode == Mode::Viewport;
bool rankPivotIsSet = false;
auto const & viewport = params.m_viewport;
ASSERT(viewport.IsValid(), ());
if (!viewportSearch && params.IsValidPosition())
{
m2::PointD const pos = params.GetPositionMercator();
if (m2::Inflate(viewport, viewport.SizeX() / 4.0, viewport.SizeY() / 4.0).IsPointInside(pos))
{
SetRankPivot(pos);
rankPivotIsSet = true;
}
}
if (!rankPivotIsSet)
SetRankPivot(viewport.Center());
if (params.IsValidPosition())
SetPosition(params.GetPositionMercator());
if (params.m_position)
SetPosition(*params.m_position);
else
SetPosition(viewport.Center());
SetMinDistanceOnMapBetweenResults(params.m_minDistanceOnMapBetweenResults);
SetSuggestsEnabled(params.m_suggestsEnabled);
m_hotelsFilter = params.m_hotelsFilter;
m_cianMode = params.m_cianMode;
SetInputLocale(params.m_inputLocale);
SetQuery(params.m_query);
SetViewport(viewport);
SetOnResults(params.m_onResults);
Geocoder::Params geocoderParams;
InitGeocoder(geocoderParams);
InitPreRanker(geocoderParams);
InitRanker(geocoderParams);
InitEmitter();
InitGeocoder(geocoderParams, params);
InitPreRanker(geocoderParams, params);
InitRanker(geocoderParams, params);
InitEmitter(params);
try
{
@ -523,72 +490,82 @@ void Processor::InitParams(QueryParams & params)
[&](int8_t lang) { params.GetLangs().Insert(static_cast<uint64_t>(lang)); });
}
void Processor::InitGeocoder(Geocoder::Params & params)
void Processor::InitGeocoder(Geocoder::Params & geocoderParams, SearchParams const & searchParams)
{
bool const viewportSearch = m_mode == Mode::Viewport;
auto const viewportSearch = searchParams.m_mode == Mode::Viewport;
InitParams(params);
params.m_mode = m_mode;
if (viewportSearch)
params.m_pivot = GetViewport();
else
params.m_pivot = GetPivotRect();
params.m_hotelsFilter = m_hotelsFilter;
params.m_cianMode = m_cianMode;
params.m_preferredTypes = m_preferredTypes;
InitParams(geocoderParams);
m_geocoder.SetParams(params);
geocoderParams.m_mode = searchParams.m_mode;
geocoderParams.m_pivot = GetPivotRect(viewportSearch);
geocoderParams.m_hotelsFilter = searchParams.m_hotelsFilter;
geocoderParams.m_cianMode = searchParams.m_cianMode;
geocoderParams.m_preferredTypes = m_preferredTypes;
m_geocoder.SetParams(geocoderParams);
}
void Processor::InitPreRanker(Geocoder::Params const & geocoderParams)
void Processor::InitPreRanker(Geocoder::Params const & geocoderParams,
SearchParams const & searchParams)
{
bool const viewportSearch = m_mode == Mode::Viewport;
bool const viewportSearch = searchParams.m_mode == Mode::Viewport;
PreRanker::Params params;
if (viewportSearch)
{
params.m_viewport = GetViewport();
params.m_minDistanceOnMapBetweenResults = m_minDistanceOnMapBetweenResults;
params.m_minDistanceOnMapBetweenResults =
searchParams.m_minDistanceOnMapBetweenResults;
}
params.m_accuratePivotCenter = GetPivotPoint();
params.m_accuratePivotCenter = GetPivotPoint(viewportSearch);
params.m_scale = geocoderParams.GetScale();
params.m_limit = max(kPreResultsCount, searchParams.m_maxNumResults);
params.m_viewportSearch = viewportSearch;
m_preRanker.Init(params);
}
void Processor::InitRanker(Geocoder::Params const & geocoderParams)
void Processor::InitRanker(Geocoder::Params const & geocoderParams,
SearchParams const & searchParams)
{
size_t const kResultsCount = 30;
bool const viewportSearch = m_mode == Mode::Viewport;
bool const viewportSearch = searchParams.m_mode == Mode::Viewport;
Ranker::Params params;
params.m_currentLocaleCode = m_currentLocaleCode;
if (viewportSearch)
{
params.m_viewport = GetViewport();
params.m_minDistanceOnMapBetweenResults = m_minDistanceOnMapBetweenResults;
params.m_limit = kPreResultsCount;
params.m_minDistanceOnMapBetweenResults = searchParams.m_minDistanceOnMapBetweenResults;
}
else
{
params.m_minDistanceOnMapBetweenResults = 100.0;
params.m_limit = kResultsCount;
params.m_minDistanceOnMapBetweenResults = kMinDistanceOnMapBetweenResultsM;
}
params.m_limit = searchParams.m_maxNumResults;
params.m_position = GetPosition();
params.m_pivotRegion = GetPivotRegion();
params.m_preferredTypes = m_preferredTypes;
params.m_suggestsEnabled = m_suggestsEnabled;
params.m_suggestsEnabled = searchParams.m_suggestsEnabled;
params.m_needAddress = searchParams.m_needAddress;
params.m_needHighlight = searchParams.m_needHighlight;
params.m_query = m_query;
params.m_tokens = m_tokens;
params.m_prefix = m_prefix;
params.m_categoryLocales = GetCategoryLocales();
params.m_accuratePivotCenter = GetPivotPoint();
params.m_accuratePivotCenter = GetPivotPoint(viewportSearch);
params.m_viewportSearch = viewportSearch;
m_ranker.Init(params, geocoderParams);
}
void Processor::InitEmitter() { m_emitter.Init(m_onResults); }
void Processor::InitEmitter(SearchParams const & searchParams)
{
m_emitter.Init(searchParams.m_onResults);
}
void Processor::ClearCaches()
{

View file

@ -4,8 +4,6 @@
#include "search/cities_boundaries_table.hpp"
#include "search/emitter.hpp"
#include "search/geocoder.hpp"
#include "search/hotels_filter.hpp"
#include "search/mode.hpp"
#include "search/pre_ranker.hpp"
#include "search/rank_table_cache.hpp"
#include "search/ranker.hpp"
@ -15,9 +13,7 @@
#include "search/token_slice.hpp"
#include "search/utils.hpp"
#include "indexer/ftypes_matcher.hpp"
#include "indexer/index.hpp"
#include "indexer/rank_table.hpp"
#include "indexer/string_slice.hpp"
#include "coding/multilang_utf8_string.hpp"
@ -25,16 +21,10 @@
#include "geometry/rect2d.hpp"
#include "base/cancellable.hpp"
#include "base/limited_priority_queue.hpp"
#include "base/string_utils.hpp"
#include "std/cstdint.hpp"
#include "std/function.hpp"
#include "std/map.hpp"
#include "std/shared_ptr.hpp"
#include "std/string.hpp"
#include "std/unique_ptr.hpp"
#include "std/unordered_set.hpp"
#include "std/vector.hpp"
class FeatureType;
@ -66,33 +56,20 @@ public:
static double const kMinViewportRadiusM;
static double const kMaxViewportRadiusM;
static double const kMinDistanceOnMapBetweenResultsM;
Processor(Index const & index, CategoriesHolder const & categories,
vector<Suggest> const & suggests, storage::CountryInfoGetter const & infoGetter);
void Init(bool viewportSearch);
void SetViewport(m2::RectD const & viewport);
void SetPreferredLocale(string const & locale);
void SetInputLocale(string const & locale);
void SetQuery(string const & query);
// TODO (@y): this function must be removed.
void SetRankPivot(m2::PointD const & pivot);
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 SetMinDistanceOnMapBetweenResults(double distance)
{
m_minDistanceOnMapBetweenResults = distance;
}
inline void SetOnResults(SearchParams::OnResults const & onResults) { m_onResults = onResults; }
inline string const & GetPivotRegion() const { return m_region; }
inline m2::PointD const & GetPosition() const { return m_position; }
/// Suggestions language code, not the same as we use in mwm data
int8_t m_inputLocaleCode = StringUtf8Multilang::kUnsupportedLanguageCode;
int8_t m_currentLocaleCode = StringUtf8Multilang::kUnsupportedLanguageCode;
inline bool IsEmptyQuery() const { return (m_prefix.empty() && m_tokens.empty()); }
inline bool IsEmptyQuery() const { return m_prefix.empty() && m_tokens.empty(); }
void Search(SearchParams const & params);
@ -101,19 +78,17 @@ public:
void InitParams(QueryParams & params);
void InitGeocoder(Geocoder::Params & params);
void InitPreRanker(Geocoder::Params const & geocoderParams);
void InitRanker(Geocoder::Params const & geocoderParams);
void InitEmitter();
void InitGeocoder(Geocoder::Params &geocoderParams,
SearchParams const &searchParams);
void InitPreRanker(Geocoder::Params const &geocoderParams,
SearchParams const &searchParams);
void InitRanker(Geocoder::Params const & geocoderParams, SearchParams const & searchParams);
void InitEmitter(SearchParams const & searchParams);
void ClearCaches();
void LoadCitiesBoundaries();
protected:
using TMWMVector = vector<shared_ptr<MwmInfo>>;
using TOffsetsVector = map<MwmSet::MwmId, vector<uint32_t>>;
using TFHeader = feature::DataHeader;
Locales GetCategoryLocales() const;
template <typename ToDo>
@ -122,8 +97,8 @@ protected:
template <typename ToDo>
void ForEachCategoryTypeFuzzy(StringSliceBase const & slice, ToDo && toDo) const;
m2::PointD GetPivotPoint() const;
m2::RectD GetPivotRect() const;
m2::PointD GetPivotPoint(bool viewportSearch) const;
m2::RectD GetPivotRect(bool viewportSearch) const;
m2::RectD const & GetViewport() const;
@ -137,16 +112,13 @@ protected:
set<uint32_t> m_preferredTypes;
m2::RectD m_viewport;
m2::PointD m_pivot;
m2::PointD m_position;
double m_minDistanceOnMapBetweenResults;
Mode m_mode;
bool m_suggestsEnabled;
shared_ptr<hotels_filter::Rule> m_hotelsFilter;
bool m_cianMode = false;
SearchParams::OnResults m_onResults;
bool m_needAddress = true;
bool m_needHighlight = true;
bool m_viewportSearch;
// Suggestions language code, not the same as we use in mwm data
int8_t m_inputLocaleCode = StringUtf8Multilang::kUnsupportedLanguageCode;
int8_t m_currentLocaleCode = StringUtf8Multilang::kUnsupportedLanguageCode;
VillagesCache m_villagesCache;
CitiesBoundariesTable m_citiesBoundaries;

View file

@ -395,19 +395,19 @@ Result Ranker::MakeResult(RankerResult const & rankerResult, bool needAddress,
auto res = mk(rankerResult);
if (needHighlighting)
if (needAddress &&
ftypes::IsLocalityChecker::Instance().GetType(rankerResult.GetTypes()) == ftypes::NONE)
{
HighlightResult(m_params.m_tokens, m_params.m_prefix, res);
if (ftypes::IsLocalityChecker::Instance().GetType(rankerResult.GetTypes()) == ftypes::NONE)
{
m_localities.GetLocality(res.GetFeatureCenter(), [&](LocalityItem const & item) {
string city;
if (item.GetSpecifiedOrDefaultName(m_localityLang, city))
res.AppendCity(city);
});
}
m_localities.GetLocality(res.GetFeatureCenter(), [&](LocalityItem const & item) {
string city;
if (item.GetSpecifiedOrDefaultName(m_localityLang, city))
res.AppendCity(city);
});
}
if (needHighlighting)
HighlightResult(m_params.m_tokens, m_params.m_prefix, res);
res.SetRankingInfo(rankerResult.GetRankingInfo());
return res;
}
@ -459,20 +459,19 @@ void Ranker::UpdateResults(bool lastUpdate)
auto const & rankerResult = m_tentativeResults[i];
if (count >= m_params.m_limit)
break;
Result result = MakeResult(rankerResult, m_params.m_needAddress, m_params.m_needHighlight);
if (m_params.m_viewportSearch)
{
// Viewport results don't need calculated address.
Result result =
MakeResult(rankerResult, false /* needAddress */, false /* needHighlighting */);
m_emitter.AddResultNoChecks(move(result));
++count;
}
else
{
if (count >= m_params.m_limit)
break;
LOG(LDEBUG, (rankerResult));
Result result = MakeResult(rankerResult, true /* needAddress */, true /* needHighlighting */);
if (m_emitter.AddResult(move(result)))
++count;
}

View file

@ -51,6 +51,8 @@ public:
string m_pivotRegion;
set<uint32_t> m_preferredTypes;
bool m_suggestsEnabled = false;
bool m_needAddress = false;
bool m_needHighlight = false;
bool m_viewportSearch = false;
string m_query;

View file

@ -98,6 +98,7 @@ unique_ptr<tests_support::TestSearchRequest> SearchTest::MakeRequest(
params.m_inputLocale = locale;
params.m_viewport = m_viewport;
params.m_mode = Mode::Everywhere;
params.m_needAddress = true;
params.m_suggestsEnabled = false;
auto request = make_unique<tests_support::TestSearchRequest>(m_engine, params);

View file

@ -121,14 +121,15 @@ UNIT_CLASS_TEST(PreRankerTest, Smoke)
TestRanker ranker(m_engine, boundariesTable, keywordsScorer, emitter, m_suggests, villagesCache,
m_cancellable, results);
PreRanker preRanker(m_engine, ranker, pois.size());
PreRanker preRanker(m_engine, ranker);
PreRanker::Params params;
params.m_viewport = kViewport;
params.m_accuratePivotCenter = kPivot;
params.m_scale = scales::GetUpperScale();
params.m_batchSize = kBatchSize;
params.m_limit = pois.size();
params.m_viewportSearch = true;
preRanker.Init(params);
preRanker.SetViewportSearch(true);
vector<double> distances(pois.size());
vector<bool> emit(pois.size());

View file

@ -12,22 +12,10 @@ using namespace std;
namespace search
{
m2::PointD SearchParams::GetPositionMercator() const
{
ASSERT(IsValidPosition(), ());
return MercatorBounds::FromLatLon(*m_position);
}
ms::LatLon SearchParams::GetPositionLatLon() const
{
ASSERT(IsValidPosition(), ());
return *m_position;
}
bool SearchParams::IsEqualCommon(SearchParams const & rhs) const
{
return m_query == rhs.m_query && m_inputLocale == rhs.m_inputLocale &&
IsValidPosition() == rhs.IsValidPosition() && m_mode == rhs.m_mode;
static_cast<bool>(m_position) == static_cast<bool>(rhs.m_position) && m_mode == rhs.m_mode;
}
string DebugPrint(SearchParams const & params)

View file

@ -3,10 +3,10 @@
#include "search/hotels_filter.hpp"
#include "search/mode.hpp"
#include "geometry/latlon.hpp"
#include "geometry/point2d.hpp"
#include "geometry/rect2d.hpp"
#include <cstddef>
#include <functional>
#include <memory>
#include <string>
@ -19,14 +19,12 @@ class Results;
struct SearchParams
{
static size_t const kDefaultNumResultsEverywhere = 30;
static size_t const kDefaultNumResultsInViewport = 200;
using OnStarted = function<void()>;
using OnResults = function<void(Results const &)>;
void SetPosition(ms::LatLon const & position) { m_position = position; }
bool IsValidPosition() const { return static_cast<bool>(m_position); }
m2::PointD GetPositionMercator() const;
ms::LatLon GetPositionLatLon() const;
bool IsEqualCommon(SearchParams const & rhs) const;
void Clear() { m_query.clear(); }
@ -37,16 +35,26 @@ struct SearchParams
std::string m_query;
std::string m_inputLocale;
boost::optional<ms::LatLon> m_position;
boost::optional<m2::PointD> m_position;
m2::RectD m_viewport;
size_t m_maxNumResults = kDefaultNumResultsEverywhere;
// A minimum distance between search results in meters, needed for
// pre-ranking of viewport search results.
double m_minDistanceOnMapBetweenResults = 0.0;
Mode m_mode = Mode::Everywhere;
bool m_forceSearch = false;
bool m_suggestsEnabled = true;
// Is it needed to generate search suggests.
bool m_suggestsEnabled = false;
// Is it needed to generate address for results.
bool m_needAddress = false;
// Is it needed to highlight matching parts of search result names.
bool m_needHighlight = false;
std::shared_ptr<hotels_filter::Rule> m_hotelsFilter;
bool m_cianMode = false;

View file

@ -193,7 +193,7 @@ void Sample::FillSearchParams(search::SearchParams & params) const
params.m_viewport = m_viewport;
params.m_mode = Mode::Everywhere;
if (m_posAvailable)
params.SetPosition(MercatorBounds::ToLatLon(m_pos));
params.m_position = m_pos;
params.m_suggestsEnabled = false;
}

View file

@ -20,6 +20,7 @@ TestSearchRequest::TestSearchRequest(TestSearchEngine & engine, string const & q
m_params.m_viewport = viewport;
m_params.m_mode = mode;
SetUpCallbacks();
SetUpResultParams();
}
TestSearchRequest::TestSearchRequest(TestSearchEngine & engine, SearchParams const & params)
@ -40,6 +41,7 @@ TestSearchRequest::TestSearchRequest(TestSearchEngine & engine, string const & q
m_params.m_mode = mode;
m_params.m_onStarted = onStarted;
m_params.m_onResults = onResults;
SetUpResultParams();
}
void TestSearchRequest::Run()
@ -79,6 +81,25 @@ void TestSearchRequest::SetUpCallbacks()
m_params.m_onResults = bind(&TestSearchRequest::OnResults, this, _1);
}
void TestSearchRequest::SetUpResultParams()
{
switch (m_params.m_mode)
{
case Mode::Everywhere:
m_params.m_needAddress = true;
m_params.m_suggestsEnabled = false;
m_params.m_needHighlight = true;
break;
case Mode::Viewport: // fallthrough
case Mode::Downloader:
m_params.m_needAddress = false;
m_params.m_suggestsEnabled = false;
m_params.m_needHighlight = false;
break;
case Mode::Count: CHECK(false, ()); break;
}
}
void TestSearchRequest::OnStarted()
{
lock_guard<mutex> lock(m_mu);

View file

@ -48,6 +48,7 @@ protected:
void Wait();
void SetUpCallbacks();
void SetUpResultParams();
void OnStarted();
void OnResults(search::Results const & results);