Commit ff70c6a1 authored by tby's avatar tby Committed by Commit Bot

[Cros SR] Replace omnibox type in category ranker with specific subtypes.

This CL makes a slightly expanded version of the Dolphin category ranking model
that learns information on subtypes of omnibox results, eg. history results and
bookmark results. This is guarded behind a Finch parameter.

Bug: 931149
Change-Id: I01c9edef80aee9f7f386fe301ffcd44e0a18fc78
Reviewed-on: https://chromium-review.googlesource.com/c/1482095
Commit-Queue: Tony Yeoman <tby@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarJia Meng <jiameng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634840}
parent 906aab7c
......@@ -122,9 +122,9 @@ void Mixer::MixAndPublish(size_t num_max_results) {
for (auto& result : results) {
RankingItemType type = RankingItemTypeFromSearchResult(*result.result);
const auto& rank_it = ranks.find(std::to_string(static_cast<int>(type)));
// The ranker only contains entries trained with types
// |RankingItemType::kFile| and |RankingItemType::kOmnibox|. This means
// scores for apps and answer cards will be unchanged.
// The ranker only contains entries trained with types relating to files
// or the omnibox. This means scores for apps, app shortcuts, and answer
// cards will be unchanged.
if (rank_it != ranks.end())
// Ranker scores are guaranteed to be in [0,1]. But, enforce that the
// result of tweaking does not put the score above 3.0, as that may
......@@ -189,7 +189,12 @@ void Mixer::Train(const std::string& id, RankingItemType type) {
if (!ranker_)
return;
if (type == RankingItemType::kFile || type == RankingItemType::kOmnibox) {
if (type == RankingItemType::kFile ||
type == RankingItemType::kOmniboxGeneric ||
type == RankingItemType::kOmniboxBookmark ||
type == RankingItemType::kOmniboxDocument ||
type == RankingItemType::kOmniboxHistory ||
type == RankingItemType::kOmniboxSearch) {
ranker_->Record(std::to_string(static_cast<int>(type)));
}
}
......
......@@ -4,23 +4,75 @@
#include "chrome/browser/ui/app_list/search/search_result_ranker/ranking_item_util.h"
#include "ash/public/cpp/app_list/app_list_features.h"
#include "ash/public/cpp/app_list/app_list_types.h"
#include "base/macros.h"
#include "base/metrics/field_trial_params.h"
#include "chrome/browser/ui/app_list/chrome_app_list_item.h"
#include "chrome/browser/ui/app_list/search/chrome_search_result.h"
#include "components/omnibox/browser/autocomplete_match_type.h"
namespace app_list {
using SearchResultType = ash::SearchResultType;
// Given a |ChromeSearchResult| representing an omnibox result, convert it based
// on the subtype specified by |ChromeSearchResult::GetSubType|. Any
// unanticipated subtypes are converted into |RankingItemType::kOmniboxGeneric|.
RankingItemType ExpandOmniboxType(const ChromeSearchResult& result) {
if (result.result_type() != SearchResultType::kOmnibox) {
NOTREACHED();
return RankingItemType::kUnknown;
}
switch (static_cast<AutocompleteMatchType::Type>(result.GetSubType())) {
case AutocompleteMatchType::Type::HISTORY_URL:
case AutocompleteMatchType::Type::HISTORY_TITLE:
case AutocompleteMatchType::Type::HISTORY_BODY:
case AutocompleteMatchType::Type::HISTORY_KEYWORD:
return RankingItemType::kOmniboxHistory;
case AutocompleteMatchType::Type::NAVSUGGEST:
case AutocompleteMatchType::Type::NAVSUGGEST_PERSONALIZED:
return RankingItemType::kOmniboxNavSuggest;
case AutocompleteMatchType::Type::SEARCH_HISTORY:
case AutocompleteMatchType::Type::SEARCH_SUGGEST:
case AutocompleteMatchType::Type::SEARCH_SUGGEST_ENTITY:
case AutocompleteMatchType::Type::SEARCH_SUGGEST_TAIL:
case AutocompleteMatchType::Type::SEARCH_SUGGEST_PERSONALIZED:
case AutocompleteMatchType::Type::SEARCH_SUGGEST_PROFILE:
case AutocompleteMatchType::Type::SEARCH_OTHER_ENGINE:
return RankingItemType::kOmniboxSearch;
case AutocompleteMatchType::Type::BOOKMARK_TITLE:
return RankingItemType::kOmniboxBookmark;
case AutocompleteMatchType::Type::DOCUMENT_SUGGESTION:
return RankingItemType::kOmniboxDocument;
case AutocompleteMatchType::Type::EXTENSION_APP_DEPRECATED:
case AutocompleteMatchType::Type::CONTACT_DEPRECATED:
case AutocompleteMatchType::Type::PHYSICAL_WEB_DEPRECATED:
case AutocompleteMatchType::Type::PHYSICAL_WEB_OVERFLOW_DEPRECATED:
case AutocompleteMatchType::Type::TAB_SEARCH_DEPRECATED:
return RankingItemType::kOmniboxDeprecated;
default:
return RankingItemType::kOmniboxGeneric;
}
}
RankingItemType RankingItemTypeFromSearchResult(
const ChromeSearchResult& result) {
// We don't want or expect the expand_omnibox_types parameter to change during
// the execution of chrome, so make it static.
static bool expand_omnibox_types = base::GetFieldTrialParamByFeatureAsBool(
app_list_features::kEnableAdaptiveResultRanker, "expand_omnibox_types",
false);
switch (result.result_type()) {
case SearchResultType::kInstalledApp:
case SearchResultType::kInternalApp:
return RankingItemType::kApp;
case SearchResultType::kOmnibox:
return RankingItemType::kOmnibox;
if (expand_omnibox_types)
return ExpandOmniboxType(result);
return RankingItemType::kOmniboxGeneric;
case SearchResultType::kLauncher:
return RankingItemType::kFile;
case SearchResultType::kUnknown:
......
......@@ -17,8 +17,14 @@ enum class RankingItemType {
kIgnored,
kFile,
kApp,
kOmnibox,
kArcAppShortcut
kOmniboxGeneric,
kArcAppShortcut,
kOmniboxBookmark,
kOmniboxDeprecated,
kOmniboxDocument,
kOmniboxHistory,
kOmniboxNavSuggest,
kOmniboxSearch
};
// Convert a |ChromeSearchResult| into its |RankingItemType|.
......
// Copyright 2018 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/ui/app_list/search/search_result_ranker/ranking_item_util.h"
#include <map>
#include <memory>
#include <string>
#include "ash/public/cpp/app_list/app_list_features.h"
#include "base/metrics/field_trial_params.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/scoped_task_environment.h"
#include "chrome/browser/ui/app_list/app_list_test_util.h"
#include "chrome/browser/ui/app_list/search/omnibox_result.h"
#include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h"
#include "chrome/test/base/testing_profile.h"
#include "components/omnibox/browser/autocomplete_match_type.h"
#include "testing/gtest/include/gtest/gtest.h"
using test::TestAppListControllerDelegate;
using testing::Eq;
namespace app_list {
class RankingItemUtilTest : public AppListTestBase {
public:
RankingItemUtilTest() {}
~RankingItemUtilTest() override {}
// AppListTestBase overrides:
void SetUp() override {
AppListTestBase::SetUp();
app_list_controller_delegate_ =
std::make_unique<::test::TestAppListControllerDelegate>();
}
void SetAdaptiveRankerParams(
const std::map<std::string, std::string>& params) {
scoped_feature_list_.InitAndEnableFeatureWithParameters(
app_list_features::kEnableAdaptiveResultRanker, params);
}
std::unique_ptr<OmniboxResult> MakeOmniboxResult(
AutocompleteMatchType::Type type) {
AutocompleteMatch match;
match.type = type;
return std::make_unique<OmniboxResult>(profile_.get(),
app_list_controller_delegate_.get(),
nullptr, match, false);
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
std::unique_ptr<TestAppListControllerDelegate> app_list_controller_delegate_;
};
TEST_F(RankingItemUtilTest, OmniboxSubtypeReturnedWithFinchParameterOn) {
SetAdaptiveRankerParams({{"expand_omnibox_types", "true"}});
std::unique_ptr<OmniboxResult> result =
MakeOmniboxResult(AutocompleteMatchType::HISTORY_URL);
RankingItemType type = RankingItemTypeFromSearchResult(*result.get());
EXPECT_EQ(type, RankingItemType::kOmniboxHistory);
}
} // namespace app_list
......@@ -310,7 +310,7 @@ TEST_F(MixerTest, RankerIsDisabledWithFlag) {
CreateMixer(false);
for (int i = 0; i < 20; ++i)
Train("omnibox2", RankingItemType::kOmnibox);
Train("omnibox2", RankingItemType::kOmniboxGeneric);
app_provider()->set_count(4);
app_provider()->set_small_relevance_range();
......@@ -327,7 +327,7 @@ TEST_F(MixerTest, RankerImprovesScores) {
CreateMixer(true, {{"boost_coefficient", "10.0"}});
for (int i = 0; i < 20; ++i)
Train("omnibox2", RankingItemType::kOmnibox);
Train("omnibox2", RankingItemType::kOmniboxGeneric);
app_provider()->set_count(4);
app_provider()->set_small_relevance_range();
......
......@@ -4656,6 +4656,7 @@ test("unit_tests") {
"../browser/ui/app_list/search/search_result_ranker/app_launch_predictor_unittest.cc",
"../browser/ui/app_list/search/search_result_ranker/app_search_result_ranker_unittest.cc",
"../browser/ui/app_list/search/search_result_ranker/frecency_store_unittest.cc",
"../browser/ui/app_list/search/search_result_ranker/ranking_item_util_unittest.cc",
"../browser/ui/app_list/search/search_result_ranker/recurrence_predictor_unittest.cc",
"../browser/ui/app_list/search/search_result_ranker/recurrence_ranker_unittest.cc",
"../browser/ui/app_list/search/settings_shortcut/settings_shortcut_provider_unittest.cc",
......
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