Merge pull request #3362 from mpimenov/processor_v2

[search] Merged Processor and ProcessorV2.
This commit is contained in:
ygorshenin 2016-05-31 14:39:48 +03:00
commit 59f40d7669
10 changed files with 270 additions and 375 deletions

View file

@ -61,7 +61,9 @@
#include "coding/png_memory_encoder.hpp"
#include "geometry/angles.hpp"
#include "geometry/any_rect2d.hpp"
#include "geometry/distance_on_sphere.hpp"
#include "geometry/rect2d.hpp"
#include "geometry/triangle2d.hpp"
#include "base/math.hpp"

View file

@ -31,6 +31,8 @@
#include "indexer/search_string_utils.hpp"
#include "indexer/trie_reader.hpp"
#include "geometry/mercator.hpp"
#include "platform/mwm_traits.hpp"
#include "platform/mwm_version.hpp"
#include "platform/preferred_languages.hpp"
@ -226,9 +228,10 @@ Processor::Processor(Index & index, CategoriesHolder const & categories,
, m_mode(Mode::Everywhere)
, m_worldSearch(true)
, m_suggestsEnabled(true)
, m_preRanker(kPreResultsCount)
, m_viewportSearch(false)
, m_keepHouseNumberInQuery(false)
, m_keepHouseNumberInQuery(true)
, m_preRanker(kPreResultsCount)
, m_geocoder(index, infoGetter)
, m_reverseGeocoder(index)
{
// Initialize keywords scorer.
@ -244,30 +247,14 @@ Processor::Processor(Index & index, CategoriesHolder const & categories,
SetPreferredLocale("en");
}
void Processor::SetLanguage(int id, int8_t lang)
void Processor::Init(bool viewportSearch)
{
m_keywordsScorer.SetLanguage(GetLangIndex(id), lang);
}
Reset();
int8_t Processor::GetLanguage(int id) const
{
return m_keywordsScorer.GetLanguage(GetLangIndex(id));
}
m2::PointD Processor::GetPivotPoint() const
{
m2::RectD const & viewport = m_viewport[CURRENT_V];
if (viewport.IsPointInside(GetPosition()))
return GetPosition();
return viewport.Center();
}
m2::RectD Processor::GetPivotRect() const
{
m2::RectD const & viewport = m_viewport[CURRENT_V];
if (viewport.IsPointInside(GetPosition()))
return GetRectAroundPosition(GetPosition());
return NormalizeViewport(viewport);
m_tokens.clear();
m_prefix.clear();
m_preRanker.Clear();
m_viewportSearch = viewportSearch;
}
void Processor::SetViewport(m2::RectD const & viewport, bool forceUpdate)
@ -280,59 +267,6 @@ void Processor::SetViewport(m2::RectD const & viewport, bool forceUpdate)
SetViewportByIndex(mwmsInfo, viewport, CURRENT_V, forceUpdate);
}
void Processor::SetViewportByIndex(TMWMVector const & mwmsInfo, m2::RectD const & viewport,
size_t idx, bool forceUpdate)
{
ASSERT(idx < COUNT_V, (idx));
if (viewport.IsValid())
{
// Check if we can skip this cache query.
if (m_viewport[idx].IsValid())
{
// Threshold to compare for equal or inner rects.
// It doesn't influence on result cached features because it's smaller
// than minimal cell size in geometry index (i'm almost sure :)).
double constexpr epsMeters = 10.0;
if (forceUpdate)
{
// skip if rects are equal
if (IsEqualMercator(m_viewport[idx], viewport, epsMeters))
return;
}
else
{
// skip if the new viewport is inside the old one (no need to recache)
m2::RectD r(m_viewport[idx]);
double constexpr eps = epsMeters * MercatorBounds::degreeInMetres;
r.Inflate(eps, eps);
if (r.IsRectInside(viewport))
return;
}
}
m_viewport[idx] = viewport;
}
else
{
ClearCache(idx);
}
}
void Processor::SetRankPivot(m2::PointD const & pivot)
{
if (!m2::AlmostEqualULPs(pivot, m_pivot))
{
storage::CountryInfo ci;
m_infoGetter.GetRegionInfo(pivot, ci);
m_region.swap(ci.m_name);
}
m_pivot = pivot;
}
void Processor::SetPreferredLocale(string const & locale)
{
ASSERT(!locale.empty(), ());
@ -355,80 +289,12 @@ void Processor::SetPreferredLocale(string const & locale)
void Processor::SetInputLocale(string const & locale)
{
if (!locale.empty())
{
LOG(LDEBUG, ("New input locale:", locale));
if (locale.empty())
return;
SetLanguage(LANG_INPUT, StringUtf8Multilang::GetLangIndex(languages::Normalize(locale)));
m_inputLocaleCode = CategoriesHolder::MapLocaleToInteger(locale);
}
}
void Processor::ClearCaches()
{
for (size_t i = 0; i < COUNT_V; ++i)
ClearCache(i);
m_locality.ClearCache();
}
void Processor::ClearCache(size_t ind) { m_viewport[ind].MakeEmpty(); }
void Processor::Init(bool viewportSearch)
{
Reset();
m_tokens.clear();
m_prefix.clear();
m_preRanker.Clear();
m_viewportSearch = viewportSearch;
}
int Processor::GetCategoryLocales(int8_t(&arr)[3]) const
{
static int8_t const enLocaleCode = CategoriesHolder::MapLocaleToInteger("en");
// Prepare array of processing locales. English locale is always present for category matching.
int count = 0;
if (m_currentLocaleCode != -1)
arr[count++] = m_currentLocaleCode;
if (m_inputLocaleCode != -1 && m_inputLocaleCode != m_currentLocaleCode)
arr[count++] = m_inputLocaleCode;
if (enLocaleCode != m_currentLocaleCode && enLocaleCode != m_inputLocaleCode)
arr[count++] = enLocaleCode;
return count;
}
template <class ToDo>
void Processor::ForEachCategoryTypes(StringSliceBase const & slice, ToDo toDo) const
{
int8_t arrLocales[3];
int const localesCount = GetCategoryLocales(arrLocales);
for (size_t i = 0; i < slice.Size(); ++i)
{
auto token = RemoveHashtag(slice.Get(i));
for (int j = 0; j < localesCount; ++j)
m_categories.ForEachTypeByName(arrLocales[j], token, bind<void>(ref(toDo), i, _1));
ProcessEmojiIfNeeded(token, i, toDo);
}
}
template <class ToDo>
void Processor::ProcessEmojiIfNeeded(strings::UniString const & token, size_t ind,
ToDo & toDo) const
{
// Special process of 2 codepoints emoji (e.g. black guy on a bike).
// Only emoji synonyms can have one codepoint.
if (token.size() > 1)
{
static int8_t const enLocaleCode = CategoriesHolder::MapLocaleToInteger("en");
m_categories.ForEachTypeByName(enLocaleCode, strings::UniString(1, token[0]),
bind<void>(ref(toDo), ind, _1));
}
LOG(LDEBUG, ("New input locale:", locale));
SetLanguage(LANG_INPUT, StringUtf8Multilang::GetLangIndex(languages::Normalize(locale)));
m_inputLocaleCode = CategoriesHolder::MapLocaleToInteger(locale);
}
void Processor::SetQuery(string const & query)
@ -499,30 +365,162 @@ void Processor::SetQuery(string const & query)
});
}
void Processor::FlushViewportResults(v2::Geocoder::Params const & params, Results & res,
bool oldHouseSearch)
void Processor::SetRankPivot(m2::PointD const & pivot)
{
vector<IndexedValue> indV;
vector<FeatureID> streets;
MakePreResult2(params, indV, streets);
RemoveDuplicatingLinear(indV);
if (indV.empty())
return;
sort(indV.begin(), indV.end(), my::LessBy(&IndexedValue::GetDistanceToPivot));
for (size_t i = 0; i < indV.size(); ++i)
if (!m2::AlmostEqualULPs(pivot, m_pivot))
{
if (IsCancelled())
break;
res.AddResultNoChecks(
(*(indV[i]))
.GenerateFinalResult(m_infoGetter, &m_categories, &m_prefferedTypes,
m_currentLocaleCode,
nullptr /* Viewport results don't need calculated address */));
storage::CountryInfo ci;
m_infoGetter.GetRegionInfo(pivot, ci);
m_region.swap(ci.m_name);
}
m_pivot = pivot;
}
void Processor::SetLanguage(int id, int8_t lang)
{
m_keywordsScorer.SetLanguage(GetLangIndex(id), lang);
}
int8_t Processor::GetLanguage(int id) const
{
return m_keywordsScorer.GetLanguage(GetLangIndex(id));
}
m2::PointD Processor::GetPivotPoint() const
{
m2::RectD const & viewport = m_viewport[CURRENT_V];
if (viewport.IsPointInside(GetPosition()))
return GetPosition();
return viewport.Center();
}
m2::RectD Processor::GetPivotRect() const
{
m2::RectD const & viewport = m_viewport[CURRENT_V];
if (viewport.IsPointInside(GetPosition()))
return GetRectAroundPosition(GetPosition());
return NormalizeViewport(viewport);
}
void Processor::SetViewportByIndex(TMWMVector const & mwmsInfo, m2::RectD const & viewport,
size_t idx, bool forceUpdate)
{
ASSERT(idx < COUNT_V, (idx));
if (viewport.IsValid())
{
// Check if we can skip this cache query.
if (m_viewport[idx].IsValid())
{
// Threshold to compare for equal or inner rects.
// It doesn't influence on result cached features because it's smaller
// than minimal cell size in geometry index (i'm almost sure :)).
double constexpr epsMeters = 10.0;
if (forceUpdate)
{
// skip if rects are equal
if (IsEqualMercator(m_viewport[idx], viewport, epsMeters))
return;
}
else
{
// skip if the new viewport is inside the old one (no need to recache)
m2::RectD r(m_viewport[idx]);
double constexpr eps = epsMeters * MercatorBounds::degreeInMetres;
r.Inflate(eps, eps);
if (r.IsRectInside(viewport))
return;
}
}
m_viewport[idx] = viewport;
}
else
{
ClearCache(idx);
}
}
void Processor::ClearCache(size_t ind) { m_viewport[ind].MakeEmpty(); }
int Processor::GetCategoryLocales(int8_t(&arr)[3]) const
{
static int8_t const enLocaleCode = CategoriesHolder::MapLocaleToInteger("en");
// Prepare array of processing locales. English locale is always present for category matching.
int count = 0;
if (m_currentLocaleCode != -1)
arr[count++] = m_currentLocaleCode;
if (m_inputLocaleCode != -1 && m_inputLocaleCode != m_currentLocaleCode)
arr[count++] = m_inputLocaleCode;
if (enLocaleCode != m_currentLocaleCode && enLocaleCode != m_inputLocaleCode)
arr[count++] = enLocaleCode;
return count;
}
template <class ToDo>
void Processor::ForEachCategoryTypes(StringSliceBase const & slice, ToDo toDo) const
{
int8_t arrLocales[3];
int const localesCount = GetCategoryLocales(arrLocales);
for (size_t i = 0; i < slice.Size(); ++i)
{
auto token = RemoveHashtag(slice.Get(i));
for (int j = 0; j < localesCount; ++j)
m_categories.ForEachTypeByName(arrLocales[j], token, bind<void>(ref(toDo), i, _1));
ProcessEmojiIfNeeded(token, i, toDo);
}
}
template <class ToDo>
void Processor::ProcessEmojiIfNeeded(strings::UniString const & token, size_t ind,
ToDo & toDo) const
{
// Special process of 2 codepoints emoji (e.g. black guy on a bike).
// Only emoji synonyms can have one codepoint.
if (token.size() > 1)
{
static int8_t const enLocaleCode = CategoriesHolder::MapLocaleToInteger("en");
m_categories.ForEachTypeByName(enLocaleCode, strings::UniString(1, token[0]),
bind<void>(ref(toDo), ind, _1));
}
}
void Processor::Search(Results & results, size_t limit)
{
if (m_tokens.empty())
SuggestStrings(results);
v2::Geocoder::Params params;
InitParams(params);
params.m_mode = m_mode;
params.m_pivot = GetPivotRect();
params.m_accuratePivotCenter = GetPivotPoint();
m_geocoder.SetParams(params);
m_geocoder.GoEverywhere(m_preRanker);
FlushResults(params, results, limit);
}
void Processor::SearchViewportPoints(Results & results)
{
v2::Geocoder::Params params;
InitParams(params);
params.m_pivot = m_viewport[CURRENT_V];
params.m_accuratePivotCenter = params.m_pivot.Center();
m_geocoder.SetParams(params);
m_geocoder.GoInViewport(m_preRanker);
FlushViewportResults(params, results);
}
void Processor::SearchCoordinates(Results & res) const
@ -709,8 +707,7 @@ void Processor::MakePreResult2(v2::Geocoder::Params const & params, vector<T> &
});
}
void Processor::FlushResults(v2::Geocoder::Params const & params, Results & res, bool allMWMs,
size_t resCount, bool oldHouseSearch)
void Processor::FlushResults(v2::Geocoder::Params const & params, Results & res, size_t resCount)
{
vector<IndexedValue> indV;
vector<FeatureID> streets;
@ -722,9 +719,7 @@ void Processor::FlushResults(v2::Geocoder::Params const & params, Results & res,
sort(indV.rbegin(), indV.rend(), my::LessBy(&IndexedValue::GetRank));
// Do not process suggestions in additional search.
if (!allMWMs || res.GetCount() == 0)
ProcessSuggestions(indV, res);
ProcessSuggestions(indV, res);
// Emit feature results.
size_t count = res.GetCount();
@ -741,9 +736,29 @@ void Processor::FlushResults(v2::Geocoder::Params const & params, Results & res,
}
}
int Processor::GetQueryIndexScale(m2::RectD const & viewport) const
void Processor::FlushViewportResults(v2::Geocoder::Params const & params, Results & res)
{
return search::GetQueryIndexScale(viewport);
vector<IndexedValue> indV;
vector<FeatureID> streets;
MakePreResult2(params, indV, streets);
RemoveDuplicatingLinear(indV);
if (indV.empty())
return;
sort(indV.begin(), indV.end(), my::LessBy(&IndexedValue::GetDistanceToPivot));
for (size_t i = 0; i < indV.size(); ++i)
{
if (IsCancelled())
break;
res.AddResultNoChecks(
(*(indV[i]))
.GenerateFinalResult(m_infoGetter, &m_categories, &m_prefferedTypes,
m_currentLocaleCode,
nullptr /* Viewport results don't need calculated address */));
}
}
void Processor::RemoveStringPrefix(string const & str, string & res) const
@ -1103,7 +1118,7 @@ int GetOldTypeFromIndex(size_t index)
}
} // namespace
void Processor::InitParams(bool localitySearch, QueryParams & params)
void Processor::InitParams(QueryParams & params)
{
params.Clear();
@ -1120,32 +1135,27 @@ void Processor::InitParams(bool localitySearch, QueryParams & params)
params.m_isCategorySynonym.assign(tokensCount + (m_prefix.empty() ? 0 : 1), false);
// Add names of categories (and synonyms).
if (!localitySearch)
{
Classificator const & c = classif();
auto addSyms = [&](size_t i, uint32_t t)
Classificator const & c = classif();
auto addSyms = [&](size_t i, uint32_t t) {
QueryParams::TSynonymsVector & v = params.GetTokens(i);
uint32_t const index = c.GetIndexForType(t);
v.push_back(FeatureTypeToString(index));
params.m_isCategorySynonym[i] = true;
// v2-version MWM has raw classificator types in search index prefix, so
// do the hack: add synonyms for old convention if needed.
if (m_supportOldFormat)
{
QueryParams::TSynonymsVector & v = params.GetTokens(i);
uint32_t const index = c.GetIndexForType(t);
v.push_back(FeatureTypeToString(index));
params.m_isCategorySynonym[i] = true;
// v2-version MWM has raw classificator types in search index prefix, so
// do the hack: add synonyms for old convention if needed.
if (m_supportOldFormat)
int const type = GetOldTypeFromIndex(index);
if (type >= 0)
{
int const type = GetOldTypeFromIndex(index);
if (type >= 0)
{
ASSERT(type == 70 || type > 4000, (type));
v.push_back(FeatureTypeToString(static_cast<uint32_t>(type)));
}
ASSERT(type == 70 || type > 4000, (type));
v.push_back(FeatureTypeToString(static_cast<uint32_t>(type)));
}
};
ForEachCategoryTypes(v2::QuerySliceOnRawStrings<decltype(m_tokens)>(m_tokens, m_prefix),
addSyms);
}
}
};
ForEachCategoryTypes(v2::QuerySliceOnRawStrings<decltype(m_tokens)>(m_tokens, m_prefix), addSyms);
for (auto & tokens : params.m_tokens)
{
@ -1159,6 +1169,19 @@ void Processor::InitParams(bool localitySearch, QueryParams & params)
params.m_langs.insert(GetLanguage(i));
}
void Processor::ClearCaches()
{
for (size_t i = 0; i < COUNT_V; ++i)
ClearCache(i);
m_locality.ClearCache();
m_geocoder.ClearCaches();
}
void Processor::Reset() { m_geocoder.Reset(); }
void Processor::Cancel() { m_geocoder.Cancel(); }
void Processor::SuggestStrings(Results & res)
{
if (m_prefix.empty() || !m_suggestsEnabled)

View file

@ -50,6 +50,12 @@ namespace search
struct Locality;
struct Region;
struct QueryParams;
class ReverseGeocoder;
namespace v2
{
class Geocoder;
} // namespace search::v2
namespace impl
{
@ -79,49 +85,44 @@ public:
/// @param[in] forceUpdate Pass true (default) to recache feature's ids even
/// if viewport is a part of the old cached rect.
void SetViewport(m2::RectD const & viewport, bool forceUpdate);
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 string const & GetPivotRegion() const { return m_region; }
inline void SetPosition(m2::PointD const & position) { m_position = position; }
inline m2::PointD const & GetPosition() const { return m_position; }
inline void SetMode(Mode mode) { m_mode = mode; }
inline void SetSearchInWorld(bool b) { m_worldSearch = b; }
inline void SetSuggestsEnabled(bool enabled) { m_suggestsEnabled = enabled; }
inline void SetPosition(m2::PointD const & position) { m_position = position; }
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, m_currentLocaleCode;
void SetPreferredLocale(string const & locale);
void SetInputLocale(string const & locale);
void SetQuery(string const & query);
inline bool IsEmptyQuery() const { return (m_prefix.empty() && m_tokens.empty()); }
/// @name Different search functions.
/// @name Various search functions.
//@{
virtual void Search(Results & results, size_t limit) = 0;
virtual void SearchViewportPoints(Results & results) = 0;
void Search(Results & results, size_t limit);
void SearchViewportPoints(Results & results);
// Tries to generate a (lat, lon) result from |m_query|.
void SearchCoordinates(Results & res) const;
//@}
// Get scale level to make geometry index query for current viewport.
virtual int GetQueryIndexScale(m2::RectD const & viewport) const;
virtual void ClearCaches();
struct CancelException
{
};
/// @name This stuff is public for implementation classes in processor.cpp
/// Do not use it in client code.
//@{
void InitParams(QueryParams & params);
void InitParams(bool localitySearch, QueryParams & params);
void ClearCaches();
// my::Cancellable overrides:
void Reset() override;
void Cancel() override;
protected:
enum ViewportID
@ -161,16 +162,8 @@ protected:
void MakePreResult2(v2::Geocoder::Params const & params, vector<T> & cont,
vector<FeatureID> & streets);
/// @param allMWMs Deprecated, need to support old search algorithm.
/// @param oldHouseSearch Deprecated, need to support old search algorithm.
//@{
void FlushHouses(Results & res, bool allMWMs, vector<FeatureID> const & streets);
void FlushResults(v2::Geocoder::Params const & params, Results & res, bool allMWMs,
size_t resCount, bool oldHouseSearch);
void FlushViewportResults(v2::Geocoder::Params const & params, Results & res,
bool oldHouseSearch);
//@}
void FlushResults(v2::Geocoder::Params const & params, Results & res, size_t resCount);
void FlushViewportResults(v2::Geocoder::Params const & params, Results & res);
void RemoveStringPrefix(string const & str, string & res) const;
void GetSuggestion(string const & name, string & suggest) const;
@ -221,30 +214,12 @@ protected:
bool m_supportOldFormat;
template <class TParam>
class TCompare
{
using TFunction = function<bool(TParam const &, TParam const &)>;
TFunction m_fn;
public:
TCompare() : m_fn(0) {}
explicit TCompare(TFunction const & fn) : m_fn(fn) {}
template <class T>
bool operator()(T const & v1, T const & v2) const
{
return m_fn(v1, v2);
}
};
using TQueueCompare = TCompare<impl::PreResult1>;
using TQueue = my::limited_priority_queue<impl::PreResult1, TQueueCompare>;
protected:
PreRanker m_preRanker;
bool m_viewportSearch;
bool m_keepHouseNumberInQuery;
search::ReverseGeocoder const m_reverseGeocoder;
PreRanker m_preRanker;
v2::Geocoder m_geocoder;
ReverseGeocoder const m_reverseGeocoder;
};
} // namespace search

View file

@ -1,7 +1,7 @@
#pragma once
#include "search/processor.hpp"
#include "search/suggest.hpp"
#include "search/v2/processor_v2.hpp"
#include "std/unique_ptr.hpp"
@ -21,7 +21,7 @@ public:
vector<Suggest> const & suggests,
storage::CountryInfoGetter const & infoGetter)
{
return make_unique<v2::ProcessorV2>(index, categories, suggests, infoGetter);
return make_unique<Processor>(index, categories, suggests, infoGetter);
}
};
} // namespace search

View file

@ -56,7 +56,6 @@ HEADERS += \
v2/mwm_context.hpp \
v2/nested_rects_cache.hpp \
v2/pre_ranking_info.hpp \
v2/processor_v2.hpp \
v2/rank_table_cache.hpp \
v2/ranking_info.hpp \
v2/ranking_utils.hpp \
@ -103,7 +102,6 @@ SOURCES += \
v2/mwm_context.cpp \
v2/nested_rects_cache.cpp \
v2/pre_ranking_info.cpp \
v2/processor_v2.cpp \
v2/rank_table_cache.cpp \
v2/ranking_info.cpp \
v2/ranking_utils.cpp \

View file

@ -160,9 +160,9 @@ Engine::~Engine()
weak_ptr<ProcessorHandle> Engine::Search(SearchParams const & params, m2::RectD const & viewport)
{
shared_ptr<ProcessorHandle> handle(new ProcessorHandle());
PostMessage(Message::TYPE_TASK, [this, params, viewport, handle](Processor & query)
PostMessage(Message::TYPE_TASK, [this, params, viewport, handle](Processor & processor)
{
DoSearch(params, viewport, handle, query);
DoSearch(params, viewport, handle, processor);
});
return handle;
}

View file

@ -30,7 +30,7 @@ namespace search
{
namespace
{
class ProcessorV2Test : public SearchTest
class ProcessorTest : public SearchTest
{
public:
unique_ptr<TestSearchRequest> MakeRequest(string const & query)
@ -53,7 +53,7 @@ public:
}
};
UNIT_CLASS_TEST(ProcessorV2Test, Smoke)
UNIT_CLASS_TEST(ProcessorTest, Smoke)
{
string const countryName = "Wonderland";
TestCountry wonderlandCountry(m2::PointD(10, 10), countryName, "en");
@ -193,7 +193,7 @@ UNIT_CLASS_TEST(ProcessorV2Test, Smoke)
}
}
UNIT_CLASS_TEST(ProcessorV2Test, SearchInWorld)
UNIT_CLASS_TEST(ProcessorTest, SearchInWorld)
{
string const countryName = "Wonderland";
TestCountry wonderland(m2::PointD(0, 0), countryName, "en");
@ -221,7 +221,7 @@ UNIT_CLASS_TEST(ProcessorV2Test, SearchInWorld)
}
}
UNIT_CLASS_TEST(ProcessorV2Test, SearchByName)
UNIT_CLASS_TEST(ProcessorTest, SearchByName)
{
string const countryName = "Wonderland";
TestCity london(m2::PointD(1, 1), "London", "en", 100 /* rank */);
@ -259,7 +259,7 @@ UNIT_CLASS_TEST(ProcessorV2Test, SearchByName)
}
}
UNIT_CLASS_TEST(ProcessorV2Test, DisableSuggests)
UNIT_CLASS_TEST(ProcessorTest, DisableSuggests)
{
TestCity london1(m2::PointD(1, 1), "London", "en", 100 /* rank */);
TestCity london2(m2::PointD(-1, -1), "London", "en", 100 /* rank */);
@ -286,7 +286,7 @@ UNIT_CLASS_TEST(ProcessorV2Test, DisableSuggests)
}
}
UNIT_CLASS_TEST(ProcessorV2Test, TestRankingInfo)
UNIT_CLASS_TEST(ProcessorTest, TestRankingInfo)
{
string const countryName = "Wonderland";
@ -367,7 +367,7 @@ UNIT_CLASS_TEST(ProcessorV2Test, TestRankingInfo)
}
}
UNIT_CLASS_TEST(ProcessorV2Test, TestPostcodes)
UNIT_CLASS_TEST(ProcessorTest, TestPostcodes)
{
string const countryName = "Russia";
@ -441,7 +441,6 @@ UNIT_CLASS_TEST(ProcessorV2Test, TestPostcodes)
{
TRules rules{ExactMatch(countryId, building28), ExactMatch(countryId, building29)};
TEST(ResultsMatch("Долгопрудный первомайская 141701", "ru", rules), ());
}
{
TRules rules{ExactMatch(countryId, building28), ExactMatch(countryId, building29)};
@ -462,7 +461,7 @@ UNIT_CLASS_TEST(ProcessorV2Test, TestPostcodes)
}
}
UNIT_CLASS_TEST(ProcessorV2Test, TestCategories)
UNIT_CLASS_TEST(ProcessorTest, TestCategories)
{
string const countryName = "Wonderland";

View file

@ -19,10 +19,10 @@ macx-*: LIBS *= "-framework IOKit"
SOURCES += \
../../testing/testingmain.cpp \
helpers.cpp \
search_query_v2_test.cpp \
smoke_test.cpp \
generate_tests.cpp \
helpers.cpp \
processor_test.cpp \
smoke_test.cpp \
HEADERS += \
helpers.hpp \

View file

@ -1,73 +0,0 @@
#include "search/v2/processor_v2.hpp"
#include "search/dummy_rank_table.hpp"
#include "indexer/rank_table.hpp"
#include "geometry/mercator.hpp"
#include "geometry/rect2d.hpp"
#include "base/macros.hpp"
namespace search
{
namespace v2
{
ProcessorV2::ProcessorV2(Index & index, CategoriesHolder const & categories,
vector<Suggest> const & suggests,
storage::CountryInfoGetter const & infoGetter)
: Processor(index, categories, suggests, infoGetter), m_geocoder(index, infoGetter)
{
m_keepHouseNumberInQuery = true;
}
void ProcessorV2::Reset()
{
Processor::Reset();
m_geocoder.Reset();
}
void ProcessorV2::Cancel()
{
Processor::Cancel();
m_geocoder.Cancel();
}
void ProcessorV2::Search(Results & results, size_t limit)
{
if (m_tokens.empty())
SuggestStrings(results);
Geocoder::Params params;
InitParams(false /* localitySearch */, params);
params.m_mode = m_mode;
params.m_pivot = GetPivotRect();
params.m_accuratePivotCenter = GetPivotPoint();
m_geocoder.SetParams(params);
m_geocoder.GoEverywhere(m_preRanker);
FlushResults(params, results, false /* allMWMs */, limit, false /* oldHouseSearch */);
}
void ProcessorV2::SearchViewportPoints(Results & results)
{
Geocoder::Params params;
InitParams(false /* localitySearch */, params);
params.m_pivot = m_viewport[CURRENT_V];
params.m_accuratePivotCenter = params.m_pivot.Center();
m_geocoder.SetParams(params);
m_geocoder.GoInViewport(m_preRanker);
FlushViewportResults(params, results, false /* oldHouseSearch */);
}
void ProcessorV2::ClearCaches()
{
Processor::ClearCaches();
m_geocoder.ClearCaches();
}
} // namespace v2
} // namespace search

View file

@ -1,29 +0,0 @@
#pragma once
#include "search/processor.hpp"
#include "search/v2/geocoder.hpp"
namespace search
{
namespace v2
{
class ProcessorV2 : public Processor
{
public:
ProcessorV2(Index & index, CategoriesHolder const & categories, vector<Suggest> const & suggests,
storage::CountryInfoGetter const & infoGetter);
// my::Cancellable overrides:
void Reset() override;
void Cancel() override;
// Query overrides:
void Search(Results & results, size_t limit) override;
void SearchViewportPoints(Results & results) override;
void ClearCaches() override;
protected:
Geocoder m_geocoder;
};
} // namespace v2
} // namespace search