Commit 8d0baacf authored by tby's avatar tby Committed by Commit Bot

[Cros SR] Pass the current query to SearchResultRanker::Train.

Our upcoming query-based model will probably require the most recent
query as a feature for training. This model is owned by the
SearchResultRanker, which currently only receives the query at
at inference-time, not at training-time. This CL fixes that.

Bug: 931149
Change-Id: I97476d5a406740367e18275b22fe5e61648458cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1669995Reviewed-by: default avatarcalamity <calamity@chromium.org>
Reviewed-by: default avatarJia Meng <jiameng@chromium.org>
Commit-Queue: Tony Yeoman <tby@chromium.org>
Cr-Commit-Position: refs/heads/master@{#671574}
parent 38ac7824
......@@ -171,9 +171,11 @@ SearchResultRanker* Mixer::GetNonAppSearchResultRanker() {
return non_app_ranker_.get();
}
void Mixer::Train(const std::string& id, RankingItemType type) {
void Mixer::Train(const std::string& query,
const std::string& id,
RankingItemType type) {
if (non_app_ranker_)
non_app_ranker_->Train(id, type);
non_app_ranker_->Train(query, id, type);
}
} // namespace app_list
......@@ -8,6 +8,7 @@
#include <stddef.h>
#include <memory>
#include <string>
#include <vector>
#include "base/gtest_prod_util.h"
......@@ -59,7 +60,9 @@ class Mixer {
SearchResultRanker* GetNonAppSearchResultRanker();
// Handle a training signal.
void Train(const std::string& id, RankingItemType type);
void Train(const std::string& query,
const std::string& id,
RankingItemType type);
// Used for sorting and mixing results.
struct SortData {
......
......@@ -215,7 +215,7 @@ void SearchController::Train(const std::string& id, RankingItemType type) {
for (const auto& provider : providers_)
provider->Train(id, type);
mixer_->Train(id, type);
mixer_->Train(base::UTF16ToUTF8(last_query_), id, type);
}
} // namespace app_list
......@@ -189,7 +189,8 @@ void SearchResultRanker::FetchRankings(const base::string16& query) {
time_of_last_fetch_ = now;
// TODO(931149): The passed |query| should be used to choose between ranking
// results with using a zero-state or query-based model.
// results with using a zero-state or query-based model. It may also be needed
// for rankings from the query model.
if (results_list_group_ranker_) {
group_ranks_.clear();
......@@ -236,7 +237,11 @@ void SearchResultRanker::Rank(Mixer::SortedResults* results) {
}
}
void SearchResultRanker::Train(const std::string& id, RankingItemType type) {
void SearchResultRanker::Train(const std::string& query,
const std::string& id,
RankingItemType type) {
// TODO(931149): Use the passed |query| as part of the training for the query
// model if it requires it.
if (ModelForType(type) == Model::MIXED_TYPES) {
if (results_list_group_ranker_) {
results_list_group_ranker_->Record(
......
......@@ -47,10 +47,13 @@ class SearchResultRanker : file_manager::file_tasks::FileTasksObserver {
void Rank(Mixer::SortedResults* results);
// Forwards the given training signal to the relevant models contained within
// the SearchResultRanker. |id| is the string ID of an item that is launched
// from the launcher, eg. an app ID or a filepath, and is derived from the
// relevant ChromeSearchResult's ID.
void Train(const std::string& id, RankingItemType type);
// the SearchResultRanker. |query| is the user's search string, which may be
// empty. |id| is the string ID of an item that is launched from the launcher,
// eg. an app ID or a filepath, and is derived from the relevant
// ChromeSearchResult's ID.
void Train(const std::string& query,
const std::string& id,
RankingItemType type);
// file_manager::file_tasks::FileTaskObserver:
void OnFilesOpened(const std::vector<FileOpenEvent>& file_opens) override;
......
......@@ -135,7 +135,7 @@ class SearchResultRankerTest : public testing::Test {
TEST_F(SearchResultRankerTest, MixedTypesRankersAreDisabledWithFlag) {
auto ranker = MakeRanker(false);
for (int i = 0; i < 20; ++i)
ranker->Train("unused", RankingItemType::kFile);
ranker->Train("query", "unused", RankingItemType::kFile);
ranker->FetchRankings(base::string16());
auto results =
......@@ -154,7 +154,7 @@ TEST_F(SearchResultRankerTest, CategoryModelImprovesScores) {
auto ranker = MakeRanker(
true, {{"use_category_model", "true"}, {"boost_coefficient", "1.0"}});
for (int i = 0; i < 20; ++i)
ranker->Train("unused", RankingItemType::kFile);
ranker->Train("query", "unused", RankingItemType::kFile);
ranker->FetchRankings(base::string16());
auto results =
......@@ -174,8 +174,8 @@ TEST_F(SearchResultRankerTest, ItemModelImprovesScores) {
auto ranker = MakeRanker(true, {{"boost_coefficient", "1.0"}});
for (int i = 0; i < 10; ++i) {
ranker->Train("C", RankingItemType::kFile);
ranker->Train("D", RankingItemType::kFile);
ranker->Train("query", "C", RankingItemType::kFile);
ranker->Train("query", "D", RankingItemType::kFile);
}
ranker->FetchRankings(base::string16());
......@@ -205,8 +205,8 @@ TEST_F(SearchResultRankerTest, ItemModelNormalizesUrlIds) {
auto ranker = MakeRanker(true, {{"boost_coefficient", "1.0"}});
for (int i = 0; i < 5; ++i) {
ranker->Train(url_1, RankingItemType::kOmniboxHistory);
ranker->Train(url_3, RankingItemType::kOmniboxHistory);
ranker->Train("query", url_1, RankingItemType::kOmniboxHistory);
ranker->Train("query", url_3, RankingItemType::kOmniboxHistory);
}
ranker->FetchRankings(base::string16());
......
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