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
diff options
context:
space:
mode:
authorMaxim Pimenov <m@maps.me>2020-07-17 02:31:16 +0300
committerTatiana Yan <tatiana.kondakova@gmail.com>2021-02-16 16:27:13 +0300
commitc9b9ac30831a4e7bbb251c099db12c090ecb4f17 (patch)
treed26fddf2bc7075e97dbebd5106210699ad742b18
parent553204622def0d7f3d454047ff55bd5ff1b92b5f (diff)
Review fixes.
-rw-r--r--search/processor.cpp25
-rw-r--r--search/processor.hpp5
2 files changed, 20 insertions, 10 deletions
diff --git a/search/processor.cpp b/search/processor.cpp
index 43b7737df0..34ccfc3d70 100644
--- a/search/processor.cpp
+++ b/search/processor.cpp
@@ -61,6 +61,7 @@
#include <algorithm>
#include <cctype>
#include <memory>
+#include <optional>
#include <set>
#include <sstream>
#include <utility>
@@ -441,12 +442,11 @@ void Processor::SearchByFeatureId()
if (m_query.size() > kMaxFeatureIdStringSize)
return;
- using Trie = base::MemTrie<storage::CountryId, base::VectorValues<bool>>;
- static Trie countriesTrie;
- if (countriesTrie.GetNumNodes() == 1)
+ if (m_countriesTrie == nullptr)
{
+ m_countriesTrie = make_unique<CountriesTrie>();
for (auto const & country : m_infoGetter.GetCountries())
- countriesTrie.Add(country.m_countryId, true);
+ m_countriesTrie->Add(country.m_countryId, true);
}
auto trimLeadingSpaces = [](string & s) {
@@ -473,7 +473,8 @@ void Processor::SearchByFeatureId()
return false;
};
- auto const eatMwmName = [&trimLeadingSpaces](string & s, storage::CountryId & mwmName) -> bool {
+ auto const eatMwmName = [this, &trimLeadingSpaces](string & s,
+ storage::CountryId & mwmName) -> bool {
trimLeadingSpaces(s);
// Greedily eat as much as possible because some country names are prefixes of others.
@@ -481,7 +482,7 @@ void Processor::SearchByFeatureId()
for (size_t i = 0; i < s.size(); ++i)
{
// todo(@m) This must be much faster but MemTrie's iterators do not expose nodes.
- if (countriesTrie.HasKey(s.substr(0, i)))
+ if (m_countriesTrie->HasKey(s.substr(0, i)))
lastPos = i;
}
if (!lastPos)
@@ -519,6 +520,8 @@ void Processor::SearchByFeatureId()
string query(m_query);
strings::Trim(query);
+ strings::EatPrefix(query, "?");
+
string const kFidPrefix = "fid";
bool hasPrefix = false;
@@ -582,12 +585,16 @@ void Processor::SearchByFeatureId()
}
}
- auto const tryEmitting = [this, &infos](storage::CountryId const & mwmName, uint32_t fid) {
+ auto const tryEmitting = [this, &infos](storage::CountryId const & mwmName,
+ optional<uint32_t> version, uint32_t fid) {
for (auto const & info : infos)
{
if (info->GetCountryName() != mwmName)
continue;
+ if (version && version != info->GetVersion())
+ continue;
+
auto guard = make_unique<FeaturesLoaderGuard>(m_dataSource, MwmSet::MwmId(info));
if (fid >= guard->GetNumFeatures())
continue;
@@ -615,7 +622,7 @@ void Processor::SearchByFeatureId()
if (parenPref == parenSuff && eatMwmName(s, mwmName) && strings::EatPrefix(s, ",") &&
eatFid(s, fid))
{
- tryEmitting(mwmName, fid);
+ tryEmitting(mwmName, {} /* version */, fid);
}
}
@@ -635,7 +642,7 @@ void Processor::SearchByFeatureId()
ok = ok && eatFid(s, fid);
ok = ok && strings::EatPrefix(s, " }");
if (ok)
- tryEmitting(mwmName, fid);
+ tryEmitting(mwmName, version, fid);
}
}
diff --git a/search/processor.hpp b/search/processor.hpp
index 61d88934d6..09196e086d 100644
--- a/search/processor.hpp
+++ b/search/processor.hpp
@@ -23,6 +23,7 @@
#include "geometry/rect2d.hpp"
#include "base/cancellable.hpp"
+#include "base/mem_trie.hpp"
#include "base/string_utils.hpp"
#include <cstddef>
@@ -116,7 +117,7 @@ public:
protected:
// Show feature by FeatureId. May try to guess as much as possible after the "fid=" prefix but
// at least supports the formats below.
- // 0. fid=123 to search for the feature with index 123, results ordered by distance
+ // 0. fid=123 or ?fid=123 to search for the feature with index 123, results ordered by distance
// from |m_position| or |m_viewport|, whichever is present and closer.
// 1. fid=MwmName,123 or fid=(MwmName,123) to search for the feature with
// index 123 in the Mwm "MwmName" (for example, "Laos" or "Laos.mwm").
@@ -139,6 +140,8 @@ protected:
CategoriesHolder const & m_categories;
storage::CountryInfoGetter const & m_infoGetter;
+ using CountriesTrie = base::MemTrie<storage::CountryId, base::VectorValues<bool>>;
+ std::unique_ptr<CountriesTrie> m_countriesTrie;
std::string m_region;
std::string m_query;