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

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

Issue 20777006: Omnibox: Create Bundled Field Trial; Convert SearchHistory trial to it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Peter's comments Created 7 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 | Annotate | Revision Log
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/callback.h" 10 #include "base/callback.h"
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 const char SearchProvider::kFalse[] = "false"; 244 const char SearchProvider::kFalse[] = "false";
245 245
246 SearchProvider::SearchProvider(AutocompleteProviderListener* listener, 246 SearchProvider::SearchProvider(AutocompleteProviderListener* listener,
247 Profile* profile) 247 Profile* profile)
248 : AutocompleteProvider(listener, profile, 248 : AutocompleteProvider(listener, profile,
249 AutocompleteProvider::TYPE_SEARCH), 249 AutocompleteProvider::TYPE_SEARCH),
250 providers_(TemplateURLServiceFactory::GetForProfile(profile)), 250 providers_(TemplateURLServiceFactory::GetForProfile(profile)),
251 suggest_results_pending_(0), 251 suggest_results_pending_(0),
252 field_trial_triggered_(false), 252 field_trial_triggered_(false),
253 field_trial_triggered_in_session_(false), 253 field_trial_triggered_in_session_(false),
254 omnibox_start_margin_(-1), 254 omnibox_start_margin_(-1) {
255 prevent_search_history_inlining_(
256 OmniboxFieldTrial::SearchHistoryPreventInlining()),
257 disable_search_history_(
258 OmniboxFieldTrial::SearchHistoryDisable()) {
259 } 255 }
260 256
261 // static 257 // static
262 AutocompleteMatch SearchProvider::CreateSearchSuggestion( 258 AutocompleteMatch SearchProvider::CreateSearchSuggestion(
263 AutocompleteProvider* autocomplete_provider, 259 AutocompleteProvider* autocomplete_provider,
264 int relevance, 260 int relevance,
265 AutocompleteMatch::Type type, 261 AutocompleteMatch::Type type,
266 const TemplateURL* template_url, 262 const TemplateURL* template_url,
267 const string16& query_string, 263 const string16& query_string,
268 const string16& input_text, 264 const string16& input_text,
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 619
624 void SearchProvider::DoHistoryQuery(bool minimal_changes) { 620 void SearchProvider::DoHistoryQuery(bool minimal_changes) {
625 // The history query results are synchronous, so if minimal_changes is true, 621 // The history query results are synchronous, so if minimal_changes is true,
626 // we still have the last results and don't need to do anything. 622 // we still have the last results and don't need to do anything.
627 if (minimal_changes) 623 if (minimal_changes)
628 return; 624 return;
629 625
630 keyword_history_results_.clear(); 626 keyword_history_results_.clear();
631 default_history_results_.clear(); 627 default_history_results_.clear();
632 628
633 if (disable_search_history_) 629 if (OmniboxFieldTrial::SearchHistoryDisable(
630 input_.current_page_classification()))
Alexei Svitkine (slow) 2013/08/02 15:25:34 Peter, can you explain why this should be indented
Peter Kasting 2013/08/02 18:17:55 It's not indented differently. You indent 4 from
634 return; 631 return;
635 632
636 HistoryService* const history_service = 633 HistoryService* const history_service =
637 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 634 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
638 history::URLDatabase* url_db = history_service ? 635 history::URLDatabase* url_db = history_service ?
639 history_service->InMemoryDatabase() : NULL; 636 history_service->InMemoryDatabase() : NULL;
640 if (!url_db) 637 if (!url_db)
641 return; 638 return;
642 639
643 // Request history for both the keyword and default provider. We grab many 640 // Request history for both the keyword and default provider. We grab many
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 1193
1197 SearchProvider::SuggestResults SearchProvider::ScoreHistoryResults( 1194 SearchProvider::SuggestResults SearchProvider::ScoreHistoryResults(
1198 const HistoryResults& results, 1195 const HistoryResults& results,
1199 bool base_prevent_inline_autocomplete, 1196 bool base_prevent_inline_autocomplete,
1200 bool input_multiple_words, 1197 bool input_multiple_words,
1201 const string16& input_text, 1198 const string16& input_text,
1202 bool is_keyword) { 1199 bool is_keyword) {
1203 AutocompleteClassifier* classifier = 1200 AutocompleteClassifier* classifier =
1204 AutocompleteClassifierFactory::GetForProfile(profile_); 1201 AutocompleteClassifierFactory::GetForProfile(profile_);
1205 SuggestResults scored_results; 1202 SuggestResults scored_results;
1203 const bool prevent_search_history_inlining =
1204 OmniboxFieldTrial::SearchHistoryPreventInlining(
1205 input_.current_page_classification());
1206 for (HistoryResults::const_iterator i(results.begin()); i != results.end(); 1206 for (HistoryResults::const_iterator i(results.begin()); i != results.end();
1207 ++i) { 1207 ++i) {
1208 // Don't autocomplete multi-word queries that have only been seen once 1208 // Don't autocomplete multi-word queries that have only been seen once
1209 // unless the user has typed more than one word. 1209 // unless the user has typed more than one word.
1210 bool prevent_inline_autocomplete = base_prevent_inline_autocomplete || 1210 bool prevent_inline_autocomplete = base_prevent_inline_autocomplete ||
1211 (!input_multiple_words && (i->visits < 2) && HasMultipleWords(i->term)); 1211 (!input_multiple_words && (i->visits < 2) && HasMultipleWords(i->term));
1212 1212
1213 // Don't autocomplete search terms that would normally be treated as URLs 1213 // Don't autocomplete search terms that would normally be treated as URLs
1214 // when typed. For example, if the user searched for "google.com" and types 1214 // when typed. For example, if the user searched for "google.com" and types
1215 // "goog", don't autocomplete to the search term "google.com". Otherwise, 1215 // "goog", don't autocomplete to the search term "google.com". Otherwise,
1216 // the input will look like a URL but act like a search, which is confusing. 1216 // the input will look like a URL but act like a search, which is confusing.
1217 // NOTE: We don't check this in the following cases: 1217 // NOTE: We don't check this in the following cases:
1218 // * When inline autocomplete is disabled, we won't be inline 1218 // * When inline autocomplete is disabled, we won't be inline
1219 // autocompleting this term, so we don't need to worry about confusion as 1219 // autocompleting this term, so we don't need to worry about confusion as
1220 // much. This also prevents calling Classify() again from inside the 1220 // much. This also prevents calling Classify() again from inside the
1221 // classifier (which will corrupt state and likely crash), since the 1221 // classifier (which will corrupt state and likely crash), since the
1222 // classifier always disables inline autocomplete. 1222 // classifier always disables inline autocomplete.
1223 // * When the user has typed the whole term, the "what you typed" history 1223 // * When the user has typed the whole term, the "what you typed" history
1224 // match will outrank us for URL-like inputs anyway, so we need not do 1224 // match will outrank us for URL-like inputs anyway, so we need not do
1225 // anything special. 1225 // anything special.
1226 if (!prevent_inline_autocomplete && classifier && (i->term != input_text)) { 1226 if (!prevent_inline_autocomplete && classifier && (i->term != input_text)) {
1227 AutocompleteMatch match; 1227 AutocompleteMatch match;
1228 classifier->Classify(i->term, false, false, &match, NULL); 1228 classifier->Classify(i->term, false, false, &match, NULL);
1229 prevent_inline_autocomplete = 1229 prevent_inline_autocomplete =
1230 !AutocompleteMatch::IsSearchType(match.type); 1230 !AutocompleteMatch::IsSearchType(match.type);
1231 } 1231 }
1232 1232
1233 int relevance = CalculateRelevanceForHistory(i->time, is_keyword, 1233 int relevance = CalculateRelevanceForHistory(
1234 prevent_inline_autocomplete); 1234 i->time, is_keyword, !prevent_inline_autocomplete,
1235 prevent_search_history_inlining);
1235 scored_results.push_back( 1236 scored_results.push_back(
1236 SuggestResult(i->term, is_keyword, relevance, false)); 1237 SuggestResult(i->term, is_keyword, relevance, false));
1237 } 1238 }
1238 1239
1239 // History returns results sorted for us. However, we may have docked some 1240 // History returns results sorted for us. However, we may have docked some
1240 // results' scores, so things are no longer in order. Do a stable sort to get 1241 // results' scores, so things are no longer in order. Do a stable sort to get
1241 // things back in order without otherwise disturbing results with equal 1242 // things back in order without otherwise disturbing results with equal
1242 // scores, then force the scores to be unique, so that the order in which 1243 // scores, then force the scores to be unique, so that the order in which
1243 // they're shown is deterministic. 1244 // they're shown is deterministic.
1244 std::stable_sort(scored_results.begin(), scored_results.end(), 1245 std::stable_sort(scored_results.begin(), scored_results.end(),
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 *relevance_from_server = use_server_relevance; 1330 *relevance_from_server = use_server_relevance;
1330 return use_server_relevance ? 1331 return use_server_relevance ?
1331 keyword_results_.verbatim_relevance : 1332 keyword_results_.verbatim_relevance :
1332 CalculateRelevanceForKeywordVerbatim(keyword_input_.type(), 1333 CalculateRelevanceForKeywordVerbatim(keyword_input_.type(),
1333 keyword_input_.prefer_keyword()); 1334 keyword_input_.prefer_keyword());
1334 } 1335 }
1335 1336
1336 int SearchProvider::CalculateRelevanceForHistory( 1337 int SearchProvider::CalculateRelevanceForHistory(
1337 const base::Time& time, 1338 const base::Time& time,
1338 bool is_keyword, 1339 bool is_keyword,
1339 bool prevent_inline_autocomplete) const { 1340 bool use_aggressive_method,
1341 bool prevent_search_history_inlining) const {
1340 // The relevance of past searches falls off over time. There are two distinct 1342 // The relevance of past searches falls off over time. There are two distinct
1341 // equations used. If the first equation is used (searches to the primary 1343 // equations used. If the first equation is used (searches to the primary
1342 // provider that we want to inline autocomplete), the score is in the range 1344 // provider that we want to score aggressively), the score is in the range
1343 // 1300-1599 (unless |prevent_search_history_inlining_|, in which case 1345 // 1300-1599 (unless |prevent_search_history_inlining|, in which case
1344 // it's in the range 1200-1299). If the second equation is used the 1346 // it's in the range 1200-1299). If the second equation is used the
1345 // relevance of a search 15 minutes ago is discounted 50 points, while the 1347 // relevance of a search 15 minutes ago is discounted 50 points, while the
1346 // relevance of a search two weeks ago is discounted 450 points. 1348 // relevance of a search two weeks ago is discounted 450 points.
1347 double elapsed_time = std::max((base::Time::Now() - time).InSecondsF(), 0.0); 1349 double elapsed_time = std::max((base::Time::Now() - time).InSecondsF(), 0.0);
1348 bool is_primary_provider = is_keyword || !providers_.has_keyword_provider(); 1350 bool is_primary_provider = is_keyword || !providers_.has_keyword_provider();
1349 if (is_primary_provider && !prevent_inline_autocomplete) { 1351 if (is_primary_provider && use_aggressive_method) {
1350 // Searches with the past two days get a different curve. 1352 // Searches with the past two days get a different curve.
1351 const double autocomplete_time = 2 * 24 * 60 * 60; 1353 const double autocomplete_time = 2 * 24 * 60 * 60;
1352 if (elapsed_time < autocomplete_time) { 1354 if (elapsed_time < autocomplete_time) {
1353 int max_score = is_keyword ? 1599 : 1399; 1355 int max_score = is_keyword ? 1599 : 1399;
1354 if (prevent_search_history_inlining_) 1356 if (prevent_search_history_inlining)
1355 max_score = 1299; 1357 max_score = 1299;
1356 return max_score - static_cast<int>(99 * 1358 return max_score - static_cast<int>(99 *
1357 std::pow(elapsed_time / autocomplete_time, 2.5)); 1359 std::pow(elapsed_time / autocomplete_time, 2.5));
1358 } 1360 }
1359 elapsed_time -= autocomplete_time; 1361 elapsed_time -= autocomplete_time;
1360 } 1362 }
1361 1363
1362 const int score_discount = 1364 const int score_discount =
1363 static_cast<int>(6.5 * std::pow(elapsed_time, 0.3)); 1365 static_cast<int>(6.5 * std::pow(elapsed_time, 0.3));
1364 1366
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1514 it->set_relevance(max_query_relevance); 1516 it->set_relevance(max_query_relevance);
1515 it->set_relevance_from_server(relevance_from_server); 1517 it->set_relevance_from_server(relevance_from_server);
1516 } 1518 }
1517 } 1519 }
1518 1520
1519 void SearchProvider::UpdateDone() { 1521 void SearchProvider::UpdateDone() {
1520 // We're done when the timer isn't running, there are no suggest queries 1522 // We're done when the timer isn't running, there are no suggest queries
1521 // pending, and we're not waiting on Instant. 1523 // pending, and we're not waiting on Instant.
1522 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); 1524 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0);
1523 } 1525 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/search_provider.h ('k') | chrome/browser/omnibox/omnibox_field_trial.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698