Commit c858d6a3 authored by Rachel Wong's avatar Rachel Wong Committed by Commit Bot

[omnibox] Add rich entity data to OmniboxResult.

There are several AutocompleteMatch fields that provide rich entity
information but are currently not used by the launcher. This CL adds
rich entity fields to the omnibox results, which will then be forwarded
to ash.

Any changes which may override existing behaviour are gated behind a
feature flag.

Bug: 1130372
Change-Id: Ia92aaa88cc1c6af41bd3b820b85b978c7b108e1f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2409685
Commit-Queue: Rachel Wong <wrong@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarThanh Nguyen <thanhdng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811516}
parent 25500236
...@@ -274,7 +274,8 @@ struct ASH_PUBLIC_EXPORT SearchResultMetadata { ...@@ -274,7 +274,8 @@ struct ASH_PUBLIC_EXPORT SearchResultMetadata {
// The subtype of this result. Derived search result classes can use this to // The subtype of this result. Derived search result classes can use this to
// represent their own subtypes. Currently, OmniboxResult sets this to // represent their own subtypes. Currently, OmniboxResult sets this to
// indicate this is a history result, previous query, etc. A value of -1 // indicate this is a history result, previous query, etc. If a result is an
// Answer, OmniboxResult will set this to be the answer type. A value of -1
// indicates no subtype has been set. // indicates no subtype has been set.
int result_subtype = -1; int result_subtype = -1;
...@@ -303,6 +304,10 @@ struct ASH_PUBLIC_EXPORT SearchResultMetadata { ...@@ -303,6 +304,10 @@ struct ASH_PUBLIC_EXPORT SearchResultMetadata {
// Whether this result is a recommendation. // Whether this result is a recommendation.
bool is_recommendation = false; bool is_recommendation = false;
// Whether this result is an answer. Answer results should originate from
// base::SuggestionAnswer.
bool is_answer = false;
// A query URL associated with this result. The meaning and treatment of the // A query URL associated with this result. The meaning and treatment of the
// URL (e.g. displaying inline web contents) is dependent on the result type. // URL (e.g. displaying inline web contents) is dependent on the result type.
base::Optional<GURL> query_url; base::Optional<GURL> query_url;
......
...@@ -109,6 +109,11 @@ void ChromeSearchResult::SetIsRecommendation(bool is_recommendation) { ...@@ -109,6 +109,11 @@ void ChromeSearchResult::SetIsRecommendation(bool is_recommendation) {
SetSearchResultMetadata(); SetSearchResultMetadata();
} }
void ChromeSearchResult::SetIsAnswer(bool is_answer) {
metadata_->is_answer = is_answer;
SetSearchResultMetadata();
}
void ChromeSearchResult::SetQueryUrl(const GURL& url) { void ChromeSearchResult::SetQueryUrl(const GURL& url) {
metadata_->query_url = url; metadata_->query_url = url;
auto* updater = model_updater(); auto* updater = model_updater();
......
...@@ -26,7 +26,6 @@ namespace app_list { ...@@ -26,7 +26,6 @@ namespace app_list {
class AppContextMenu; class AppContextMenu;
} // namespace app_list } // namespace app_list
// ChromeSearchResult consists of an icon, title text and details text. Title // ChromeSearchResult consists of an icon, title text and details text. Title
// and details text can have tagged ranges that are displayed differently from // and details text can have tagged ranges that are displayed differently from
// default style. // default style.
...@@ -67,6 +66,7 @@ class ChromeSearchResult { ...@@ -67,6 +66,7 @@ class ChromeSearchResult {
double display_score() const { return metadata_->display_score; } double display_score() const { return metadata_->display_score; }
bool is_installing() const { return metadata_->is_installing; } bool is_installing() const { return metadata_->is_installing; }
bool is_recommendation() const { return metadata_->is_recommendation; } bool is_recommendation() const { return metadata_->is_recommendation; }
bool is_answer() const { return metadata_->is_answer; }
const base::Optional<GURL>& query_url() const { return metadata_->query_url; } const base::Optional<GURL>& query_url() const { return metadata_->query_url; }
const base::Optional<std::string>& equivalent_result_id() const { const base::Optional<std::string>& equivalent_result_id() const {
return metadata_->equivalent_result_id; return metadata_->equivalent_result_id;
...@@ -97,6 +97,7 @@ class ChromeSearchResult { ...@@ -97,6 +97,7 @@ class ChromeSearchResult {
void SetActions(const Actions& actions); void SetActions(const Actions& actions);
void SetIsOmniboxSearch(bool is_omnibox_search); void SetIsOmniboxSearch(bool is_omnibox_search);
void SetIsRecommendation(bool is_recommendation); void SetIsRecommendation(bool is_recommendation);
void SetIsAnswer(bool is_answer);
void SetIsInstalling(bool is_installing); void SetIsInstalling(bool is_installing);
void SetQueryUrl(const GURL& url); void SetQueryUrl(const GURL& url);
void SetEquivalentResutlId(const std::string& equivlanet_result_id); void SetEquivalentResutlId(const std::string& equivlanet_result_id);
......
...@@ -7,9 +7,12 @@ ...@@ -7,9 +7,12 @@
#include <stddef.h> #include <stddef.h>
#include "ash/public/cpp/app_list/app_list_config.h" #include "ash/public/cpp/app_list/app_list_config.h"
#include "ash/public/cpp/app_list/app_list_features.h"
#include "ash/public/cpp/app_list/vector_icons/vector_icons.h" #include "ash/public/cpp/app_list/vector_icons/vector_icons.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/strings/strcat.h"
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -125,6 +128,16 @@ const gfx::VectorIcon& TypeToVectorIcon(AutocompleteMatchType::Type type) { ...@@ -125,6 +128,16 @@ const gfx::VectorIcon& TypeToVectorIcon(AutocompleteMatchType::Type type) {
return ash::kDomainIcon; return ash::kDomainIcon;
} }
base::string16 ImageLineToString16(const SuggestionAnswer::ImageLine& line) {
std::vector<base::string16> text;
for (const auto& text_field : line.text_fields()) {
text.push_back(text_field.text());
}
// TODO(crbug.com/1130372): Use placeholders or a l10n-friendly way to
// construct this string instead of concatenation.
return base::JoinString(text, base::ASCIIToUTF16(" "));
}
} // namespace } // namespace
OmniboxResult::OmniboxResult(Profile* profile, OmniboxResult::OmniboxResult(Profile* profile,
...@@ -147,6 +160,12 @@ OmniboxResult::OmniboxResult(Profile* profile, ...@@ -147,6 +160,12 @@ OmniboxResult::OmniboxResult(Profile* profile,
set_result_subtype(static_cast<int>(match_.type)); set_result_subtype(static_cast<int>(match_.type));
SetMetricsType(GetSearchResultType()); SetMetricsType(GetSearchResultType());
if (ShouldDisplayAsAnswer()) {
SetIsAnswer(match_.answer.has_value());
// The answer subtype overrides the match subtype.
set_result_subtype(static_cast<int>(match_.answer->type()));
}
// Derive relevance from omnibox relevance and normalize it to [0, 1]. // Derive relevance from omnibox relevance and normalize it to [0, 1].
// The magic number 1500 is the highest score of an omnibox result. // The magic number 1500 is the highest score of an omnibox result.
// See comments in autocomplete_provider.h. // See comments in autocomplete_provider.h.
...@@ -263,7 +282,19 @@ void OmniboxResult::UpdateTitleAndDetails() { ...@@ -263,7 +282,19 @@ void OmniboxResult::UpdateTitleAndDetails() {
// details. // details.
const bool use_directly = !IsUrlResultWithDescription(); const bool use_directly = !IsUrlResultWithDescription();
ChromeSearchResult::Tags title_tags; ChromeSearchResult::Tags title_tags;
if (use_directly) { if (ShouldDisplayAsAnswer()) {
const auto* additional_text = match_.answer->first_line().additional_text();
const bool has_additional_text =
additional_text && !additional_text->text().empty();
// TODO(crbug.com/1130372): Use placeholders or a l10n-friendly way to
// construct this string instead of concatenation.
SetTitle(has_additional_text
? base::StrCat({match_.contents, base::ASCIIToUTF16(" "),
additional_text->text()})
: match_.contents);
ACMatchClassificationsToTags(match_.contents, match_.contents_class,
&title_tags);
} else if (use_directly) {
SetTitle(match_.contents); SetTitle(match_.contents);
ACMatchClassificationsToTags(match_.contents, match_.contents_class, ACMatchClassificationsToTags(match_.contents, match_.contents_class,
&title_tags); &title_tags);
...@@ -275,7 +306,10 @@ void OmniboxResult::UpdateTitleAndDetails() { ...@@ -275,7 +306,10 @@ void OmniboxResult::UpdateTitleAndDetails() {
SetTitleTags(title_tags); SetTitleTags(title_tags);
ChromeSearchResult::Tags details_tags; ChromeSearchResult::Tags details_tags;
if (use_directly) { if (ShouldDisplayAsAnswer()) {
// Answer results will contain the answer in the second line.
SetDetails(ImageLineToString16(match_.answer->second_line()));
} else if (use_directly) {
if (AutocompleteMatch::IsSearchType(match_.type)) { if (AutocompleteMatch::IsSearchType(match_.type)) {
SetAccessibleName(l10n_util::GetStringFUTF16( SetAccessibleName(l10n_util::GetStringFUTF16(
IDS_APP_LIST_QUERY_SEARCH_ACCESSIBILITY_NAME, title(), IDS_APP_LIST_QUERY_SEARCH_ACCESSIBILITY_NAME, title(),
...@@ -343,4 +377,8 @@ void OmniboxResult::RecordOmniboxResultHistogram() { ...@@ -343,4 +377,8 @@ void OmniboxResult::RecordOmniboxResultHistogram() {
: OmniboxResultType::kQuerySuggestion); : OmniboxResultType::kQuerySuggestion);
} }
bool OmniboxResult::ShouldDisplayAsAnswer() {
return app_list_features::IsOmniboxRichEntitiesEnabled() && is_answer();
}
} // namespace app_list } // namespace app_list
...@@ -60,6 +60,10 @@ class OmniboxResult : public ChromeSearchResult { ...@@ -60,6 +60,10 @@ class OmniboxResult : public ChromeSearchResult {
ash::SearchResultType GetSearchResultType() const; ash::SearchResultType GetSearchResultType() const;
// Whether or not the result is an answer and rich entities are enabled.
// TODO(crbug/1130372): Remove this when rich entities are enabled by default.
bool ShouldDisplayAsAnswer();
Profile* profile_; Profile* profile_;
AppListControllerDelegate* list_controller_; AppListControllerDelegate* list_controller_;
AutocompleteController* autocomplete_controller_; AutocompleteController* autocomplete_controller_;
......
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