| 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 "chrome/browser/autocomplete/scored_history_match.h" | 5 #include "chrome/browser/autocomplete/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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 days_ago_to_recency_score[days_ago - 1]); | 116 days_ago_to_recency_score[days_ago - 1]); |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 | 120 |
| 121 } // namespace | 121 } // namespace |
| 122 | 122 |
| 123 // static | 123 // static |
| 124 const size_t ScoredHistoryMatch::kMaxVisitsToScore = 10; | 124 const size_t ScoredHistoryMatch::kMaxVisitsToScore = 10; |
| 125 int ScoredHistoryMatch::bookmark_value_ = 1; | 125 int ScoredHistoryMatch::bookmark_value_ = 1; |
| 126 bool ScoredHistoryMatch::fix_frequency_bugs_ = false; |
| 126 bool ScoredHistoryMatch::allow_tld_matches_ = false; | 127 bool ScoredHistoryMatch::allow_tld_matches_ = false; |
| 127 bool ScoredHistoryMatch::allow_scheme_matches_ = false; | 128 bool ScoredHistoryMatch::allow_scheme_matches_ = false; |
| 128 bool ScoredHistoryMatch::hqp_experimental_scoring_enabled_ = false; | 129 bool ScoredHistoryMatch::hqp_experimental_scoring_enabled_ = false; |
| 129 float ScoredHistoryMatch::topicality_threshold_ = -1; | 130 float ScoredHistoryMatch::topicality_threshold_ = -1; |
| 130 std::vector<ScoredHistoryMatch::ScoreMaxRelevance>* | 131 std::vector<ScoredHistoryMatch::ScoreMaxRelevance>* |
| 131 ScoredHistoryMatch::hqp_relevance_buckets_ = nullptr; | 132 ScoredHistoryMatch::hqp_relevance_buckets_ = nullptr; |
| 132 | 133 |
| 133 ScoredHistoryMatch::ScoredHistoryMatch() : raw_score(0), can_inline(false) { | 134 ScoredHistoryMatch::ScoredHistoryMatch() : raw_score(0), can_inline(false) { |
| 134 } | 135 } |
| 135 | 136 |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 // to non-inlineable scores (scores less than 1200). Without | 398 // to non-inlineable scores (scores less than 1200). Without |
| 398 // HUP-like-scoring, these results would actually come from the HUP | 399 // HUP-like-scoring, these results would actually come from the HUP |
| 399 // and not be demoted, thus outscoring the demoted HQP results. | 400 // and not be demoted, thus outscoring the demoted HQP results. |
| 400 // When the HQP provides these, we need to clamp the non-inlineable | 401 // When the HQP provides these, we need to clamp the non-inlineable |
| 401 // results to preserve this behavior. | 402 // results to preserve this behavior. |
| 402 if (kAlsoDoHupLikeScoring) { | 403 if (kAlsoDoHupLikeScoring) { |
| 403 max_assigned_score_for_non_inlineable_matches = | 404 max_assigned_score_for_non_inlineable_matches = |
| 404 HistoryURLProvider::kScoreForBestInlineableResult - 1; | 405 HistoryURLProvider::kScoreForBestInlineableResult - 1; |
| 405 } | 406 } |
| 406 bookmark_value_ = OmniboxFieldTrial::HQPBookmarkValue(); | 407 bookmark_value_ = OmniboxFieldTrial::HQPBookmarkValue(); |
| 408 fix_frequency_bugs_ = OmniboxFieldTrial::HQPFixFrequencyScoringBugs(); |
| 407 allow_tld_matches_ = OmniboxFieldTrial::HQPAllowMatchInTLDValue(); | 409 allow_tld_matches_ = OmniboxFieldTrial::HQPAllowMatchInTLDValue(); |
| 408 allow_scheme_matches_ = OmniboxFieldTrial::HQPAllowMatchInSchemeValue(); | 410 allow_scheme_matches_ = OmniboxFieldTrial::HQPAllowMatchInSchemeValue(); |
| 409 | 411 |
| 410 InitRawTermScoreToTopicalityScoreArray(); | 412 InitRawTermScoreToTopicalityScoreArray(); |
| 411 InitDaysAgoToRecencyScoreArray(); | 413 InitDaysAgoToRecencyScoreArray(); |
| 412 InitHQPExperimentalParams(); | 414 InitHQPExperimentalParams(); |
| 413 } | 415 } |
| 414 | 416 |
| 415 float ScoredHistoryMatch::GetTopicalityScore( | 417 float ScoredHistoryMatch::GetTopicalityScore( |
| 416 const int num_terms, | 418 const int num_terms, |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 // Compute the weighted average |value_of_transition| over the last at | 578 // Compute the weighted average |value_of_transition| over the last at |
| 577 // most kMaxVisitsToScore visits, where each visit is weighted using | 579 // most kMaxVisitsToScore visits, where each visit is weighted using |
| 578 // GetRecencyScore() based on how many days ago it happened. Use | 580 // GetRecencyScore() based on how many days ago it happened. Use |
| 579 // kMaxVisitsToScore as the denominator for the average regardless of | 581 // kMaxVisitsToScore as the denominator for the average regardless of |
| 580 // how many visits there were in order to penalize a match that has | 582 // how many visits there were in order to penalize a match that has |
| 581 // fewer visits than kMaxVisitsToScore. | 583 // fewer visits than kMaxVisitsToScore. |
| 582 float summed_visit_points = 0; | 584 float summed_visit_points = 0; |
| 583 const size_t max_visit_to_score = | 585 const size_t max_visit_to_score = |
| 584 std::min(visits.size(), ScoredHistoryMatch::kMaxVisitsToScore); | 586 std::min(visits.size(), ScoredHistoryMatch::kMaxVisitsToScore); |
| 585 for (size_t i = 0; i < max_visit_to_score; ++i) { | 587 for (size_t i = 0; i < max_visit_to_score; ++i) { |
| 586 int value_of_transition = | 588 const bool typed_visit = fix_frequency_bugs_ ? |
| 587 (visits[i].second == ui::PAGE_TRANSITION_TYPED) ? 20 : 1; | 589 (visits[i].second & ui::PAGE_TRANSITION_TYPED) : |
| 590 (visits[i].second == ui::PAGE_TRANSITION_TYPED); |
| 591 int value_of_transition = typed_visit ? 20 : 1; |
| 588 if (bookmarked) | 592 if (bookmarked) |
| 589 value_of_transition = std::max(value_of_transition, bookmark_value_); | 593 value_of_transition = std::max(value_of_transition, bookmark_value_); |
| 590 const float bucket_weight = | 594 const float bucket_weight = |
| 591 GetRecencyScore((now - visits[i].first).InDays()); | 595 GetRecencyScore((now - visits[i].first).InDays()); |
| 592 summed_visit_points += (value_of_transition * bucket_weight); | 596 summed_visit_points += (value_of_transition * bucket_weight); |
| 593 } | 597 } |
| 598 if (fix_frequency_bugs_) |
| 599 return summed_visit_points / ScoredHistoryMatch::kMaxVisitsToScore; |
| 594 return visits.size() * summed_visit_points / | 600 return visits.size() * summed_visit_points / |
| 595 ScoredHistoryMatch::kMaxVisitsToScore; | 601 ScoredHistoryMatch::kMaxVisitsToScore; |
| 596 } | 602 } |
| 597 | 603 |
| 598 // static | 604 // static |
| 599 float ScoredHistoryMatch::GetFinalRelevancyScore( | 605 float ScoredHistoryMatch::GetFinalRelevancyScore( |
| 600 float topicality_score, | 606 float topicality_score, |
| 601 float frequency_score, | 607 float frequency_score, |
| 602 const std::vector<ScoreMaxRelevance>& hqp_relevance_buckets) { | 608 const std::vector<ScoreMaxRelevance>& hqp_relevance_buckets) { |
| 603 DCHECK(hqp_relevance_buckets.size() > 0); | 609 DCHECK(hqp_relevance_buckets.size() > 0); |
| 604 DCHECK_EQ(hqp_relevance_buckets[0].first, 0.0); | 610 DCHECK_EQ(hqp_relevance_buckets[0].first, 0.0); |
| 605 | 611 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 base::StringToDouble(it->first, &bucket.first); | 705 base::StringToDouble(it->first, &bucket.first); |
| 700 DCHECK(is_valid_intermediate_score); | 706 DCHECK(is_valid_intermediate_score); |
| 701 bool is_valid_hqp_score = base::StringToInt(it->second, &bucket.second); | 707 bool is_valid_hqp_score = base::StringToInt(it->second, &bucket.second); |
| 702 DCHECK(is_valid_hqp_score); | 708 DCHECK(is_valid_hqp_score); |
| 703 hqp_buckets->push_back(bucket); | 709 hqp_buckets->push_back(bucket); |
| 704 } | 710 } |
| 705 return true; | 711 return true; |
| 706 } | 712 } |
| 707 return false; | 713 return false; |
| 708 } | 714 } |
| OLD | NEW |