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

Side by Side Diff: components/omnibox/browser/history_url_provider.cc

Issue 1286093006: Launch HQP & HUP score changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing Peters comments Created 5 years, 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "components/omnibox/browser/history_url_provider.h" 5 #include "components/omnibox/browser/history_url_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 } 107 }
108 108
109 // Calculates a new relevance score applying half-life time decaying to |count| 109 // Calculates a new relevance score applying half-life time decaying to |count|
110 // using |time_since_last_visit| and |score_buckets|. This function will never 110 // using |time_since_last_visit| and |score_buckets|. This function will never
111 // return a score higher than |undecayed_relevance|; in other words, it can only 111 // return a score higher than |undecayed_relevance|; in other words, it can only
112 // demote the old score. 112 // demote the old score.
113 double CalculateRelevanceUsingScoreBuckets( 113 double CalculateRelevanceUsingScoreBuckets(
114 const HUPScoringParams::ScoreBuckets& score_buckets, 114 const HUPScoringParams::ScoreBuckets& score_buckets,
115 const base::TimeDelta& time_since_last_visit, 115 const base::TimeDelta& time_since_last_visit,
116 int undecayed_relevance, 116 int undecayed_relevance,
117 int count) { 117 int undecayed_count) {
118 // Back off if above relevance cap. 118 // Back off if above relevance cap.
119 if ((score_buckets.relevance_cap() != -1) && 119 if ((score_buckets.relevance_cap() != -1) &&
120 (undecayed_relevance >= score_buckets.relevance_cap())) 120 (undecayed_relevance >= score_buckets.relevance_cap()))
121 return undecayed_relevance; 121 return undecayed_relevance;
122 122
123 // Time based decay using half-life time. 123 // Time based decay using half-life time.
124 double decayed_count = count; 124 double decayed_count = undecayed_count;
125 double decay_factor = score_buckets.HalfLifeTimeDecay(time_since_last_visit);
125 if (decayed_count > 0) 126 if (decayed_count > 0)
126 decayed_count *= score_buckets.HalfLifeTimeDecay(time_since_last_visit); 127 decayed_count *= decay_factor;
127 128
128 // Find a threshold where decayed_count >= bucket.
129 const HUPScoringParams::ScoreBuckets::CountMaxRelevance* score_bucket = NULL; 129 const HUPScoringParams::ScoreBuckets::CountMaxRelevance* score_bucket = NULL;
130 const double factor = (score_buckets.use_decay_factor() ? decay_factor :
Peter Kasting 2015/08/27 19:21:40 Nit: Break after ? rather than :
Ashok vardhan 2015/08/27 19:51:37 Done.
131 decayed_count);
130 for (size_t i = 0; i < score_buckets.buckets().size(); ++i) { 132 for (size_t i = 0; i < score_buckets.buckets().size(); ++i) {
131 score_bucket = &score_buckets.buckets()[i]; 133 score_bucket = &score_buckets.buckets()[i];
132 if (decayed_count >= score_bucket->first) 134 if (factor >= score_bucket->first)
133 break; // Buckets are in descending order, so we can ignore the rest. 135 break;
134 } 136 }
135 137
136 return (score_bucket && (undecayed_relevance > score_bucket->second)) ? 138 return (score_bucket && (undecayed_relevance > score_bucket->second)) ?
137 score_bucket->second : undecayed_relevance; 139 score_bucket->second : undecayed_relevance;
138 } 140 }
139 141
140 // Returns a new relevance score for the given |match| based on the 142 // Returns a new relevance score for the given |match| based on the
141 // |old_relevance| score and |scoring_params|. The new relevance score is 143 // |old_relevance| score and |scoring_params|. The new relevance score is
142 // guaranteed to be less than or equal to |old_relevance|. In other words, this 144 // guaranteed to be less than or equal to |old_relevance|. In other words, this
143 // function can only demote a score, never boost it. Returns |old_relevance| if 145 // function can only demote a score, never boost it. Returns |old_relevance| if
144 // experimental scoring is disabled. 146 // experimental scoring is disabled.
145 int CalculateRelevanceScoreUsingScoringParams( 147 int CalculateRelevanceScoreUsingScoringParams(
146 const history::HistoryMatch& match, 148 const history::HistoryMatch& match,
147 int old_relevance, 149 int old_relevance,
148 const HUPScoringParams& scoring_params) { 150 const HUPScoringParams& scoring_params) {
149 if (!scoring_params.experimental_scoring_enabled)
150 return old_relevance;
151
152 const base::TimeDelta time_since_last_visit = 151 const base::TimeDelta time_since_last_visit =
153 base::Time::Now() - match.url_info.last_visit(); 152 base::Time::Now() - match.url_info.last_visit();
154 153
155 int relevance = CalculateRelevanceUsingScoreBuckets( 154 int relevance = CalculateRelevanceUsingScoreBuckets(
156 scoring_params.typed_count_buckets, time_since_last_visit, old_relevance, 155 scoring_params.typed_count_buckets, time_since_last_visit, old_relevance,
157 match.url_info.typed_count()); 156 match.url_info.typed_count());
158 157
159 // Additional demotion (on top of typed_count demotion) of URLs that were 158 // Additional demotion (on top of typed_count demotion) of URLs that were
160 // never typed. 159 // never typed.
161 if (match.url_info.typed_count() == 0) { 160 if (match.url_info.typed_count() == 0) {
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 } 455 }
457 456
458 HistoryURLProviderParams::~HistoryURLProviderParams() { 457 HistoryURLProviderParams::~HistoryURLProviderParams() {
459 } 458 }
460 459
461 HistoryURLProvider::HistoryURLProvider(AutocompleteProviderClient* client, 460 HistoryURLProvider::HistoryURLProvider(AutocompleteProviderClient* client,
462 AutocompleteProviderListener* listener) 461 AutocompleteProviderListener* listener)
463 : HistoryProvider(AutocompleteProvider::TYPE_HISTORY_URL, client), 462 : HistoryProvider(AutocompleteProvider::TYPE_HISTORY_URL, client),
464 listener_(listener), 463 listener_(listener),
465 params_(NULL) { 464 params_(NULL) {
465 // Initialize the default HUP scoring params.
466 OmniboxFieldTrial::GetDefaultHUPScoringParams(&scoring_params_);
466 // Initialize HUP scoring params based on the current experiment. 467 // Initialize HUP scoring params based on the current experiment.
467 OmniboxFieldTrial::GetExperimentalHUPScoringParams(&scoring_params_); 468 OmniboxFieldTrial::GetExperimentalHUPScoringParams(&scoring_params_);
468 } 469 }
469 470
470 void HistoryURLProvider::Start(const AutocompleteInput& input, 471 void HistoryURLProvider::Start(const AutocompleteInput& input,
471 bool minimal_changes) { 472 bool minimal_changes) {
472 // NOTE: We could try hard to do less work in the |minimal_changes| case 473 // NOTE: We could try hard to do less work in the |minimal_changes| case
473 // here; some clever caching would let us reuse the raw matches from the 474 // here; some clever caching would let us reuse the raw matches from the
474 // history DB without re-querying. However, we'd still have to go back to 475 // history DB without re-querying. However, we'd still have to go back to
475 // the history thread to mark these up properly, and if pass 2 is currently 476 // the history thread to mark these up properly, and if pass 2 is currently
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, 1200 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0,
1200 match.contents.length(), ACMatchClassification::URL, 1201 match.contents.length(), ACMatchClassification::URL,
1201 &match.contents_class); 1202 &match.contents_class);
1202 } 1203 }
1203 match.description = info.title(); 1204 match.description = info.title();
1204 match.description_class = 1205 match.description_class =
1205 ClassifyDescription(params.input.text(), match.description); 1206 ClassifyDescription(params.input.text(), match.description);
1206 RecordAdditionalInfoFromUrlRow(info, &match); 1207 RecordAdditionalInfoFromUrlRow(info, &match);
1207 return match; 1208 return match;
1208 } 1209 }
OLDNEW
« no previous file with comments | « no previous file | components/omnibox/browser/omnibox_field_trial.h » ('j') | components/omnibox/browser/omnibox_field_trial.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698