Commit d4203a22 authored by Daniel Classon's avatar Daniel Classon Committed by Commit Bot

[OsSettingsSearch] Hide identical search results for subpage and setting

Modified AddSubpageResult to check for identical search tags between
subpages and child settings, similar to the existing check between
settings and subpages. Helps with deep linking the change account image
setting which ran into this behavior.

Bug: 1084154
Change-Id: I19ef66dff5279a2804041eaf258a5b59ad687f3c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2376453Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Daniel Classon <dclasson@google.com>
Cr-Commit-Position: refs/heads/master@{#801568}
parent 881845a9
......@@ -153,7 +153,7 @@ void SearchHandler::AddParentResults(
// Nested subpage.
if (metadata.parent_subpage) {
it = AddSubpageResultIfPossible(it, *metadata.parent_subpage,
it = AddSubpageResultIfPossible(it, result, *metadata.parent_subpage,
result->relevance_score,
search_results);
break;
......@@ -171,7 +171,7 @@ void SearchHandler::AddParentResults(
// Nested setting.
if (metadata.primary.second) {
it = AddSubpageResultIfPossible(it, *metadata.primary.second,
it = AddSubpageResultIfPossible(it, result, *metadata.primary.second,
result->relevance_score,
search_results);
break;
......@@ -213,6 +213,7 @@ SearchHandler::AddSectionResultIfPossible(
std::vector<mojom::SearchResultPtr>::iterator
SearchHandler::AddSubpageResultIfPossible(
const std::vector<mojom::SearchResultPtr>::iterator& curr_position,
const mojom::SearchResultPtr& child_result,
mojom::Subpage subpage,
double relevance_score,
std::vector<mojom::SearchResultPtr>* results) const {
......@@ -220,6 +221,15 @@ SearchHandler::AddSubpageResultIfPossible(
if (ContainsSubpageResult(*results, subpage))
return curr_position;
mojom::SearchResultPtr subpage_result =
hierarchy_->GetSubpageMetadata(subpage).ToSearchResult(
child_result->relevance_score);
// Don't add a result for a parent subpage if it has the exact same text as
// the child result, since this results in a broken-looking UI.
if (subpage_result->result_text == child_result->result_text)
return curr_position;
return results->insert(
curr_position + 1,
hierarchy_->GetSubpageMetadata(subpage).ToSearchResult(relevance_score));
......
......@@ -90,6 +90,7 @@ class SearchHandler : public mojom::SearchHandler,
std::vector<mojom::SearchResultPtr>::iterator AddSubpageResultIfPossible(
const std::vector<mojom::SearchResultPtr>::iterator& position,
const mojom::SearchResultPtr& child_result,
mojom::Subpage subpage,
double relevance_score,
std::vector<mojom::SearchResultPtr>* results) const;
......
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