#pragma once #include "search/keyword_matcher.hpp" #include "base/string_utils.hpp" #include #include #include #include #include namespace search { class KeywordLangMatcher { public: class Score { public: Score(); bool operator<(Score const & s) const; bool operator<=(Score const & s) const; private: friend class KeywordLangMatcher; friend std::string DebugPrint(Score const & score); Score(KeywordMatcher::Score const & score, int langScore); KeywordMatcher::Score m_parentScore; int m_langScore; }; // Constructs a matcher that supports up to |maxLanguageTiers| tiers. // All languages in the same tier are considered equal. // The lower the tier is, the more important the languages in it are. explicit KeywordLangMatcher(size_t maxLanguageTiers); // Defines the languages in the |tier| to be exactly |languages|. void SetLanguages(size_t const tier, std::vector && languages); // Calls |fn| on every language in every tier. Does not make a distinction // between languages in different tiers. template void ForEachLanguage(Fn && fn) const { for (auto const & langs : m_languagePriorities) { for (int8_t lang : langs) fn(lang); } } // Store references to keywords from source array of strings. inline void SetKeywords(strings::UniString const * keywords, size_t count, strings::UniString const & prefix) { m_keywordMatcher.SetKeywords(keywords, count, prefix); } // Returns the Score of the name (greater is better). Score CalcScore(int8_t lang, std::string const & name) const; Score CalcScore(int8_t lang, strings::UniString const & name) const; Score CalcScore(int8_t lang, strings::UniString const * tokens, size_t count) const; private: int CalcLangScore(int8_t lang) const; std::vector> m_languagePriorities; KeywordMatcher m_keywordMatcher; }; } // namespace search