Commit 6951ee71 authored by manuk's avatar manuk Committed by Commit Bot

[omnibox] Return documents after provider_max_matches_ with score 0.

Currently, the doc provider returns at most provider_max_matches_ docs, dropping
any additional docs returned from the server. With this CL, the provider returns
the remaining docs with a score of 0 so that they are displayed only if deduped
with history, shortcut, or bookmark matches.

This CL does not affect how many or which suggestions are displayed. It
only helps format doc suggestions from other providers (e.g. 'Omnibox doc -
01/01/1991 - Google Docs').

Bug: 941548
Change-Id: I173b3f62d3af33f83a6531e086a0ecd0985db986
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1819629Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Commit-Queue: manuk hovanesian <manukh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699027}
parent 0facb111
...@@ -695,9 +695,6 @@ ACMatches DocumentProvider::ParseDocumentSearchResults( ...@@ -695,9 +695,6 @@ ACMatches DocumentProvider::ParseDocumentSearchResults(
// Ensure server's suggestions are added with monotonically decreasing scores. // Ensure server's suggestions are added with monotonically decreasing scores.
int previous_score = INT_MAX; int previous_score = INT_MAX;
for (size_t i = 0; i < num_results; i++) { for (size_t i = 0; i < num_results; i++) {
if (matches.size() >= provider_max_matches_) {
break;
}
const base::DictionaryValue* result = nullptr; const base::DictionaryValue* result = nullptr;
if (!results_list->GetDictionary(i, &result)) { if (!results_list->GetDictionary(i, &result)) {
return matches; return matches;
...@@ -716,13 +713,18 @@ ACMatches DocumentProvider::ParseDocumentSearchResults( ...@@ -716,13 +713,18 @@ ACMatches DocumentProvider::ParseDocumentSearchResults(
int server_score = 0; int server_score = 0;
result->GetInteger("score", &server_score); result->GetInteger("score", &server_score);
int score = 0; int score = 0;
// Set |score| only if we haven't surpassed |provider_max_matches_| yet.
// Otherwise, score the remaining matches 0 to avoid displaying them except
// when deduped with history, shortcut, or bookmark matches.
if (matches.size() < provider_max_matches_) {
if (use_client_score && use_server_score) if (use_client_score && use_server_score)
score = std::min(client_score, server_score); score = std::min(client_score, server_score);
else else
score = use_client_score ? client_score : server_score; score = use_client_score ? client_score : server_score;
if (cap_score_per_rank) { if (cap_score_per_rank) {
int score_cap = i < score_caps.size() ? score_caps[i] : score_caps.back(); int score_cap =
i < score_caps.size() ? score_caps[i] : score_caps.back();
score = std::min(score, score_cap); score = std::min(score, score_cap);
} }
...@@ -735,6 +737,7 @@ ACMatches DocumentProvider::ParseDocumentSearchResults( ...@@ -735,6 +737,7 @@ ACMatches DocumentProvider::ParseDocumentSearchResults(
if (!use_client_score && score >= previous_score) if (!use_client_score && score >= previous_score)
score = std::max(previous_score - 1, 0); score = std::max(previous_score - 1, 0);
previous_score = score; previous_score = score;
}
AutocompleteMatch match(this, score, false, AutocompleteMatch match(this, score, false,
AutocompleteMatchType::DOCUMENT_SUGGESTION); AutocompleteMatchType::DOCUMENT_SUGGESTION);
...@@ -776,6 +779,8 @@ ACMatches DocumentProvider::ParseDocumentSearchResults( ...@@ -776,6 +779,8 @@ ACMatches DocumentProvider::ParseDocumentSearchResults(
match.transition = ui::PAGE_TRANSITION_GENERATED; match.transition = ui::PAGE_TRANSITION_GENERATED;
match.RecordAdditionalInfo("client score", client_score); match.RecordAdditionalInfo("client score", client_score);
match.RecordAdditionalInfo("server score", server_score); match.RecordAdditionalInfo("server score", server_score);
if (matches.size() >= provider_max_matches_)
match.RecordAdditionalInfo("for deduping only", "true");
const std::string* snippet = result->FindStringPath("snippet.snippet"); const std::string* snippet = result->FindStringPath("snippet.snippet");
if (snippet) if (snippet)
match.RecordAdditionalInfo("snippet", *snippet); match.RecordAdditionalInfo("snippet", *snippet);
......
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