Trim search query.

This commit is contained in:
vng 2013-08-11 12:54:58 +03:00
parent b55c51af3c
commit 90b6b5b6b7
3 changed files with 14 additions and 2 deletions

7
env/strings.cpp vendored
View file

@ -5,10 +5,17 @@
#include "../3rdparty/utf8proc/utf8proc.h"
#include <boost/algorithm/string.hpp>
namespace str
{
void Trim(string & s)
{
boost::trim(s);
}
string MakeNormalizeAndLowerUtf8(string const & s)
{
int const count = static_cast<int>(s.size());

2
env/strings.hpp vendored
View file

@ -14,6 +14,8 @@ template <class T> string ToString(T const & t)
return ss.str();
}
void Trim(string & s);
string MakeNormalizeAndLowerUtf8(string const & s);
template <class IterT>

View file

@ -42,7 +42,10 @@ void Storage::QueryArticleInfo(string const & prefix, double lat, double lon)
{
m_lastQuery.clear();
if (prefix.empty())
string query = prefix;
str::Trim(query);
if (query.empty())
{
size_t const count = m_info.size();
m_lastQuery.reserve(count);
@ -57,7 +60,7 @@ void Storage::QueryArticleInfo(string const & prefix, double lat, double lon)
// find range of articles by input query
typedef vector<ArticleInfo>::iterator IterT;
pair<IterT, IterT> range = equal_range(m_info.begin(), m_info.end(),
str::MakeNormalizeAndLowerUtf8(prefix),
str::MakeNormalizeAndLowerUtf8(query),
ArticleInfo::LessPrefix());
// filter duplicating redirects