From c7350fe933afb84e0cded4b9ed4af93c9279c868 Mon Sep 17 00:00:00 2001 From: vng Date: Wed, 30 Sep 2015 13:19:01 +0300 Subject: [PATCH] [search] Fixed search for Apple-specific emoji variations. --- search/search_query.cpp | 18 ++++++++++++++++++ search/search_query.hpp | 2 ++ 2 files changed, 20 insertions(+) diff --git a/search/search_query.cpp b/search/search_query.cpp index 28b64367fc..20eb6aac90 100644 --- a/search/search_query.cpp +++ b/search/search_query.cpp @@ -368,16 +368,34 @@ void Query::ForEachCategoryTypes(ToDo toDo) const { for (int j = 0; j < localesCount; ++j) m_pCategories->ForEachTypeByName(arrLocales[j], m_tokens[i], bind(ref(toDo), i, _1)); + + ProcessEmojiIfNeeded(m_tokens[i], i, toDo); } if (!m_prefix.empty()) { for (int j = 0; j < localesCount; ++j) m_pCategories->ForEachTypeByName(arrLocales[j], m_prefix, bind(ref(toDo), tokensCount, _1)); + + ProcessEmojiIfNeeded(m_prefix, tokensCount, toDo); } } } +template +void Query::ProcessEmojiIfNeeded(strings::UniString const & token, size_t ind, ToDo & toDo) const +{ + // Special process of 2 codepoints emoji (e.g. black guy on a bike). + // Only emoji synonyms can have one codepoint. + if (token.size() > 1) + { + static int8_t const enLocaleCode = CategoriesHolder::MapLocaleToInteger("en"); + + m_pCategories->ForEachTypeByName(enLocaleCode, strings::UniString(1, token[0]), + bind(ref(toDo), ind, _1)); + } +} + void Query::SetQuery(string const & query) { m_query = &query; diff --git a/search/search_query.hpp b/search/search_query.hpp index 10c45a6f76..1c4236859f 100644 --- a/search/search_query.hpp +++ b/search/search_query.hpp @@ -129,6 +129,8 @@ private: int GetCategoryLocales(int8_t (&arr) [3]) const; template void ForEachCategoryTypes(ToDo toDo) const; + template void ProcessEmojiIfNeeded( + strings::UniString const & token, size_t ind, ToDo & toDo) const; using TMWMVector = vector>; using TOffsetsVector = map>;