mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-30 01:24:07 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
46
search/suggest.cpp
Normal file
46
search/suggest.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "search/suggest.hpp"
|
||||
|
||||
#include "indexer/search_string_utils.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
namespace search
|
||||
{
|
||||
|
||||
std::string GetSuggestion(std::string const & name, QueryString const & query)
|
||||
{
|
||||
auto const nTokens = NormalizeAndTokenizeString(name);
|
||||
|
||||
bool prefixMatched = false;
|
||||
bool fullPrefixMatched = false;
|
||||
|
||||
for (auto const & token : nTokens)
|
||||
{
|
||||
if (StartsWith(token, query.m_prefix))
|
||||
{
|
||||
prefixMatched = true;
|
||||
fullPrefixMatched = token.size() == query.m_prefix.size();
|
||||
}
|
||||
}
|
||||
|
||||
// When |name| does not match prefix or when prefix equals to some
|
||||
// token of the |name| (for example, when user entered "Moscow"
|
||||
// without space at the end), we should not suggest anything.
|
||||
if (!prefixMatched || fullPrefixMatched)
|
||||
return {};
|
||||
|
||||
std::string suggest;
|
||||
for (auto const & token : query.m_tokens)
|
||||
{
|
||||
/// @todo Process street shorts like: st, av, ne, w, ..
|
||||
if (std::find(nTokens.begin(), nTokens.end(), token) == nTokens.end())
|
||||
{
|
||||
suggest += strings::ToUtf8(token);
|
||||
suggest += ' ';
|
||||
}
|
||||
}
|
||||
|
||||
return suggest + name + ' ';
|
||||
}
|
||||
} // namespace search
|
||||
Reference in New Issue
Block a user