OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/omnibox_field_trial.h" | 5 #include "components/omnibox/browser/omnibox_field_trial.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 // The maximum number of the autocomplete dynamic field trials (aka layers). | 38 // The maximum number of the autocomplete dynamic field trials (aka layers). |
39 const int kMaxAutocompleteDynamicFieldTrials = 5; | 39 const int kMaxAutocompleteDynamicFieldTrials = 5; |
40 | 40 |
41 | 41 |
42 // Concatenates the autocomplete dynamic field trial prefix with a field trial | 42 // Concatenates the autocomplete dynamic field trial prefix with a field trial |
43 // ID to form a complete autocomplete field trial name. | 43 // ID to form a complete autocomplete field trial name. |
44 std::string DynamicFieldTrialName(int id) { | 44 std::string DynamicFieldTrialName(int id) { |
45 return base::StringPrintf("%s%d", kAutocompleteDynamicFieldTrialPrefix, id); | 45 return base::StringPrintf("%s%d", kAutocompleteDynamicFieldTrialPrefix, id); |
46 } | 46 } |
47 | 47 |
| 48 void InitializeBucketsFromString(const std::string& bucket_string, |
| 49 ScoreBuckets* score_buckets) { |
| 50 // Clear the buckets. |
| 51 score_buckets->buckets().clear(); |
| 52 base::StringPairs kv_pairs; |
| 53 if (base::SplitStringIntoKeyValuePairs(bucket_string, ':', ',', &kv_pairs)) { |
| 54 for (base::StringPairs::const_iterator it = kv_pairs.begin(); |
| 55 it != kv_pairs.end(); ++it) { |
| 56 ScoreBuckets::CountMaxRelevance bucket; |
| 57 base::StringToDouble(it->first, &bucket.first); |
| 58 base::StringToInt(it->second, &bucket.second); |
| 59 score_buckets->buckets().push_back(bucket); |
| 60 } |
| 61 std::sort(score_buckets->buckets().begin(), |
| 62 score_buckets->buckets().end(), |
| 63 std::greater<ScoreBuckets::CountMaxRelevance>()); |
| 64 } |
| 65 } |
| 66 |
48 void InitializeScoreBuckets(const VariationParams& params, | 67 void InitializeScoreBuckets(const VariationParams& params, |
49 const char* relevance_cap_param, | 68 const char* relevance_cap_param, |
50 const char* half_life_param, | 69 const char* half_life_param, |
51 const char* score_buckets_param, | 70 const char* score_buckets_param, |
| 71 const char* use_decay_factor_param, |
52 ScoreBuckets* score_buckets) { | 72 ScoreBuckets* score_buckets) { |
53 VariationParams::const_iterator it = params.find(relevance_cap_param); | 73 VariationParams::const_iterator it = params.find(relevance_cap_param); |
54 if (it != params.end()) { | 74 if (it != params.end()) { |
55 int relevance_cap; | 75 int relevance_cap; |
56 if (base::StringToInt(it->second, &relevance_cap)) | 76 if (base::StringToInt(it->second, &relevance_cap)) |
57 score_buckets->set_relevance_cap(relevance_cap); | 77 score_buckets->set_relevance_cap(relevance_cap); |
58 } | 78 } |
59 | 79 |
| 80 it = params.find(use_decay_factor_param); |
| 81 if (it != params.end()) { |
| 82 int use_decay_factor; |
| 83 if (base::StringToInt(it->second, &use_decay_factor)) |
| 84 score_buckets->set_use_decay_factor(use_decay_factor != 0); |
| 85 } |
| 86 |
60 it = params.find(half_life_param); | 87 it = params.find(half_life_param); |
61 if (it != params.end()) { | 88 if (it != params.end()) { |
62 int half_life_days; | 89 int half_life_days; |
63 if (base::StringToInt(it->second, &half_life_days)) | 90 if (base::StringToInt(it->second, &half_life_days)) |
64 score_buckets->set_half_life_days(half_life_days); | 91 score_buckets->set_half_life_days(half_life_days); |
65 } | 92 } |
66 | 93 |
67 it = params.find(score_buckets_param); | 94 it = params.find(score_buckets_param); |
68 if (it != params.end()) { | 95 if (it != params.end()) { |
69 // The value of the score bucket is a comma-separated list of | 96 // The value of the score bucket is a comma-separated list of |
70 // {DecayedCount + ":" + MaxRelevance}. | 97 // {DecayedCount/DecayedFactor + ":" + MaxRelevance}. |
71 base::StringPairs kv_pairs; | 98 InitializeBucketsFromString(it->second, score_buckets); |
72 if (base::SplitStringIntoKeyValuePairs(it->second, ':', ',', &kv_pairs)) { | |
73 for (base::StringPairs::const_iterator it = kv_pairs.begin(); | |
74 it != kv_pairs.end(); ++it) { | |
75 ScoreBuckets::CountMaxRelevance bucket; | |
76 base::StringToDouble(it->first, &bucket.first); | |
77 base::StringToInt(it->second, &bucket.second); | |
78 score_buckets->buckets().push_back(bucket); | |
79 } | |
80 std::sort(score_buckets->buckets().begin(), | |
81 score_buckets->buckets().end(), | |
82 std::greater<ScoreBuckets::CountMaxRelevance>()); | |
83 } | |
84 } | 99 } |
85 } | 100 } |
86 | 101 |
87 } // namespace | 102 } // namespace |
88 | 103 |
89 HUPScoringParams::ScoreBuckets::ScoreBuckets() | 104 HUPScoringParams::ScoreBuckets::ScoreBuckets() |
90 : relevance_cap_(-1), | 105 : relevance_cap_(-1), |
91 half_life_days_(-1) { | 106 half_life_days_(-1) { |
92 } | 107 } |
93 | 108 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 // errors smartly. | 270 // errors smartly. |
256 int k, v; | 271 int k, v; |
257 base::StringToInt(it->first, &k); | 272 base::StringToInt(it->first, &k); |
258 base::StringToInt(it->second, &v); | 273 base::StringToInt(it->second, &v); |
259 (*demotions_by_type)[static_cast<AutocompleteMatchType::Type>(k)] = | 274 (*demotions_by_type)[static_cast<AutocompleteMatchType::Type>(k)] = |
260 static_cast<float>(v) / 100.0f; | 275 static_cast<float>(v) / 100.0f; |
261 } | 276 } |
262 } | 277 } |
263 } | 278 } |
264 | 279 |
| 280 void OmniboxFieldTrial::GetDefaultHUPScoringParams( |
| 281 HUPScoringParams* scoring_params) { |
| 282 ScoreBuckets* type_score_buckets = &scoring_params->typed_count_buckets; |
| 283 type_score_buckets->set_half_life_days(30); |
| 284 type_score_buckets->set_use_decay_factor(false); |
| 285 // Default typed count buckets based on decayed typed count. The |
| 286 // values here are based on the results of field trials to determine what |
| 287 // maximized overall result quality. |
| 288 const std::string& typed_count_score_buckets_str = |
| 289 "1.0:1413,0.97:1390,0.93:1360,0.85:1340,0.72:1320,0.50:1250,0.0:1203"; |
| 290 InitializeBucketsFromString(typed_count_score_buckets_str, |
| 291 type_score_buckets); |
| 292 |
| 293 ScoreBuckets* visit_score_buckets = &scoring_params->visited_count_buckets; |
| 294 visit_score_buckets->set_half_life_days(30); |
| 295 visit_score_buckets->set_use_decay_factor(false); |
| 296 // Buckets based on visit count. Like the typed count buckets above, the |
| 297 // values here were chosen based on field trials. Note that when a URL hasn't |
| 298 // been visited in the last 30 days, we clamp its score to 100, which |
| 299 // basically demotes it below any other results in the dropdown. |
| 300 const std::string& visit_count_score_buckets_str = "4.0:790,0.5:590,0.0:100"; |
| 301 InitializeBucketsFromString(visit_count_score_buckets_str, |
| 302 visit_score_buckets); |
| 303 } |
| 304 |
265 void OmniboxFieldTrial::GetExperimentalHUPScoringParams( | 305 void OmniboxFieldTrial::GetExperimentalHUPScoringParams( |
266 HUPScoringParams* scoring_params) { | 306 HUPScoringParams* scoring_params) { |
267 scoring_params->experimental_scoring_enabled = false; | 307 scoring_params->experimental_scoring_enabled = false; |
268 | 308 |
269 VariationParams params; | 309 VariationParams params; |
270 if (!variations::GetVariationParams(kBundledExperimentFieldTrialName, | 310 if (!variations::GetVariationParams(kBundledExperimentFieldTrialName, |
271 ¶ms)) | 311 ¶ms)) |
272 return; | 312 return; |
273 | 313 |
274 VariationParams::const_iterator it = params.find(kHUPNewScoringEnabledParam); | 314 VariationParams::const_iterator it = params.find(kHUPNewScoringEnabledParam); |
275 if (it != params.end()) { | 315 if (it != params.end()) { |
276 int enabled = 0; | 316 int enabled = 0; |
277 if (base::StringToInt(it->second, &enabled)) | 317 if (base::StringToInt(it->second, &enabled)) |
278 scoring_params->experimental_scoring_enabled = (enabled != 0); | 318 scoring_params->experimental_scoring_enabled = (enabled != 0); |
279 } | 319 } |
280 | 320 |
281 InitializeScoreBuckets(params, kHUPNewScoringTypedCountRelevanceCapParam, | 321 InitializeScoreBuckets(params, kHUPNewScoringTypedCountRelevanceCapParam, |
282 kHUPNewScoringTypedCountHalfLifeTimeParam, | 322 kHUPNewScoringTypedCountHalfLifeTimeParam, |
283 kHUPNewScoringTypedCountScoreBucketsParam, | 323 kHUPNewScoringTypedCountScoreBucketsParam, |
| 324 kHUPNewScoringTypedCountUseDecayFactorParam, |
284 &scoring_params->typed_count_buckets); | 325 &scoring_params->typed_count_buckets); |
285 InitializeScoreBuckets(params, kHUPNewScoringVisitedCountRelevanceCapParam, | 326 InitializeScoreBuckets(params, kHUPNewScoringVisitedCountRelevanceCapParam, |
286 kHUPNewScoringVisitedCountHalfLifeTimeParam, | 327 kHUPNewScoringVisitedCountHalfLifeTimeParam, |
287 kHUPNewScoringVisitedCountScoreBucketsParam, | 328 kHUPNewScoringVisitedCountScoreBucketsParam, |
| 329 kHUPNewScoringVisitedCountUseDecayFactorParam, |
288 &scoring_params->visited_count_buckets); | 330 &scoring_params->visited_count_buckets); |
289 } | 331 } |
290 | 332 |
291 int OmniboxFieldTrial::HQPBookmarkValue() { | 333 int OmniboxFieldTrial::HQPBookmarkValue() { |
292 std::string bookmark_value_str = | 334 std::string bookmark_value_str = |
293 variations::GetVariationParamValue(kBundledExperimentFieldTrialName, | 335 variations::GetVariationParamValue(kBundledExperimentFieldTrialName, |
294 kHQPBookmarkValueRule); | 336 kHQPBookmarkValueRule); |
295 if (bookmark_value_str.empty()) | 337 if (bookmark_value_str.empty()) |
296 return 10; | 338 return 10; |
297 // This is a best-effort conversion; we trust the hand-crafted parameters | 339 // This is a best-effort conversion; we trust the hand-crafted parameters |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 "PreventUWYTDefaultForNonURLInputs"; | 470 "PreventUWYTDefaultForNonURLInputs"; |
429 | 471 |
430 const char OmniboxFieldTrial::kHUPNewScoringEnabledParam[] = | 472 const char OmniboxFieldTrial::kHUPNewScoringEnabledParam[] = |
431 "HUPExperimentalScoringEnabled"; | 473 "HUPExperimentalScoringEnabled"; |
432 const char OmniboxFieldTrial::kHUPNewScoringTypedCountRelevanceCapParam[] = | 474 const char OmniboxFieldTrial::kHUPNewScoringTypedCountRelevanceCapParam[] = |
433 "TypedCountRelevanceCap"; | 475 "TypedCountRelevanceCap"; |
434 const char OmniboxFieldTrial::kHUPNewScoringTypedCountHalfLifeTimeParam[] = | 476 const char OmniboxFieldTrial::kHUPNewScoringTypedCountHalfLifeTimeParam[] = |
435 "TypedCountHalfLifeTime"; | 477 "TypedCountHalfLifeTime"; |
436 const char OmniboxFieldTrial::kHUPNewScoringTypedCountScoreBucketsParam[] = | 478 const char OmniboxFieldTrial::kHUPNewScoringTypedCountScoreBucketsParam[] = |
437 "TypedCountScoreBuckets"; | 479 "TypedCountScoreBuckets"; |
| 480 const char OmniboxFieldTrial::kHUPNewScoringTypedCountUseDecayFactorParam[] = |
| 481 "TypedCountUseDecayFactor"; |
438 const char OmniboxFieldTrial::kHUPNewScoringVisitedCountRelevanceCapParam[] = | 482 const char OmniboxFieldTrial::kHUPNewScoringVisitedCountRelevanceCapParam[] = |
439 "VisitedCountRelevanceCap"; | 483 "VisitedCountRelevanceCap"; |
440 const char OmniboxFieldTrial::kHUPNewScoringVisitedCountHalfLifeTimeParam[] = | 484 const char OmniboxFieldTrial::kHUPNewScoringVisitedCountHalfLifeTimeParam[] = |
441 "VisitedCountHalfLifeTime"; | 485 "VisitedCountHalfLifeTime"; |
442 const char OmniboxFieldTrial::kHUPNewScoringVisitedCountScoreBucketsParam[] = | 486 const char OmniboxFieldTrial::kHUPNewScoringVisitedCountScoreBucketsParam[] = |
443 "VisitedCountScoreBuckets"; | 487 "VisitedCountScoreBuckets"; |
| 488 const char OmniboxFieldTrial::kHUPNewScoringVisitedCountUseDecayFactorParam[] = |
| 489 "VisitedCountUseDecayFactor"; |
444 | 490 |
445 const char OmniboxFieldTrial::kHQPExperimentalScoringEnabledParam[] = | 491 const char OmniboxFieldTrial::kHQPExperimentalScoringEnabledParam[] = |
446 "HQPExperimentalScoringEnabled"; | 492 "HQPExperimentalScoringEnabled"; |
447 const char OmniboxFieldTrial::kHQPExperimentalScoringBucketsParam[] = | 493 const char OmniboxFieldTrial::kHQPExperimentalScoringBucketsParam[] = |
448 "HQPExperimentalScoringBuckets"; | 494 "HQPExperimentalScoringBuckets"; |
449 const char | 495 const char |
450 OmniboxFieldTrial::kHQPExperimentalScoringTopicalityThresholdParam[] = | 496 OmniboxFieldTrial::kHQPExperimentalScoringTopicalityThresholdParam[] = |
451 "HQPExperimentalScoringTopicalityThreshold"; | 497 "HQPExperimentalScoringTopicalityThreshold"; |
452 | 498 |
453 // static | 499 // static |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 if (it != params.end()) | 554 if (it != params.end()) |
509 return it->second; | 555 return it->second; |
510 // Fall back to the global instant extended context. | 556 // Fall back to the global instant extended context. |
511 it = params.find(rule + ":" + page_classification_str + ":*"); | 557 it = params.find(rule + ":" + page_classification_str + ":*"); |
512 if (it != params.end()) | 558 if (it != params.end()) |
513 return it->second; | 559 return it->second; |
514 // Look up rule in the global context. | 560 // Look up rule in the global context. |
515 it = params.find(rule + ":*:*"); | 561 it = params.find(rule + ":*:*"); |
516 return (it != params.end()) ? it->second : std::string(); | 562 return (it != params.end()) ? it->second : std::string(); |
517 } | 563 } |
OLD | NEW |