| Index: components/history/core/browser/scored_history_match_client.cc
|
| diff --git a/components/history/core/browser/scored_history_match_client.cc b/components/history/core/browser/scored_history_match_client.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..cfcf1ad808bd59bc04acb587ad9aa348a0690915
|
| --- /dev/null
|
| +++ b/components/history/core/browser/scored_history_match_client.cc
|
| @@ -0,0 +1,95 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "components/history/core/browser/scored_history_match_client.h"
|
| +
|
| +#include "components/history/core/browser/scored_history_match.h"
|
| +
|
| +namespace history {
|
| +namespace {
|
| +
|
| +// The number of days of recency scores to precompute.
|
| +const int kDaysToPrecomputeRecencyScoresFor = 366;
|
| +
|
| +// The number of raw term score buckets use; raw term scores
|
| +// greater this are capped at the score of the largest bucket.
|
| +const int kMaxRawTermScore = 30;
|
| +
|
| +void FillInRawScoreToTopicalityScoreArray(
|
| + std::vector<float>* raw_score_to_topicality_score) {
|
| + raw_score_to_topicality_score->resize(kMaxRawTermScore);
|
| + for (int term_score = 0; term_score < kMaxRawTermScore; ++term_score) {
|
| + float topicality_score;
|
| + if (term_score < 10) {
|
| + // If the term scores less than 10 points (no full-credit hit, or
|
| + // no combination of hits that score that well), then the topicality
|
| + // score is linear in the term score.
|
| + topicality_score = 0.1 * term_score;
|
| + } else {
|
| + // For term scores of at least ten points, pass them through a log
|
| + // function so a score of 10 points gets a 1.0 (to meet up exactly
|
| + // with the linear component) and increases logarithmically until
|
| + // maxing out at 30 points, with computes to a score around 2.1.
|
| + topicality_score = (1.0 + 2.25 * log10(0.1 * term_score));
|
| + }
|
| + (*raw_score_to_topicality_score)[term_score] = topicality_score;
|
| + }
|
| +}
|
| +
|
| +void FillInDaysAgoToRecencyScoreArray(
|
| + std::vector<float>* days_ago_to_recency_score) {
|
| + days_ago_to_recency_score->resize(kDaysToPrecomputeRecencyScoresFor);
|
| + for (int days_ago = 0; days_ago < kDaysToPrecomputeRecencyScoresFor;
|
| + days_ago++) {
|
| + int unnormalized_recency_score;
|
| + if (days_ago <= 4) {
|
| + unnormalized_recency_score = 100;
|
| + } else if (days_ago <= 14) {
|
| + // Linearly extrapolate between 4 and 14 days so 14 days has a score
|
| + // of 70.
|
| + unnormalized_recency_score = 70 + (14 - days_ago) * (100 - 70) / (14 - 4);
|
| + } else if (days_ago <= 31) {
|
| + // Linearly extrapolate between 14 and 31 days so 31 days has a score
|
| + // of 50.
|
| + unnormalized_recency_score = 50 + (31 - days_ago) * (70 - 50) / (31 - 14);
|
| + } else if (days_ago <= 90) {
|
| + // Linearly extrapolate between 30 and 90 days so 90 days has a score
|
| + // of 30.
|
| + unnormalized_recency_score = 30 + (90 - days_ago) * (50 - 30) / (90 - 30);
|
| + } else {
|
| + // Linearly extrapolate between 90 and 365 days so 365 days has a score
|
| + // of 10.
|
| + unnormalized_recency_score =
|
| + 10 + (365 - days_ago) * (20 - 10) / (365 - 90);
|
| + }
|
| + (*days_ago_to_recency_score)[days_ago] = unnormalized_recency_score / 100.0;
|
| + if (days_ago > 0) {
|
| + DCHECK_LE((*days_ago_to_recency_score)[days_ago],
|
| + (*days_ago_to_recency_score)[days_ago - 1]);
|
| + }
|
| + }
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +ScoredHistoryMatchClient::ScoredHistoryMatchClient() {
|
| + FillInRawScoreToTopicalityScoreArray(&raw_score_to_topicality_score_);
|
| + FillInDaysAgoToRecencyScoreArray(&days_ago_to_recency_score_);
|
| +}
|
| +
|
| +ScoredHistoryMatchClient::~ScoredHistoryMatchClient() {
|
| +}
|
| +
|
| +float ScoredHistoryMatchClient::GetTopicalityScoreFromRawScore(
|
| + int raw_score) const {
|
| + return raw_score_to_topicality_score_[std::max(
|
| + std::min(raw_score, kMaxRawTermScore - 1), 0)];
|
| +}
|
| +
|
| +float ScoredHistoryMatchClient::GetRecencyScore(int last_visit_days_ago) const {
|
| + return days_ago_to_recency_score_[std::max(
|
| + std::min(last_visit_days_ago, kDaysToPrecomputeRecencyScoresFor - 1), 0)];
|
| +}
|
| +
|
| +} // namespace history
|
|
|