Commit 1a5c61ae authored by tby's avatar tby Committed by Chromium LUCI CQ

Fix duplicate search results in launcher

There are some edge cases where we still show duplicate results. Until
we remove the old logic that does this, we should continue de-duping.

Bug: 1156846
Change-Id: I4366467ebf645c3b957bea6916be90be71bbcdc3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2596456
Commit-Queue: Tony Yeoman <tby@chromium.org>
Reviewed-by: default avatarThanh Nguyen <thanhdng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837929}
parent c4239a2d
......@@ -15,6 +15,8 @@
#include "base/macros.h"
#include "base/metrics/field_trial_params.h"
#include "base/numerics/ranges.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/ui/app_list/app_list_model_updater.h"
#include "chrome/browser/ui/app_list/search/chrome_search_result.h"
#include "chrome/browser/ui/app_list/search/search_controller.h"
......@@ -24,6 +26,32 @@
#include "chrome/browser/ui/app_list/search/search_result_ranker/search_result_ranker.h"
namespace app_list {
namespace {
// TODO(crbug.com/1028447): This is a stop-gap until we remove the two-stage
// result adding logic in Mixer::MixAndPublish. Remove this when possible.
void RemoveDuplicates(Mixer::SortedResults* results) {
Mixer::SortedResults deduplicated;
deduplicated.reserve(results->size());
std::set<std::string> seen;
for (const Mixer::SortData& sort_data : *results) {
// If a result is intended for display in two views, we will have two
// results with the same id but different display types. We want to keep
// both of these, so insert concat(id, display_type).
const std::string display_type = base::NumberToString(
static_cast<int>(sort_data.result->display_type()));
if (!seen.insert(base::StrCat({sort_data.result->id(), display_type}))
.second)
continue;
deduplicated.emplace_back(sort_data);
}
results->swap(deduplicated);
}
} // namespace
Mixer::SortData::SortData() : result(nullptr), score(0.0) {}
......@@ -151,6 +179,7 @@ void Mixer::MixAndPublish(size_t num_max_results, const base::string16& query) {
// would not be seen at all once the result list is truncated.)
std::sort(results.begin() + original_size, results.end());
}
RemoveDuplicates(&results);
std::vector<ChromeSearchResult*> new_results;
for (const SortData& sort_data : results) {
......
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