[search] Replaced Token's ForEach with a more descriptive ForEachSynonym.

This commit is contained in:
Maxim Pimenov 2019-07-09 17:54:45 +03:00 committed by Tatiana Yan
parent 7f92a8b56d
commit 9c7dfb9cc3
10 changed files with 23 additions and 23 deletions

View file

@ -51,15 +51,14 @@ private:
void Retrieve(QueryParams::Token const & token, Fn && fn) const
{
SearchTrieRequest<DFA> request;
token.ForEach([&request](strings::UniString const & s)
{
request.m_names.emplace_back(BuildLevenshteinDFA(s));
});
token.ForEachSynonym([&request](strings::UniString const & s) {
request.m_names.emplace_back(BuildLevenshteinDFA(s));
});
request.m_langs.insert(StringUtf8Multilang::kDefaultCode);
MatchFeaturesInTrie(request, m_index.GetRootIterator(),
[](Id const & /* id */) { return true; } /* filter */,
std::forward<Fn>(fn));
MatchFeaturesInTrie(
request, m_index.GetRootIterator(), [](Id const & /* id */) { return true; } /* filter */,
std::forward<Fn>(fn));
}
QueryVec GetQueryVec(IdfMap & idfs, QueryParams const & params) const;

View file

@ -334,7 +334,7 @@ void MatchPostcodesInTrie(TokenSlice const & slice, trie::Iterator<ValueList> co
// 2. For prefix match query like "streetname 40" where |streetname| is located in 40xxx
// postcode zone will give all street vicinity as the result which is wrong.
std::vector<UniStringDFA> dfas;
slice.Get(i).ForEach([&dfas](UniString const & s) { dfas.emplace_back(s); });
slice.Get(i).ForEachSynonym([&dfas](UniString const & s) { dfas.emplace_back(s); });
MatchInTrie(dfas, TrieRootPrefix<ValueList>(*postcodesRoot, edge), intersector);
intersector.NextStep();

View file

@ -366,7 +366,7 @@ void Geocoder::SetParams(Params const & params)
{
m_tokenRequests.emplace_back();
auto & request = m_tokenRequests.back();
m_params.GetToken(i).ForEach([&request](UniString const & s) {
m_params.GetToken(i).ForEachSynonym([&request](UniString const & s) {
request.m_names.emplace_back(BuildLevenshteinDFA(s));
});
for (auto const & index : m_params.GetTypeIndices(i))
@ -376,7 +376,7 @@ void Geocoder::SetParams(Params const & params)
else
{
auto & request = m_prefixTokenRequest;
m_params.GetToken(i).ForEach([&request](UniString const & s) {
m_params.GetToken(i).ForEachSynonym([&request](UniString const & s) {
request.m_names.emplace_back(BuildLevenshteinDFA(s));
});
for (auto const & index : m_params.GetTypeIndices(i))

View file

@ -103,7 +103,7 @@ void LocalityScorer::GetTopLocalities(MwmSet::MwmId const & countryId, BaseConte
auto const df = intersections.back().m_features.PopCount();
if (df != 0)
{
m_params.GetToken(i).ForEach([&tokensToDf, &df](UniString const & s) {
m_params.GetToken(i).ForEachSynonym([&tokensToDf, &df](UniString const & s) {
tokensToDf.emplace_back(BuildLevenshteinDFA(s), df);
});
}
@ -116,7 +116,7 @@ void LocalityScorer::GetTopLocalities(MwmSet::MwmId const & countryId, BaseConte
auto const prefixDf = intersections.back().m_features.PopCount();
if (prefixDf != 0)
{
m_params.GetToken(count).ForEach([&prefixToDf, &prefixDf](UniString const & s) {
m_params.GetToken(count).ForEachSynonym([&prefixToDf, &prefixDf](UniString const & s) {
prefixToDf.emplace_back(PrefixDFAModifier<LevenshteinDFA>(BuildLevenshteinDFA(s)),
prefixDf);
});

View file

@ -103,7 +103,7 @@ bool QueryParams::IsNumberTokens(TokenRange const & range) const
for (size_t i : range)
{
bool number = false;
GetToken(i).ForEach([&number](String const & s) {
GetToken(i).ForEachSynonym([&number](String const & s) {
if (feature::IsNumber(s))
{
number = true;

View file

@ -38,7 +38,7 @@ public:
// Calls |fn| on the original token and on synonyms.
template <typename Fn>
std::enable_if_t<std::is_same<std::result_of_t<Fn(String)>, void>::value> ForEach(
std::enable_if_t<std::is_same<std::result_of_t<Fn(String)>, void>::value> ForEachSynonym(
Fn && fn) const
{
fn(m_original);
@ -47,7 +47,7 @@ public:
// Calls |fn| on the original token and on synonyms until |fn| return false.
template <typename Fn>
std::enable_if_t<std::is_same<std::result_of_t<Fn(String)>, bool>::value> ForEach(
std::enable_if_t<std::is_same<std::result_of_t<Fn(String)>, bool>::value> ForEachSynonym(
Fn && fn) const
{
if (!fn(m_original))
@ -60,7 +60,7 @@ public:
}
template <typename Fn>
std::enable_if_t<std::is_same<std::result_of_t<Fn(String)>, bool>::value, bool> AnyOf(
std::enable_if_t<std::is_same<std::result_of_t<Fn(String)>, bool>::value, bool> AnyOfSynonyms(
Fn && fn) const
{
if (fn(m_original))

View file

@ -156,7 +156,7 @@ pair<ErrorsMade, size_t> MatchTokenRange(FeatureType & ft, Geocoder::Params cons
for (auto const token : range)
{
ErrorsMade tokenErrors;
params.GetToken(token).ForEach([&](strings::UniString const & s) {
params.GetToken(token).ForEachSynonym([&](strings::UniString const & s) {
tokenErrors = ErrorsMade::Max(tokenErrors, ErrorsMade{GetMaxErrorsForToken(s)});
});
errorsMade += tokenErrors;

View file

@ -70,12 +70,12 @@ namespace impl
{
bool FullMatch(QueryParams::Token const & token, UniString const & text)
{
return token.AnyOf([&text](UniString const & s) { return s == text; });
return token.AnyOfSynonyms([&text](UniString const & s) { return s == text; });
}
bool PrefixMatch(QueryParams::Token const & token, UniString const & text)
{
return token.AnyOf([&text](UniString const & s) { return StartsWith(text, s); });
return token.AnyOfSynonyms([&text](UniString const & s) { return StartsWith(text, s); });
}
ErrorsMade GetMinErrorsMade(vector<strings::UniString> const & tokens,

View file

@ -186,7 +186,7 @@ ErrorsMade GetErrorsMade(std::vector<strings::UniString> const & tokens, Slice c
for (size_t i = 0; i < slice.Size(); ++i)
{
ErrorsMade errorsMade;
slice.Get(i).ForEach([&](strings::UniString const & s) {
slice.Get(i).ForEachSynonym([&](strings::UniString const & s) {
errorsMade = ErrorsMade::Min(errorsMade, impl::GetMinErrorsMade(tokens, s));
});

View file

@ -78,17 +78,18 @@ public:
bool const isPrefixToken = m_params.IsPrefixToken(i);
vector<uint64_t> ids;
token.ForEach([&](UniString const & name) {
token.ForEachSynonym([&](UniString const & synonym) {
if (isPrefixToken)
{
m_searchIndex.ForEachInSubtree(name,
m_searchIndex.ForEachInSubtree(synonym,
[&](UniString const & /* prefix */, uint32_t featureId) {
ids.push_back(featureId);
});
}
else
{
m_searchIndex.ForEachInNode(name, [&](uint32_t featureId) { ids.push_back(featureId); });
m_searchIndex.ForEachInNode(synonym,
[&](uint32_t featureId) { ids.push_back(featureId); });
}
});