Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: chrome/browser/autocomplete/search_provider.cc

Issue 470313004: [AiS] Use top local result for prefetch. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Score HistoryResults earlier if part of Answers FieldTrial Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/autocomplete/search_provider.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/autocomplete/search_provider.h" 5 #include "chrome/browser/autocomplete/search_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 match.allowed_to_be_default_match = true; 238 match.allowed_to_be_default_match = true;
239 matches_.push_back(match); 239 matches_.push_back(match);
240 } 240 }
241 Stop(true); 241 Stop(true);
242 return; 242 return;
243 } 243 }
244 244
245 input_ = input; 245 input_ = input;
246 246
247 DoHistoryQuery(minimal_changes); 247 DoHistoryQuery(minimal_changes);
248 // Answers needs the scored history results before any suggest query has been
249 // started.
250 if (OmniboxFieldTrial::EnableAnswersInSuggest()) {
groby-ooo-7-16 2014/08/22 23:09:56 Do we want a UMA histogram for the time spent here
251 scored_default_history_results_.clear();
252 scored_keyword_history_results_.clear();
253 ScoreHistoryResultsMultiWord(
254 default_history_results_, false, &scored_default_history_results_);
255 ScoreHistoryResultsMultiWord(
256 keyword_history_results_, true, &scored_keyword_history_results_);
257 }
248 DoAnswersQuery(input); 258 DoAnswersQuery(input);
249 StartOrStopSuggestQuery(minimal_changes); 259 StartOrStopSuggestQuery(minimal_changes);
250 UpdateMatches(); 260 UpdateMatches();
251 } 261 }
252 262
253 void SearchProvider::Stop(bool clear_cached_results) { 263 void SearchProvider::Stop(bool clear_cached_results) {
254 StopSuggest(); 264 StopSuggest();
255 done_ = true; 265 done_ = true;
256 266
257 if (clear_cached_results) 267 if (clear_cached_results)
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 } 876 }
867 877
868 void SearchProvider::AddHistoryResultsToMap(const HistoryResults& results, 878 void SearchProvider::AddHistoryResultsToMap(const HistoryResults& results,
869 bool is_keyword, 879 bool is_keyword,
870 int did_not_accept_suggestion, 880 int did_not_accept_suggestion,
871 MatchMap* map) { 881 MatchMap* map) {
872 if (results.empty()) 882 if (results.empty())
873 return; 883 return;
874 884
875 base::TimeTicks start_time(base::TimeTicks::Now()); 885 base::TimeTicks start_time(base::TimeTicks::Now());
876 bool prevent_inline_autocomplete = input_.prevent_inline_autocomplete() ||
877 (input_.type() == metrics::OmniboxInputType::URL);
878 const base::string16& input_text =
879 is_keyword ? keyword_input_.text() : input_.text();
880 bool input_multiple_words = HasMultipleWords(input_text);
881 886
882 SearchSuggestionParser::SuggestResults scored_results; 887 // Until Answers becomes default, scoring of history results will still happen
883 if (!prevent_inline_autocomplete && input_multiple_words) { 888 // here for non-Answers Chrome, to prevent any impact on timing measurements.
884 // ScoreHistoryResults() allows autocompletion of multi-word, 1-visit 889 // Answers FieldTrials will instead use scoring results obtained previously.
885 // queries if the input also has multiple words. But if we were already 890 SearchSuggestionParser::SuggestResults local_scored_results;
886 // scoring a multi-word, multi-visit query aggressively, and the current 891 const SearchSuggestionParser::SuggestResults* scored_results = NULL;
887 // input is still a prefix of it, then changing the suggestion suddenly 892 if (!OmniboxFieldTrial::EnableAnswersInSuggest()) {
groby-ooo-7-16 2014/08/22 23:09:56 Since scoring can now take two different paths - s
888 // feels wrong. To detect this case, first score as if only one word has 893 ScoreHistoryResultsMultiWord(results, is_keyword, &local_scored_results);
889 // been typed, then check if the best result came from aggressive search 894 scored_results = &local_scored_results;
890 // history scoring. If it did, then just keep that score set. This 895 } else {
891 // 1200 the lowest possible score in CalculateRelevanceForHistory()'s 896 scored_results = is_keyword ? &scored_keyword_history_results_
892 // aggressive-scoring curve. 897 : &scored_default_history_results_;
893 scored_results = ScoreHistoryResults(results, prevent_inline_autocomplete,
894 false, input_text, is_keyword);
895 if ((scored_results.front().relevance() < 1200) ||
896 !HasMultipleWords(scored_results.front().suggestion()))
897 scored_results.clear(); // Didn't detect the case above, score normally.
898 } 898 }
899 if (scored_results.empty()) 899 DCHECK(scored_results);
900 scored_results = ScoreHistoryResults(results, prevent_inline_autocomplete, 900
901 input_multiple_words, input_text,
902 is_keyword);
903 for (SearchSuggestionParser::SuggestResults::const_iterator i( 901 for (SearchSuggestionParser::SuggestResults::const_iterator i(
904 scored_results.begin()); i != scored_results.end(); ++i) { 902 scored_results->begin()); i != scored_results->end(); ++i) {
905 AddMatchToMap(*i, std::string(), did_not_accept_suggestion, true, 903 AddMatchToMap(*i, std::string(), did_not_accept_suggestion, true,
906 providers_.GetKeywordProviderURL() != NULL, map); 904 providers_.GetKeywordProviderURL() != NULL, map);
907 } 905 }
908 UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.AddHistoryResultsTime", 906 UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.AddHistoryResultsTime",
909 base::TimeTicks::Now() - start_time); 907 base::TimeTicks::Now() - start_time);
910 } 908 }
911 909
912 SearchSuggestionParser::SuggestResults SearchProvider::ScoreHistoryResults( 910 SearchSuggestionParser::SuggestResults SearchProvider::ScoreHistoryResults(
913 const HistoryResults& results, 911 const HistoryResults& results,
914 bool base_prevent_inline_autocomplete, 912 bool base_prevent_inline_autocomplete,
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 for (SearchSuggestionParser::SuggestResults::iterator i( 1012 for (SearchSuggestionParser::SuggestResults::iterator i(
1015 scored_results.begin()); i != scored_results.end(); ++i) { 1013 scored_results.begin()); i != scored_results.end(); ++i) {
1016 if ((last_relevance != 0) && (i->relevance() >= last_relevance)) 1014 if ((last_relevance != 0) && (i->relevance() >= last_relevance))
1017 i->set_relevance(last_relevance - 1); 1015 i->set_relevance(last_relevance - 1);
1018 last_relevance = i->relevance(); 1016 last_relevance = i->relevance();
1019 } 1017 }
1020 1018
1021 return scored_results; 1019 return scored_results;
1022 } 1020 }
1023 1021
1022 void SearchProvider::ScoreHistoryResultsMultiWord(
1023 const HistoryResults& results,
1024 bool is_keyword,
1025 SearchSuggestionParser::SuggestResults* scored_results) {
1026 bool prevent_inline_autocomplete =
1027 input_.prevent_inline_autocomplete() ||
1028 (input_.type() == metrics::OmniboxInputType::URL);
1029 const base::string16& input_text =
1030 is_keyword ? keyword_input_.text() : input_.text();
1031 bool input_multiple_words = HasMultipleWords(input_text);
1032
1033 if (!prevent_inline_autocomplete && input_multiple_words) {
1034 // ScoreHistoryResults() allows autocompletion of multi-word, 1-visit
1035 // queries if the input also has multiple words. But if we were already
1036 // scoring a multi-word, multi-visit query aggressively, and the current
1037 // input is still a prefix of it, then changing the suggestion suddenly
1038 // feels wrong. To detect this case, first score as if only one word has
1039 // been typed, then check if the best result came from aggressive search
1040 // history scoring. If it did, then just keep that score set. This
1041 // 1200 the lowest possible score in CalculateRelevanceForHistory()'s
1042 // aggressive-scoring curve.
1043 *scored_results = ScoreHistoryResults(
1044 results, prevent_inline_autocomplete, false, input_text, is_keyword);
1045 if ((scored_results->front().relevance() < 1200) ||
1046 !HasMultipleWords(scored_results->front().suggestion()))
1047 scored_results->clear(); // Didn't detect the case above, score normally.
1048 }
1049 if (scored_results->empty())
1050 *scored_results = ScoreHistoryResults(results, prevent_inline_autocomplete,
1051 input_multiple_words, input_text,
1052 is_keyword);
1053 }
1054
1024 void SearchProvider::AddSuggestResultsToMap( 1055 void SearchProvider::AddSuggestResultsToMap(
1025 const SearchSuggestionParser::SuggestResults& results, 1056 const SearchSuggestionParser::SuggestResults& results,
1026 const std::string& metadata, 1057 const std::string& metadata,
1027 MatchMap* map) { 1058 MatchMap* map) {
1028 for (size_t i = 0; i < results.size(); ++i) { 1059 for (size_t i = 0; i < results.size(); ++i) {
1029 AddMatchToMap(results[i], metadata, i, false, 1060 AddMatchToMap(results[i], metadata, i, false,
1030 providers_.GetKeywordProviderURL() != NULL, map); 1061 providers_.GetKeywordProviderURL() != NULL, map);
1031 } 1062 }
1032 } 1063 }
1033 1064
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 last_answer_seen_.query_type = match->answer_type; 1291 last_answer_seen_.query_type = match->answer_type;
1261 } 1292 }
1262 1293
1263 void SearchProvider::DoAnswersQuery(const AutocompleteInput& input) { 1294 void SearchProvider::DoAnswersQuery(const AutocompleteInput& input) {
1264 // If the query text starts with trimmed input, this is valid prefetch data. 1295 // If the query text starts with trimmed input, this is valid prefetch data.
1265 prefetch_data_ = StartsWith(last_answer_seen_.full_query_text, 1296 prefetch_data_ = StartsWith(last_answer_seen_.full_query_text,
1266 base::CollapseWhitespace(input.text(), false), 1297 base::CollapseWhitespace(input.text(), false),
1267 false) ? 1298 false) ?
1268 last_answer_seen_ : AnswersQueryData(); 1299 last_answer_seen_ : AnswersQueryData();
1269 } 1300 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/search_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698