| OLD | NEW |
| 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/scored_history_match.h" | 5 #include "components/omnibox/browser/scored_history_match.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 105 |
| 106 // static | 106 // static |
| 107 const size_t ScoredHistoryMatch::kMaxVisitsToScore = 10; | 107 const size_t ScoredHistoryMatch::kMaxVisitsToScore = 10; |
| 108 bool ScoredHistoryMatch::also_do_hup_like_scoring_ = false; | 108 bool ScoredHistoryMatch::also_do_hup_like_scoring_ = false; |
| 109 int ScoredHistoryMatch::bookmark_value_ = 1; | 109 int ScoredHistoryMatch::bookmark_value_ = 1; |
| 110 bool ScoredHistoryMatch::fix_frequency_bugs_ = false; | 110 bool ScoredHistoryMatch::fix_frequency_bugs_ = false; |
| 111 bool ScoredHistoryMatch::allow_tld_matches_ = false; | 111 bool ScoredHistoryMatch::allow_tld_matches_ = false; |
| 112 bool ScoredHistoryMatch::allow_scheme_matches_ = false; | 112 bool ScoredHistoryMatch::allow_scheme_matches_ = false; |
| 113 size_t ScoredHistoryMatch::num_title_words_to_allow_ = 10u; | 113 size_t ScoredHistoryMatch::num_title_words_to_allow_ = 10u; |
| 114 bool ScoredHistoryMatch::hqp_experimental_scoring_enabled_ = false; | 114 bool ScoredHistoryMatch::hqp_experimental_scoring_enabled_ = false; |
| 115 float ScoredHistoryMatch::topicality_threshold_ = -1; | 115 float ScoredHistoryMatch::topicality_threshold_ = 0.8f; |
| 116 // Default HQP relevance buckets. See GetFinalRelevancyScore() |
| 117 // for more details on these numbers. |
| 118 char ScoredHistoryMatch::hqp_relevance_buckets_str_[] = |
| 119 "0.0:400,1.5:600,5.0:900,10.5:1203,15.0:1300,20.0:1399"; |
| 116 std::vector<ScoredHistoryMatch::ScoreMaxRelevance>* | 120 std::vector<ScoredHistoryMatch::ScoreMaxRelevance>* |
| 117 ScoredHistoryMatch::hqp_relevance_buckets_ = nullptr; | 121 ScoredHistoryMatch::hqp_relevance_buckets_ = nullptr; |
| 118 | 122 |
| 119 ScoredHistoryMatch::ScoredHistoryMatch() | 123 ScoredHistoryMatch::ScoredHistoryMatch() |
| 120 : ScoredHistoryMatch(history::URLRow(), | 124 : ScoredHistoryMatch(history::URLRow(), |
| 121 VisitInfoVector(), | 125 VisitInfoVector(), |
| 122 std::string(), | 126 std::string(), |
| 123 base::string16(), | 127 base::string16(), |
| 124 String16Vector(), | 128 String16Vector(), |
| 125 WordStarts(), | 129 WordStarts(), |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 return 0; | 537 return 0; |
| 534 topicality_score += raw_term_score_to_topicality_score[std::min( | 538 topicality_score += raw_term_score_to_topicality_score[std::min( |
| 535 term_score, kMaxRawTermScore - 1)]; | 539 term_score, kMaxRawTermScore - 1)]; |
| 536 } | 540 } |
| 537 // TODO(mpearson): If there are multiple terms, consider taking the | 541 // TODO(mpearson): If there are multiple terms, consider taking the |
| 538 // geometric mean of per-term scores rather than the arithmetic mean. | 542 // geometric mean of per-term scores rather than the arithmetic mean. |
| 539 | 543 |
| 540 const float final_topicality_score = topicality_score / num_terms; | 544 const float final_topicality_score = topicality_score / num_terms; |
| 541 | 545 |
| 542 // Demote the URL if the topicality score is less than threshold. | 546 // Demote the URL if the topicality score is less than threshold. |
| 543 if (hqp_experimental_scoring_enabled_ && | 547 if (final_topicality_score < topicality_threshold_) { |
| 544 (final_topicality_score < topicality_threshold_)) { | |
| 545 return 0.0; | 548 return 0.0; |
| 546 } | 549 } |
| 547 | 550 |
| 548 return final_topicality_score; | 551 return final_topicality_score; |
| 549 } | 552 } |
| 550 | 553 |
| 551 float ScoredHistoryMatch::GetRecencyScore(int last_visit_days_ago) const { | 554 float ScoredHistoryMatch::GetRecencyScore(int last_visit_days_ago) const { |
| 552 // Lookup the score in days_ago_to_recency_score, treating | 555 // Lookup the score in days_ago_to_recency_score, treating |
| 553 // everything older than what we've precomputed as the oldest thing | 556 // everything older than what we've precomputed as the oldest thing |
| 554 // we've precomputed. The std::max is to protect against corruption | 557 // we've precomputed. The std::max is to protect against corruption |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 } | 641 } |
| 639 // It will reach this stage when the score is > highest bucket score. | 642 // It will reach this stage when the score is > highest bucket score. |
| 640 // Return the highest bucket score. | 643 // Return the highest bucket score. |
| 641 return hqp_relevance_buckets[i - 1].second; | 644 return hqp_relevance_buckets[i - 1].second; |
| 642 } | 645 } |
| 643 | 646 |
| 644 // static | 647 // static |
| 645 void ScoredHistoryMatch::InitHQPExperimentalParams() { | 648 void ScoredHistoryMatch::InitHQPExperimentalParams() { |
| 646 // These are default HQP relevance scoring buckets. | 649 // These are default HQP relevance scoring buckets. |
| 647 // See GetFinalRelevancyScore() for details. | 650 // See GetFinalRelevancyScore() for details. |
| 648 std::string hqp_relevance_buckets_str = "0.0:400,1.5:600,12.0:1300,20.0:1399"; | 651 std::string hqp_relevance_buckets_str = std::string( |
| 652 hqp_relevance_buckets_str_); |
| 649 | 653 |
| 650 // Fetch the experiment params if they are any. | 654 // Fetch the experiment params if they are any. |
| 651 hqp_experimental_scoring_enabled_ = | 655 hqp_experimental_scoring_enabled_ = |
| 652 OmniboxFieldTrial::HQPExperimentalScoringEnabled(); | 656 OmniboxFieldTrial::HQPExperimentalScoringEnabled(); |
| 653 | 657 |
| 654 if (hqp_experimental_scoring_enabled_) { | 658 if (hqp_experimental_scoring_enabled_) { |
| 655 // Add the topicality threshold from experiment params. | 659 // Add the topicality threshold from experiment params. |
| 656 float hqp_experimental_topicality_threhold = | 660 float hqp_experimental_topicality_threhold = |
| 657 OmniboxFieldTrial::HQPExperimentalTopicalityThreshold(); | 661 OmniboxFieldTrial::HQPExperimentalTopicalityThreshold(); |
| 658 topicality_threshold_ = hqp_experimental_topicality_threhold; | 662 topicality_threshold_ = hqp_experimental_topicality_threhold; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 base::StringToDouble(it->first, &bucket.first); | 694 base::StringToDouble(it->first, &bucket.first); |
| 691 DCHECK(is_valid_intermediate_score); | 695 DCHECK(is_valid_intermediate_score); |
| 692 bool is_valid_hqp_score = base::StringToInt(it->second, &bucket.second); | 696 bool is_valid_hqp_score = base::StringToInt(it->second, &bucket.second); |
| 693 DCHECK(is_valid_hqp_score); | 697 DCHECK(is_valid_hqp_score); |
| 694 hqp_buckets->push_back(bucket); | 698 hqp_buckets->push_back(bucket); |
| 695 } | 699 } |
| 696 return true; | 700 return true; |
| 697 } | 701 } |
| 698 return false; | 702 return false; |
| 699 } | 703 } |
| OLD | NEW |