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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 } | 101 } |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 } // namespace | 105 } // namespace |
106 | 106 |
107 // static | 107 // static |
108 const size_t ScoredHistoryMatch::kMaxVisitsToScore = 10; | 108 const size_t ScoredHistoryMatch::kMaxVisitsToScore = 10; |
109 bool ScoredHistoryMatch::also_do_hup_like_scoring_ = false; | 109 bool ScoredHistoryMatch::also_do_hup_like_scoring_ = false; |
110 int ScoredHistoryMatch::bookmark_value_ = 1; | 110 int ScoredHistoryMatch::bookmark_value_ = 1; |
111 bool ScoredHistoryMatch::fix_typed_visit_bug_ = false; | |
112 bool ScoredHistoryMatch::fix_few_visits_bug_ = false; | 111 bool ScoredHistoryMatch::fix_few_visits_bug_ = false; |
113 bool ScoredHistoryMatch::allow_tld_matches_ = false; | 112 bool ScoredHistoryMatch::allow_tld_matches_ = false; |
114 bool ScoredHistoryMatch::allow_scheme_matches_ = false; | 113 bool ScoredHistoryMatch::allow_scheme_matches_ = false; |
115 size_t ScoredHistoryMatch::num_title_words_to_allow_ = 10u; | 114 size_t ScoredHistoryMatch::num_title_words_to_allow_ = 10u; |
116 bool ScoredHistoryMatch::hqp_experimental_scoring_enabled_ = false; | 115 bool ScoredHistoryMatch::hqp_experimental_scoring_enabled_ = false; |
117 float ScoredHistoryMatch::topicality_threshold_ = 0.8f; | 116 float ScoredHistoryMatch::topicality_threshold_ = 0.8f; |
118 // Default HQP relevance buckets. See GetFinalRelevancyScore() | 117 // Default HQP relevance buckets. See GetFinalRelevancyScore() |
119 // for more details on these numbers. | 118 // for more details on these numbers. |
120 char ScoredHistoryMatch::hqp_relevance_buckets_str_[] = | 119 char ScoredHistoryMatch::hqp_relevance_buckets_str_[] = |
121 "0.0:400,1.5:600,5.0:900,10.5:1203,15.0:1300,20.0:1399"; | 120 "0.0:400,1.5:600,5.0:900,10.5:1203,15.0:1300,20.0:1399"; |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 // static | 421 // static |
423 void ScoredHistoryMatch::Init() { | 422 void ScoredHistoryMatch::Init() { |
424 static bool initialized = false; | 423 static bool initialized = false; |
425 | 424 |
426 if (initialized) | 425 if (initialized) |
427 return; | 426 return; |
428 | 427 |
429 initialized = true; | 428 initialized = true; |
430 also_do_hup_like_scoring_ = OmniboxFieldTrial::HQPAlsoDoHUPLikeScoring(); | 429 also_do_hup_like_scoring_ = OmniboxFieldTrial::HQPAlsoDoHUPLikeScoring(); |
431 bookmark_value_ = OmniboxFieldTrial::HQPBookmarkValue(); | 430 bookmark_value_ = OmniboxFieldTrial::HQPBookmarkValue(); |
432 fix_typed_visit_bug_ = OmniboxFieldTrial::HQPFixTypedVisitBug(); | |
433 fix_few_visits_bug_ = OmniboxFieldTrial::HQPFixFewVisitsBug(); | 431 fix_few_visits_bug_ = OmniboxFieldTrial::HQPFixFewVisitsBug(); |
434 allow_tld_matches_ = OmniboxFieldTrial::HQPAllowMatchInTLDValue(); | 432 allow_tld_matches_ = OmniboxFieldTrial::HQPAllowMatchInTLDValue(); |
435 allow_scheme_matches_ = OmniboxFieldTrial::HQPAllowMatchInSchemeValue(); | 433 allow_scheme_matches_ = OmniboxFieldTrial::HQPAllowMatchInSchemeValue(); |
436 num_title_words_to_allow_ = OmniboxFieldTrial::HQPNumTitleWordsToAllow(); | 434 num_title_words_to_allow_ = OmniboxFieldTrial::HQPNumTitleWordsToAllow(); |
437 | 435 |
438 InitRawTermScoreToTopicalityScoreArray(); | 436 InitRawTermScoreToTopicalityScoreArray(); |
439 InitDaysAgoToRecencyScoreArray(); | 437 InitDaysAgoToRecencyScoreArray(); |
440 InitHQPExperimentalParams(); | 438 InitHQPExperimentalParams(); |
441 } | 439 } |
442 | 440 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 // Compute the weighted average |value_of_transition| over the last at | 597 // Compute the weighted average |value_of_transition| over the last at |
600 // most kMaxVisitsToScore visits, where each visit is weighted using | 598 // most kMaxVisitsToScore visits, where each visit is weighted using |
601 // GetRecencyScore() based on how many days ago it happened. Use | 599 // GetRecencyScore() based on how many days ago it happened. Use |
602 // kMaxVisitsToScore as the denominator for the average regardless of | 600 // kMaxVisitsToScore as the denominator for the average regardless of |
603 // how many visits there were in order to penalize a match that has | 601 // how many visits there were in order to penalize a match that has |
604 // fewer visits than kMaxVisitsToScore. | 602 // fewer visits than kMaxVisitsToScore. |
605 float summed_visit_points = 0; | 603 float summed_visit_points = 0; |
606 const size_t max_visit_to_score = | 604 const size_t max_visit_to_score = |
607 std::min(visits.size(), ScoredHistoryMatch::kMaxVisitsToScore); | 605 std::min(visits.size(), ScoredHistoryMatch::kMaxVisitsToScore); |
608 for (size_t i = 0; i < max_visit_to_score; ++i) { | 606 for (size_t i = 0; i < max_visit_to_score; ++i) { |
609 const bool is_page_transition_typed = | 607 const bool is_page_transition_typed = ui::PageTransitionCoreTypeIs( |
610 fix_typed_visit_bug_ ? ui::PageTransitionCoreTypeIs( | 608 visits[i].second, ui::PAGE_TRANSITION_TYPED); |
611 visits[i].second, ui::PAGE_TRANSITION_TYPED) | |
612 : ui::PageTransitionTypeIncludingQualifiersIs( | |
613 visits[i].second, ui::PAGE_TRANSITION_TYPED); | |
614 int value_of_transition = is_page_transition_typed ? 20 : 1; | 609 int value_of_transition = is_page_transition_typed ? 20 : 1; |
615 if (bookmarked) | 610 if (bookmarked) |
616 value_of_transition = std::max(value_of_transition, bookmark_value_); | 611 value_of_transition = std::max(value_of_transition, bookmark_value_); |
617 const float bucket_weight = | 612 const float bucket_weight = |
618 GetRecencyScore((now - visits[i].first).InDays()); | 613 GetRecencyScore((now - visits[i].first).InDays()); |
619 summed_visit_points += (value_of_transition * bucket_weight); | 614 summed_visit_points += (value_of_transition * bucket_weight); |
620 } | 615 } |
621 if (fix_few_visits_bug_) | 616 if (fix_few_visits_bug_) |
622 return summed_visit_points / ScoredHistoryMatch::kMaxVisitsToScore; | 617 return summed_visit_points / ScoredHistoryMatch::kMaxVisitsToScore; |
623 return visits.size() * summed_visit_points / | 618 return visits.size() * summed_visit_points / |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 base::StringToDouble(it->first, &bucket.first); | 724 base::StringToDouble(it->first, &bucket.first); |
730 DCHECK(is_valid_intermediate_score); | 725 DCHECK(is_valid_intermediate_score); |
731 bool is_valid_hqp_score = base::StringToInt(it->second, &bucket.second); | 726 bool is_valid_hqp_score = base::StringToInt(it->second, &bucket.second); |
732 DCHECK(is_valid_hqp_score); | 727 DCHECK(is_valid_hqp_score); |
733 hqp_buckets->push_back(bucket); | 728 hqp_buckets->push_back(bucket); |
734 } | 729 } |
735 return true; | 730 return true; |
736 } | 731 } |
737 return false; | 732 return false; |
738 } | 733 } |
OLD | NEW |