Commit a4f1008a authored by Moe Ahmadi's avatar Moe Ahmadi Committed by Commit Bot

Fieldtrial params to fine-tune frecency score of local repeatable queries

Adds Fieldtrial params to be used for fine-tuning the frecency score of
local repeatable queries. These params allow fine tuning of the age
threshold, recency decay, and frequency exponent of the score.

The default values match those in http://shortn/_VLAOJTxx6J

Bug: 1110077
Change-Id: I6d2cd1452d02c1133c7e2f6232b25168d81408da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2422427
Commit-Queue: Moe Ahmadi <mahmadi@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815437}
parent a97eb3fc
......@@ -5,6 +5,8 @@
#include "chrome/browser/search/ntp_features.h"
#include "base/feature_list.h"
#include "base/strings/string_number_conversions.h"
#include "base/time/time.h"
#include "build/build_config.h"
namespace ntp_features {
......@@ -68,4 +70,58 @@ const base::Feature kModules{"NtpModules", base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kNtpShoppingTasksModule{"NtpShoppingTasksModule",
base::FEATURE_DISABLED_BY_DEFAULT};
const char kNtpRepeatableQueriesAgeThresholdDaysParam[] =
"NtpRepeatableQueriesAgeThresholdDays";
const char kNtpRepeatableQueriesRecencyHalfLifeSecondsParam[] =
"NtpRepeatableQueriesRecencyHalfLifeSeconds";
const char kNtpRepeatableQueriesFrequencyExponentParam[] =
"NtpRepeatableQueriesFrequencyExponent";
base::Time GetLocalHistoryRepeatableQueriesAgeThreshold() {
const base::TimeDelta kLocalHistoryRepeatableQueriesAgeThreshold =
base::TimeDelta::FromDays(180); // Six months.
std::string param_value = base::GetFieldTrialParamValueByFeature(
kNtpRepeatableQueries, kNtpRepeatableQueriesAgeThresholdDaysParam);
// If the field trial param is not found or cannot be parsed to an unsigned
// integer, return the default value.
unsigned int param_value_as_int = 0;
if (!base::StringToUint(param_value, &param_value_as_int)) {
return base::Time::Now() - kLocalHistoryRepeatableQueriesAgeThreshold;
}
return (base::Time::Now() - base::TimeDelta::FromDays(param_value_as_int));
}
int GetLocalHistoryRepeatableQueriesRecencyHalfLifeSeconds() {
const base::TimeDelta kLocalHistoryRepeatableQueriesRecencyHalfLife =
base::TimeDelta::FromDays(7); // One week.
std::string param_value = base::GetFieldTrialParamValueByFeature(
kNtpRepeatableQueries, kNtpRepeatableQueriesRecencyHalfLifeSecondsParam);
// If the field trial param is not found or cannot be parsed to an unsigned
// integer, return the default value.
unsigned int param_value_as_int = 0;
if (!base::StringToUint(param_value, &param_value_as_int)) {
return kLocalHistoryRepeatableQueriesRecencyHalfLife.InSeconds();
}
return param_value_as_int;
}
double GetLocalHistoryRepeatableQueriesFrequencyExponent() {
const double kLocalHistoryRepeatableQueriesFrequencyExponent = 2.0;
std::string param_value = base::GetFieldTrialParamValueByFeature(
kNtpRepeatableQueries, kNtpRepeatableQueriesFrequencyExponentParam);
// If the field trial param is not found or cannot be parsed to an unsigned
// integer, return the default value.
double param_value_as_double = 0;
if (!base::StringToDouble(param_value, &param_value_as_double)) {
return kLocalHistoryRepeatableQueriesFrequencyExponent;
}
return param_value_as_double;
}
} // namespace ntp_features
......@@ -7,6 +7,10 @@
#include "base/feature_list.h"
namespace base {
class Time;
} // namespace base
namespace ntp_features {
// The features should be documented alongside the definition of their values in
......@@ -27,6 +31,28 @@ extern const base::Feature kNtpShoppingTasksModule;
extern const base::Feature kSearchSuggestChips;
extern const base::Feature kDisableSearchSuggestChips;
// Parameter name determining the age threshold in days for local history
// repeatable queries.
// The value of this parameter should be parsable as an unsigned integer.
extern const char kNtpRepeatableQueriesAgeThresholdDaysParam[];
// Parameter name determining the number of seconds until the recency component
// of the frecency score for local history repeatable queries decays to half.
// The value of this parameter should be parsable as an unsigned integer.
extern const char kNtpRepeatableQueriesRecencyHalfLifeSecondsParam[];
// Parameter name determining the factor by which the frequency component of the
// frecency score for local history repeatable queries is exponentiated.
// The value of this parameter should be parsable as a double.
extern const char kNtpRepeatableQueriesFrequencyExponentParam[];
// Returns the age threshold for local history repeatable queries.
base::Time GetLocalHistoryRepeatableQueriesAgeThreshold();
// Returns the number of seconds until the recency component of the frecency
// score for local history repeatable queries decays to half.
int GetLocalHistoryRepeatableQueriesRecencyHalfLifeSeconds();
// Returns the factor by which the frequency component of the frecency score for
// local history repeatable queries is exponentiated.
double GetLocalHistoryRepeatableQueriesFrequencyExponent();
} // namespace ntp_features
#endif // CHROME_BROWSER_SEARCH_NTP_FEATURES_H_
// Copyright 2019 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 "chrome/browser/search/ntp_features.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace ntp_features {
TEST(NTPFeaturesTest, LocalHistoryRepeatableQueriesAgeThresholdDays) {
base::test::ScopedFeatureList scoped_feature_list_;
// The default value can be overridden.
scoped_feature_list_.InitWithFeaturesAndParameters(
{{kNtpRepeatableQueries,
{{kNtpRepeatableQueriesAgeThresholdDaysParam, "7"}}}},
{});
base::Time age_threshold = GetLocalHistoryRepeatableQueriesAgeThreshold();
EXPECT_EQ(7, base::TimeDelta(base::Time::Now() - age_threshold).InDays());
// If the age threshold is not parsable to an unsigned integer, the default
// value is used.
scoped_feature_list_.Reset();
scoped_feature_list_.InitWithFeaturesAndParameters(
{{kNtpRepeatableQueries,
{{kNtpRepeatableQueriesAgeThresholdDaysParam, "j"}}}},
{});
age_threshold = GetLocalHistoryRepeatableQueriesAgeThreshold();
EXPECT_EQ(180, base::TimeDelta(base::Time::Now() - age_threshold).InDays());
}
TEST(NTPFeaturesTest, LocalHistoryRepeatableQueriesRecencyDecayUnit) {
base::test::ScopedFeatureList scoped_feature_list_;
// The default value can be overridden.
scoped_feature_list_.InitWithFeaturesAndParameters(
{{kNtpRepeatableQueries,
{{kNtpRepeatableQueriesRecencyHalfLifeSecondsParam,
"86400" /* One day */}}}},
{});
int recency_decay = GetLocalHistoryRepeatableQueriesRecencyHalfLifeSeconds();
EXPECT_EQ(86400, recency_decay);
// If the recency decay unit is not parsable to an unsigned integer, the
// default value is used.
scoped_feature_list_.Reset();
scoped_feature_list_.InitWithFeaturesAndParameters(
{{kNtpRepeatableQueries,
{{kNtpRepeatableQueriesRecencyHalfLifeSecondsParam, "j"}}}},
{});
recency_decay = GetLocalHistoryRepeatableQueriesRecencyHalfLifeSeconds();
EXPECT_EQ(604800 /* One week */, recency_decay);
}
TEST(NTPFeaturesTest, LocalHistoryRepeatableQueriesFrequencyExponent) {
base::test::ScopedFeatureList scoped_feature_list_;
// The default value can be overridden.
scoped_feature_list_.InitWithFeaturesAndParameters(
{{kNtpRepeatableQueries,
{{kNtpRepeatableQueriesFrequencyExponentParam, "1.5"}}}},
{});
double frequency_exponent =
GetLocalHistoryRepeatableQueriesFrequencyExponent();
EXPECT_EQ(1.5, frequency_exponent);
// If the recency decay unit is not parsable to an unsigned integer, the
// default value is used.
scoped_feature_list_.Reset();
scoped_feature_list_.InitWithFeaturesAndParameters(
{{kNtpRepeatableQueries,
{{kNtpRepeatableQueriesFrequencyExponentParam, "j"}}}},
{});
frequency_exponent = GetLocalHistoryRepeatableQueriesFrequencyExponent();
EXPECT_EQ(2, frequency_exponent);
}
} // namespace ntp_features
......@@ -4629,6 +4629,7 @@ test("unit_tests") {
"../browser/feedback/system_logs/log_sources/crash_ids_source_unittest.cc",
# NTP is in native code on Android.
"../browser/search/ntp_features_unittest.cc",
"../browser/search/shopping_tasks/shopping_tasks_service_unittest.cc",
]
if (is_posix || is_fuchsia) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment