diff --git a/search/keyword_matcher.cpp b/search/keyword_matcher.cpp index d6583d9b66..711516abda 100644 --- a/search/keyword_matcher.cpp +++ b/search/keyword_matcher.cpp @@ -40,13 +40,22 @@ void KeywordMatcher::ProcessName(string const & name) if (!m_prefix.empty()) { - m_minPrefixMatchCost = min(m_minPrefixMatchCost, - m_prefixMatchFn(&m_prefix[0], m_prefix.size(), - &s[0], s.size(), - m_minPrefixMatchCost)); + uint32_t const matchCost = m_prefixMatchFn(&m_prefix[0], m_prefix.size(), + &s[0], s.size(), m_minPrefixMatchCost); + if (matchCost < m_minPrefixMatchCost) + { + m_bestPrefixMatch = name; + m_minPrefixMatchCost = matchCost; + } } else - m_minPrefixMatchCost = 0; + { + if (m_bestPrefixMatch.empty()) + { + m_bestPrefixMatch = name; + m_minPrefixMatchCost = 0; + } + } } } diff --git a/search/keyword_matcher.hpp b/search/keyword_matcher.hpp index e6968ea338..0d9e2ee549 100644 --- a/search/keyword_matcher.hpp +++ b/search/keyword_matcher.hpp @@ -23,6 +23,7 @@ class KeywordMatcher StringMatchFn m_keywordMatchFn, m_prefixMatchFn; buffer_vector m_minKeywordMatchCost; uint32_t m_minPrefixMatchCost; + string m_bestPrefixMatch; public: KeywordMatcher(strings::UniString * pKeywords, @@ -48,6 +49,8 @@ public: // Get match score for each keyword. uint32_t const * GetKeywordMatchScores() const { return &m_minKeywordMatchCost[0]; } + + string GetBestPrefixMatch() const { return m_bestPrefixMatch; } }; } // namespace search::impl diff --git a/search/query.cpp b/search/query.cpp index e9af464100..b3c1b3e31f 100644 --- a/search/query.cpp +++ b/search/query.cpp @@ -48,7 +48,7 @@ struct FeatureProcessor 512, 256 * max(0, int(m_query.m_prefix.size()) - 1), &KeywordMatch, &PrefixMatch); feature.ForEachNameRef(matcher); - m_query.AddResult(Result(feature.GetPreferredDrawableName(), feature.GetLimitRect(-1), + m_query.AddResult(Result(matcher.GetBestPrefixMatch(), feature.GetLimitRect(-1), matcher.GetMatchScore())); } };