Files
comaps/search/suggest.cpp
Konstantin Pastbin e3e4a1985a 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
2025-05-08 21:10:51 +07:00

47 lines
1.1 KiB
C++

#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