Skip to content

Commit

Permalink
[games] Tweak the games scoring parameters.
Browse files Browse the repository at this point in the history
This CL contains two tweaks that aim to limit overtriggering of game
results:

1. Increase the minimum score threshold for game results.

This has been tested with some sample queries, but further improvements
will need to actually delve deeper into the scoring mechanisms.

2. Ignore some common game title punctuation characters when searching.

This allows for some games with these punctuations to still exceed the
minimum score threshold.

Bug: 1350008
Change-Id: Ie7a58919d7fa84bf0a313b805b1cd8fbab7aa293
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3827104
Commit-Queue: Rachel Wong <wrong@chromium.org>
Reviewed-by: Amanda Deacon <amandadeacon@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1034951}
  • Loading branch information
Rachel Wong authored and Chromium LUCI CQ committed Aug 15, 2022
1 parent dee85ed commit 29d134e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
23 changes: 19 additions & 4 deletions chrome/browser/ui/app_list/search/games/game_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "base/metrics/histogram_functions.h"
#include "base/rand_util.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "chrome/browser/apps/app_discovery_service/app_discovery_service.h"
Expand Down Expand Up @@ -39,9 +40,9 @@ using ::ash::string_matching::TokenizedString;
// Parameters for FuzzyTokenizedStringMatch.
constexpr bool kUseWeightedRatio = false;
constexpr bool kUseEditDistance = false;
constexpr double kRelevanceThreshold = 0.32;
constexpr double kPartialMatchPenaltyRate = 0.9;

constexpr double kRelevanceThreshold = 0.65;
constexpr size_t kMaxResults = 3u;
constexpr double kEpsilon = 1e-5;

Expand Down Expand Up @@ -76,10 +77,22 @@ bool EnabledByPolicy(Profile* profile) {
return suggested_content_enabled;
}

// Game titles often contain special characters. Strip out some common ones
// before searching.
// This does not affect query highlighting, which calculates matched portions of
// text in a separate post-processing step.
std::u16string GetStrippedText(const std::u16string& text) {
std::u16string stripped_text;
// In order, these are: apostrophe, left quote, right quote, TM, circled R.
base::RemoveChars(text, u"\'\u2018\u2019\u2122\u24C7", &stripped_text);
return stripped_text;
}

double CalculateTitleRelevance(const TokenizedString& tokenized_query,
const std::u16string& game_title) {
const TokenizedString tokenized_title(game_title,
TokenizedString::Mode::kCamelCase);
std::u16string stripped_title = GetStrippedText(game_title);
const TokenizedString tokenized_title(stripped_title,
TokenizedString::Mode::kWords);

if (tokenized_query.text().empty() || tokenized_title.text().empty()) {
static constexpr double kDefaultRelevance = 0.0;
Expand All @@ -96,7 +109,9 @@ std::vector<std::pair<const apps::Result*, double>> SearchGames(
const GameProvider::GameIndex* index) {
DCHECK(index);

TokenizedString tokenized_query(query, TokenizedString::Mode::kCamelCase);
std::u16string stripped_query = GetStrippedText(query);
TokenizedString tokenized_query(stripped_query,
TokenizedString::Mode::kWords);
std::vector<std::pair<const apps::Result*, double>> matches;
for (const auto& game : *index) {
double relevance =
Expand Down
21 changes: 21 additions & 0 deletions chrome/browser/ui/app_list/search/games/game_provider_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,27 @@ TEST_P(GameProviderTest, SearchResultsMatchQuery) {
Title(u"Third Title")));
}

// Tests that scores are not greatly affected by characters such as apostrophe.
TEST_P(GameProviderTest, SpecialCharactersIgnored) {
GameProvider::GameIndex index;
index.push_back(MakeAppsResult(u"titles one"));
index.push_back(MakeAppsResult(u"title's one"));
provider()->SetGameIndexForTest(std::move(index));

// Expect that the results have similar scores.
StartSearch(u"titles");
ASSERT_EQ(LastResults().size(), 2);
double score_diff =
abs(LastResults()[0]->relevance() - LastResults()[1]->relevance());
EXPECT_LT(score_diff, 0.01);

StartSearch(u"title's");
ASSERT_EQ(LastResults().size(), 2);
score_diff =
abs(LastResults()[0]->relevance() - LastResults()[1]->relevance());
EXPECT_LT(score_diff, 0.01);
}

TEST_P(GameProviderTest, Policy) {
SetUpTestingIndex();

Expand Down

0 comments on commit 29d134e

Please sign in to comment.