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. | |
Peter Kasting
2015/08/27 19:21:40
Nit: Wrong indent
Ashok vardhan
2015/08/27 19:51:38
Acknowledged.
| |
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. If url is | |
286 // 1-day older give score of 1390, 3 days older 0.93 and so on. Values are | |
Peter Kasting
2015/08/27 19:21:40
Nit: Omit the sentence about "If url is 1-day olde
Ashok vardhan
2015/08/27 19:51:38
Done.
| |
287 // chosen on idea of demoting the URLs with lower counts based on the | |
288 // number of days back they visited. | |
Peter Kasting
2015/08/27 19:21:40
Nit: This last sentence is kind of vague. It's so
Ashok vardhan
2015/08/27 19:51:38
Done.
| |
289 const std::string& typed_count_score_buckets_str = | |
290 "1.0:1413,0.97:1390,0.93:1360,0.85:1340,0.72:1320,0.50:1250,0.0:1203"; | |
291 InitializeBucketsFromString(typed_count_score_buckets_str, | |
292 type_score_buckets); | |
293 | |
294 ScoreBuckets* visit_score_buckets = &scoring_params->visited_count_buckets; | |
295 visit_score_buckets->set_half_life_days(30); | |
296 visit_score_buckets->set_use_decay_factor(false); | |
297 // High number of visits - 790, at least 1 in 30 days - 590 otherwise give 100 | |
298 // (which practically means to drop the urls on to floor). | |
Peter Kasting
2015/08/27 19:21:40
Similar comment applies here.
Ashok vardhan
2015/08/27 19:51:38
Done.
| |
299 const std::string& visit_count_score_buckets_str = "4.0:790,0.5:590,0.0:100"; | |
300 InitializeBucketsFromString(visit_count_score_buckets_str, | |
301 visit_score_buckets); | |
302 } | |
303 | |
265 void OmniboxFieldTrial::GetExperimentalHUPScoringParams( | 304 void OmniboxFieldTrial::GetExperimentalHUPScoringParams( |
266 HUPScoringParams* scoring_params) { | 305 HUPScoringParams* scoring_params) { |
267 scoring_params->experimental_scoring_enabled = false; | 306 scoring_params->experimental_scoring_enabled = false; |
268 | 307 |
269 VariationParams params; | 308 VariationParams params; |
270 if (!variations::GetVariationParams(kBundledExperimentFieldTrialName, | 309 if (!variations::GetVariationParams(kBundledExperimentFieldTrialName, |
271 ¶ms)) | 310 ¶ms)) |
272 return; | 311 return; |
273 | 312 |
274 VariationParams::const_iterator it = params.find(kHUPNewScoringEnabledParam); | 313 VariationParams::const_iterator it = params.find(kHUPNewScoringEnabledParam); |
275 if (it != params.end()) { | 314 if (it != params.end()) { |
276 int enabled = 0; | 315 int enabled = 0; |
277 if (base::StringToInt(it->second, &enabled)) | 316 if (base::StringToInt(it->second, &enabled)) |
278 scoring_params->experimental_scoring_enabled = (enabled != 0); | 317 scoring_params->experimental_scoring_enabled = (enabled != 0); |
279 } | 318 } |
280 | 319 |
281 InitializeScoreBuckets(params, kHUPNewScoringTypedCountRelevanceCapParam, | 320 InitializeScoreBuckets(params, kHUPNewScoringTypedCountRelevanceCapParam, |
282 kHUPNewScoringTypedCountHalfLifeTimeParam, | 321 kHUPNewScoringTypedCountHalfLifeTimeParam, |
283 kHUPNewScoringTypedCountScoreBucketsParam, | 322 kHUPNewScoringTypedCountScoreBucketsParam, |
323 kHUPNewScoringTypedCountUseDecayFactorParam, | |
284 &scoring_params->typed_count_buckets); | 324 &scoring_params->typed_count_buckets); |
285 InitializeScoreBuckets(params, kHUPNewScoringVisitedCountRelevanceCapParam, | 325 InitializeScoreBuckets(params, kHUPNewScoringVisitedCountRelevanceCapParam, |
286 kHUPNewScoringVisitedCountHalfLifeTimeParam, | 326 kHUPNewScoringVisitedCountHalfLifeTimeParam, |
287 kHUPNewScoringVisitedCountScoreBucketsParam, | 327 kHUPNewScoringVisitedCountScoreBucketsParam, |
328 kHUPNewScoringVisitedCountUseDecayFactorParam, | |
288 &scoring_params->visited_count_buckets); | 329 &scoring_params->visited_count_buckets); |
289 } | 330 } |
290 | 331 |
291 int OmniboxFieldTrial::HQPBookmarkValue() { | 332 int OmniboxFieldTrial::HQPBookmarkValue() { |
292 std::string bookmark_value_str = | 333 std::string bookmark_value_str = |
293 variations::GetVariationParamValue(kBundledExperimentFieldTrialName, | 334 variations::GetVariationParamValue(kBundledExperimentFieldTrialName, |
294 kHQPBookmarkValueRule); | 335 kHQPBookmarkValueRule); |
295 if (bookmark_value_str.empty()) | 336 if (bookmark_value_str.empty()) |
296 return 10; | 337 return 10; |
297 // This is a best-effort conversion; we trust the hand-crafted parameters | 338 // 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"; | 469 "PreventUWYTDefaultForNonURLInputs"; |
429 | 470 |
430 const char OmniboxFieldTrial::kHUPNewScoringEnabledParam[] = | 471 const char OmniboxFieldTrial::kHUPNewScoringEnabledParam[] = |
431 "HUPExperimentalScoringEnabled"; | 472 "HUPExperimentalScoringEnabled"; |
432 const char OmniboxFieldTrial::kHUPNewScoringTypedCountRelevanceCapParam[] = | 473 const char OmniboxFieldTrial::kHUPNewScoringTypedCountRelevanceCapParam[] = |
433 "TypedCountRelevanceCap"; | 474 "TypedCountRelevanceCap"; |
434 const char OmniboxFieldTrial::kHUPNewScoringTypedCountHalfLifeTimeParam[] = | 475 const char OmniboxFieldTrial::kHUPNewScoringTypedCountHalfLifeTimeParam[] = |
435 "TypedCountHalfLifeTime"; | 476 "TypedCountHalfLifeTime"; |
436 const char OmniboxFieldTrial::kHUPNewScoringTypedCountScoreBucketsParam[] = | 477 const char OmniboxFieldTrial::kHUPNewScoringTypedCountScoreBucketsParam[] = |
437 "TypedCountScoreBuckets"; | 478 "TypedCountScoreBuckets"; |
479 const char OmniboxFieldTrial::kHUPNewScoringTypedCountUseDecayFactorParam[] = | |
480 "TypedCountUseDecayFactor"; | |
438 const char OmniboxFieldTrial::kHUPNewScoringVisitedCountRelevanceCapParam[] = | 481 const char OmniboxFieldTrial::kHUPNewScoringVisitedCountRelevanceCapParam[] = |
439 "VisitedCountRelevanceCap"; | 482 "VisitedCountRelevanceCap"; |
440 const char OmniboxFieldTrial::kHUPNewScoringVisitedCountHalfLifeTimeParam[] = | 483 const char OmniboxFieldTrial::kHUPNewScoringVisitedCountHalfLifeTimeParam[] = |
441 "VisitedCountHalfLifeTime"; | 484 "VisitedCountHalfLifeTime"; |
442 const char OmniboxFieldTrial::kHUPNewScoringVisitedCountScoreBucketsParam[] = | 485 const char OmniboxFieldTrial::kHUPNewScoringVisitedCountScoreBucketsParam[] = |
443 "VisitedCountScoreBuckets"; | 486 "VisitedCountScoreBuckets"; |
487 const char OmniboxFieldTrial::kHUPNewScoringVisitedCountUseDecayFactorParam[] = | |
488 "VisitedCountUseDecayFactor"; | |
444 | 489 |
445 const char OmniboxFieldTrial::kHQPExperimentalScoringEnabledParam[] = | 490 const char OmniboxFieldTrial::kHQPExperimentalScoringEnabledParam[] = |
446 "HQPExperimentalScoringEnabled"; | 491 "HQPExperimentalScoringEnabled"; |
447 const char OmniboxFieldTrial::kHQPExperimentalScoringBucketsParam[] = | 492 const char OmniboxFieldTrial::kHQPExperimentalScoringBucketsParam[] = |
448 "HQPExperimentalScoringBuckets"; | 493 "HQPExperimentalScoringBuckets"; |
449 const char | 494 const char |
450 OmniboxFieldTrial::kHQPExperimentalScoringTopicalityThresholdParam[] = | 495 OmniboxFieldTrial::kHQPExperimentalScoringTopicalityThresholdParam[] = |
451 "HQPExperimentalScoringTopicalityThreshold"; | 496 "HQPExperimentalScoringTopicalityThreshold"; |
452 | 497 |
453 // static | 498 // static |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
508 if (it != params.end()) | 553 if (it != params.end()) |
509 return it->second; | 554 return it->second; |
510 // Fall back to the global instant extended context. | 555 // Fall back to the global instant extended context. |
511 it = params.find(rule + ":" + page_classification_str + ":*"); | 556 it = params.find(rule + ":" + page_classification_str + ":*"); |
512 if (it != params.end()) | 557 if (it != params.end()) |
513 return it->second; | 558 return it->second; |
514 // Look up rule in the global context. | 559 // Look up rule in the global context. |
515 it = params.find(rule + ":*:*"); | 560 it = params.find(rule + ":*:*"); |
516 return (it != params.end()) ? it->second : std::string(); | 561 return (it != params.end()) ? it->second : std::string(); |
517 } | 562 } |
OLD | NEW |