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

[Launcher settings] Splits max requested and max shown results.

We request a certain number of results from the settings search backend,
and also have a maximum number of results we want to show. However the
backend can return duplicate results that are removed, so we should
request a few more results than we need to display.

This CL also removes a TODO on testing the new settings results.

Bug: 1068851
Change-Id: I7a80766112f06679ceae19057f6e9adfe36c44aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2217721Reviewed-by: default avatarRachel Wong <wrong@chromium.org>
Commit-Queue: Tony Yeoman <tby@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773006}
parent 91c1f90f
......@@ -33,7 +33,8 @@ using SearchResultPtr = chromeos::settings::mojom::SearchResultPtr;
constexpr char kOsSettingsResultPrefix[] = "os-settings://";
constexpr float kScoreEps = 1e-5;
constexpr size_t kMaxResults = 2u;
constexpr size_t kNumRequestedResults = 5u;
constexpr size_t kMaxShownResults = 2u;
// Various error states of the OsSettingsProvider. kOk is currently not emitted,
// but may be used in future. These values persist to logs. Entries should not
......@@ -152,11 +153,7 @@ void OsSettingsProvider::Start(const base::string16& query) {
// Invalidate weak pointers to cancel existing searches.
weak_factory_.InvalidateWeakPtrs();
// TODO(crbug.com/1068851): There are currently only a handful of settings
// returned from the backend. Once the search service has finished integration
// into settings, verify we see all results here, and that opening works
// correctly for the new URLs.
search_handler_->Search(query, kMaxResults,
search_handler_->Search(query, kNumRequestedResults,
chromeos::settings::mojom::ParentResultBehavior::
kDoNotIncludeParentResults,
base::BindOnce(&OsSettingsProvider::OnSearchReturned,
......@@ -165,7 +162,7 @@ void OsSettingsProvider::Start(const base::string16& query) {
void OsSettingsProvider::OnSearchReturned(
std::vector<chromeos::settings::mojom::SearchResultPtr> results) {
DCHECK_LE(results.size(), kMaxResults);
DCHECK_LE(results.size(), kNumRequestedResults);
std::vector<SearchResultPtr> clean_results = DeduplicateResults(results);
std::sort(clean_results.begin(), clean_results.end(),
......@@ -177,7 +174,8 @@ void OsSettingsProvider::OnSearchReturned(
// Instead, we are gluing at most two to the top of the search box. Consider
// ranking these with other results in the next version of the feature.
SearchProvider::Results search_results;
for (size_t i = 0; i < clean_results.size(); ++i) {
const size_t num_results = std::min(clean_results.size(), kMaxShownResults);
for (size_t i = 0; i < num_results; ++i) {
const auto& result = clean_results[i];
const float score = 1.0f - i * kScoreEps;
search_results.emplace_back(
......
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