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 c059c6ec2030c57e826980c33907b53beb5e7646..5fcaebc3a79f4f8687e4d82d5c8512f07bf91724 100644 |
| --- a/chrome/browser/autocomplete/search_provider.cc |
| +++ b/chrome/browser/autocomplete/search_provider.cc |
| @@ -245,6 +245,16 @@ void SearchProvider::Start(const AutocompleteInput& input, |
| input_ = input; |
| DoHistoryQuery(minimal_changes); |
| + // Answers needs the scored history results before any suggest query has been |
| + // started. |
| + if (OmniboxFieldTrial::EnableAnswersInSuggest()) { |
|
groby-ooo-7-16
2014/08/22 23:09:56
Do we want a UMA histogram for the time spent here
|
| + scored_default_history_results_.clear(); |
| + scored_keyword_history_results_.clear(); |
| + ScoreHistoryResultsMultiWord( |
| + default_history_results_, false, &scored_default_history_results_); |
| + ScoreHistoryResultsMultiWord( |
| + keyword_history_results_, true, &scored_keyword_history_results_); |
| + } |
| DoAnswersQuery(input); |
| StartOrStopSuggestQuery(minimal_changes); |
| UpdateMatches(); |
| @@ -873,35 +883,23 @@ void SearchProvider::AddHistoryResultsToMap(const HistoryResults& results, |
| return; |
| base::TimeTicks start_time(base::TimeTicks::Now()); |
| - bool prevent_inline_autocomplete = input_.prevent_inline_autocomplete() || |
| - (input_.type() == metrics::OmniboxInputType::URL); |
| - const base::string16& input_text = |
| - is_keyword ? keyword_input_.text() : input_.text(); |
| - bool input_multiple_words = HasMultipleWords(input_text); |
| - SearchSuggestionParser::SuggestResults scored_results; |
| - if (!prevent_inline_autocomplete && input_multiple_words) { |
| - // ScoreHistoryResults() allows autocompletion of multi-word, 1-visit |
| - // queries if the input also has multiple words. But if we were already |
| - // scoring a multi-word, multi-visit query aggressively, and the current |
| - // input is still a prefix of it, then changing the suggestion suddenly |
| - // feels wrong. To detect this case, first score as if only one word has |
| - // been typed, then check if the best result came from aggressive search |
| - // history scoring. If it did, then just keep that score set. This |
| - // 1200 the lowest possible score in CalculateRelevanceForHistory()'s |
| - // aggressive-scoring curve. |
| - scored_results = ScoreHistoryResults(results, prevent_inline_autocomplete, |
| - false, input_text, is_keyword); |
| - if ((scored_results.front().relevance() < 1200) || |
| - !HasMultipleWords(scored_results.front().suggestion())) |
| - scored_results.clear(); // Didn't detect the case above, score normally. |
| + // Until Answers becomes default, scoring of history results will still happen |
| + // here for non-Answers Chrome, to prevent any impact on timing measurements. |
| + // Answers FieldTrials will instead use scoring results obtained previously. |
| + SearchSuggestionParser::SuggestResults local_scored_results; |
| + const SearchSuggestionParser::SuggestResults* scored_results = NULL; |
| + if (!OmniboxFieldTrial::EnableAnswersInSuggest()) { |
|
groby-ooo-7-16
2014/08/22 23:09:56
Since scoring can now take two different paths - s
|
| + ScoreHistoryResultsMultiWord(results, is_keyword, &local_scored_results); |
| + scored_results = &local_scored_results; |
| + } else { |
| + scored_results = is_keyword ? &scored_keyword_history_results_ |
| + : &scored_default_history_results_; |
| } |
| - if (scored_results.empty()) |
| - scored_results = ScoreHistoryResults(results, prevent_inline_autocomplete, |
| - input_multiple_words, input_text, |
| - is_keyword); |
| + DCHECK(scored_results); |
| + |
| for (SearchSuggestionParser::SuggestResults::const_iterator i( |
| - scored_results.begin()); i != scored_results.end(); ++i) { |
| + scored_results->begin()); i != scored_results->end(); ++i) { |
| AddMatchToMap(*i, std::string(), did_not_accept_suggestion, true, |
| providers_.GetKeywordProviderURL() != NULL, map); |
| } |
| @@ -1021,6 +1019,39 @@ SearchSuggestionParser::SuggestResults SearchProvider::ScoreHistoryResults( |
| return scored_results; |
| } |
| +void SearchProvider::ScoreHistoryResultsMultiWord( |
| + const HistoryResults& results, |
| + bool is_keyword, |
| + SearchSuggestionParser::SuggestResults* scored_results) { |
| + bool prevent_inline_autocomplete = |
| + input_.prevent_inline_autocomplete() || |
| + (input_.type() == metrics::OmniboxInputType::URL); |
| + const base::string16& input_text = |
| + is_keyword ? keyword_input_.text() : input_.text(); |
| + bool input_multiple_words = HasMultipleWords(input_text); |
| + |
| + if (!prevent_inline_autocomplete && input_multiple_words) { |
| + // ScoreHistoryResults() allows autocompletion of multi-word, 1-visit |
| + // queries if the input also has multiple words. But if we were already |
| + // scoring a multi-word, multi-visit query aggressively, and the current |
| + // input is still a prefix of it, then changing the suggestion suddenly |
| + // feels wrong. To detect this case, first score as if only one word has |
| + // been typed, then check if the best result came from aggressive search |
| + // history scoring. If it did, then just keep that score set. This |
| + // 1200 the lowest possible score in CalculateRelevanceForHistory()'s |
| + // aggressive-scoring curve. |
| + *scored_results = ScoreHistoryResults( |
| + results, prevent_inline_autocomplete, false, input_text, is_keyword); |
| + if ((scored_results->front().relevance() < 1200) || |
| + !HasMultipleWords(scored_results->front().suggestion())) |
| + scored_results->clear(); // Didn't detect the case above, score normally. |
| + } |
| + if (scored_results->empty()) |
| + *scored_results = ScoreHistoryResults(results, prevent_inline_autocomplete, |
| + input_multiple_words, input_text, |
| + is_keyword); |
| +} |
| + |
| void SearchProvider::AddSuggestResultsToMap( |
| const SearchSuggestionParser::SuggestResults& results, |
| const std::string& metadata, |