Chromium Code Reviews| Index: chrome/browser/autocomplete/search_provider.cc |
| diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc |
| index f1e02da9162e21b9aee5ff4151960043caa7cd30..49cc988a947d85868f33dae3e1b82ed147c39e82 100644 |
| --- a/chrome/browser/autocomplete/search_provider.cc |
| +++ b/chrome/browser/autocomplete/search_provider.cc |
| @@ -783,7 +783,6 @@ void SearchProvider::ConvertResultsToAutocompleteMatches() { |
| int did_not_accept_keyword_suggestion = keyword_suggest_results_.empty() ? |
| TemplateURLRef::NO_SUGGESTIONS_AVAILABLE : |
| TemplateURLRef::NO_SUGGESTION_CHOSEN; |
| - // Keyword what you typed results are handled by the KeywordProvider. |
| int verbatim_relevance = GetVerbatimRelevance(); |
| int did_not_accept_default_suggestion = default_suggest_results_.empty() ? |
| @@ -794,7 +793,23 @@ void SearchProvider::ConvertResultsToAutocompleteMatches() { |
| AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, |
| did_not_accept_default_suggestion, false, &map); |
| } |
| - const size_t what_you_typed_size = map.size(); |
| + if (!keyword_input_text_.empty()) { |
| + const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); |
| + // We only create the verbatim search query match for a keyword |
| + // if it's not an extension keyword. Extension keywords are handled |
| + // in KeywordProvider::Start(). (Extensions are complicated...) |
| + // Note: in this provider, SEARCH_OTHER_ENGINE must correspond |
| + // to the keyword verbatim search query. Do not create other matches |
| + // of type SEARCH_OTHER_ENGINE. |
| + if (keyword_url && !keyword_url->IsExtensionKeyword()) { |
| + AddMatchToMap(keyword_input_text_, keyword_input_text_, |
| + CalculateRelevanceForKeywordVerbatim( |
| + input_.type(), input_.prefer_keyword()), |
| + AutocompleteMatch::SEARCH_OTHER_ENGINE, |
| + did_not_accept_keyword_suggestion, true, &map); |
| + } |
| + } |
| + const size_t verbatim_matches_size = map.size(); |
| if (!default_provider_suggestion_.text.empty() && |
| default_provider_suggestion_.type == INSTANT_SUGGESTION_SEARCH && |
| !input_.prevent_inline_autocomplete()) |
| @@ -830,8 +845,8 @@ void SearchProvider::ConvertResultsToAutocompleteMatches() { |
| AddNavigationResultsToMatches(keyword_navigation_results_, true); |
| AddNavigationResultsToMatches(default_navigation_results_, false); |
| - // Allow an additional match for "what you typed" if it's present. |
| - const size_t max_total_matches = kMaxMatches + what_you_typed_size; |
| + // Allow additional match(es) for verbatim results if present. |
| + const size_t max_total_matches = kMaxMatches + verbatim_matches_size; |
| std::partial_sort(matches_.begin(), |
| matches_.begin() + std::min(max_total_matches, matches_.size()), |
| matches_.end(), &AutocompleteMatch::MoreRelevant); |
| @@ -865,12 +880,17 @@ bool SearchProvider::IsTopMatchHighRankSearchForURL() const { |
| return input_.type() == AutocompleteInput::URL && |
| matches_.front().relevance > CalculateRelevanceForVerbatim() && |
| (matches_.front().type == AutocompleteMatch::SEARCH_SUGGEST || |
| - matches_.front().type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED); |
| + matches_.front().type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED || |
| + matches_.front().type == AutocompleteMatch::SEARCH_OTHER_ENGINE); |
| } |
| bool SearchProvider::IsTopMatchNotInlinable() const { |
| + // Note: this test assumes the SEARCH_OTHER_ENGINE match corresponds to |
| + // the verbatim search query on the keyword engine. SearchProvider should |
| + // not create any other match of type SEARCH_OTHER_ENGINE. |
| return matches_.front().type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED && |
| matches_.front().type != AutocompleteMatch::URL_WHAT_YOU_TYPED && |
| + matches_.front().type != AutocompleteMatch::SEARCH_OTHER_ENGINE && |
| matches_.front().inline_autocomplete_offset == string16::npos && |
| matches_.front().fill_into_edit != input_.text(); |
| } |
| @@ -902,10 +922,11 @@ void SearchProvider::UpdateMatches() { |
| ConvertResultsToAutocompleteMatches(); |
| } |
| if (IsTopMatchNotInlinable()) { |
| - // Disregard suggested relevances if the top match is not SWYT, inlinable, |
| - // or URL_WHAT_YOU_TYPED (which may be top match regardless of inlining). |
| - // For example, input "foo" should not invoke a search for "bar", which |
| - // would happen if the "bar" search match outranked all other matches. |
| + // Disregard suggested relevances if the top match is not a verbatim |
| + // match, inlinable, or URL_WHAT_YOU_TYPED (which may be top match |
| + // regardless of inlining). For example, input "foo" should not |
| + // invoke a search for "bar", which would happen if the "bar" search |
| + // match outranked all other matches. |
| ApplyCalculatedRelevance(); |
| ConvertResultsToAutocompleteMatches(); |
| } |
| @@ -1090,6 +1111,22 @@ int SearchProvider::CalculateRelevanceForVerbatim() const { |
| } |
| } |
| +// static |
| +int SearchProvider::CalculateRelevanceForKeywordVerbatim( |
| + AutocompleteInput::Type type, |
| + bool prefer_keyword) { |
| + // Perhaps this should be kept similar to |
|
Peter Kasting
2013/02/05 23:17:48
I'm not a huge fan of the "perhaps" comments here
Mark P
2013/02/06 01:31:59
I don't like these comments either. I think they
Peter Kasting
2013/02/06 02:01:41
My hope was either:
* Make the functions match an
Mark P
2013/02/06 04:31:14
My judgment call is that they don't need to match.
Peter Kasting
2013/02/06 18:47:34
Honestly, looking at these, it sure looks to me li
Mark P
2013/02/06 18:54:11
You are correct; that's how I made the function.
Peter Kasting
2013/02/06 19:00:09
That seems like the right comment, then:
// This
Mark P
2013/02/06 19:50:22
That comment sounds good to me. I copied and past
|
| + // KeywordProvider::CalculateRelevance(). That function calculates, |
| + // among other things, the verbatim query score for search keywords |
| + // but only extension-based ones. It would be a bit odd if the score |
| + // for a verbatim query for an extension keyword and for a |
| + // non-extension keyword differed dramatically (though no immediate |
| + // harm would come from it). |
| + if (prefer_keyword) |
| + return 1500; |
| + return type == AutocompleteInput::QUERY ? 1450 : 1100; |
|
Peter Kasting
2013/02/05 23:17:48
Nit: I'd put parens around binary subexpression fo
Mark P
2013/02/06 01:31:59
Done.
|
| +} |
| + |
| int SearchProvider::CalculateRelevanceForHistory( |
| const Time& time, |
| bool is_keyword, |