Commit df4ede0f authored by Donn Denman's avatar Donn Denman Committed by Commit Bot

[TTS][Template URL] Add support for exact-search.

Adds support for a new Contextual Search Resolve request parameter:
"ctxsl_exact" boolean used to restrict the server to only resolve
a search for the exact selection.  This means the returned Search
Term is restricted to the exact selection and the selection will
not be expanded.  This is needed for user-adjusted selections
as part of the Long-press triggering experiment.

BUG=956277

Change-Id: I5f1285ce04bd4afff7250fbc76bca79c4da0dbf7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1994265
Commit-Queue: Donn Denman <donnd@chromium.org>
Auto-Submit: Donn Denman <donnd@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#733058}
parent cb008a1d
...@@ -285,10 +285,12 @@ std::string ContextualSearchDelegate::BuildRequestUrl( ...@@ -285,10 +285,12 @@ std::string ContextualSearchDelegate::BuildRequestUrl(
contextual_cards_version = field_trial_->GetContextualCardsVersion(); contextual_cards_version = field_trial_->GetContextualCardsVersion();
} }
// TODO(donnd): use a passed-in value for is_search_exact ASAP (CL pending).
bool is_exact_search = false;
TemplateURLRef::SearchTermsArgs::ContextualSearchParams params( TemplateURLRef::SearchTermsArgs::ContextualSearchParams params(
kContextualSearchRequestVersion, contextual_cards_version, kContextualSearchRequestVersion, contextual_cards_version,
context->GetHomeCountry(), context->GetPreviousEventId(), context->GetHomeCountry(), context->GetPreviousEventId(),
context->GetPreviousEventResults()); context->GetPreviousEventResults(), is_exact_search);
search_terms_args.contextual_search_params = params; search_terms_args.contextual_search_params = params;
......
...@@ -216,23 +216,21 @@ size_t TemplateURLRef::SearchTermsArgs::EstimateMemoryUsage() const { ...@@ -216,23 +216,21 @@ size_t TemplateURLRef::SearchTermsArgs::EstimateMemoryUsage() const {
} }
TemplateURLRef::SearchTermsArgs::ContextualSearchParams:: TemplateURLRef::SearchTermsArgs::ContextualSearchParams::
ContextualSearchParams() ContextualSearchParams() = default;
: version(-1),
contextual_cards_version(0),
previous_event_id(0),
previous_event_results(0) {}
TemplateURLRef::SearchTermsArgs::ContextualSearchParams::ContextualSearchParams( TemplateURLRef::SearchTermsArgs::ContextualSearchParams::ContextualSearchParams(
int version, int version,
int contextual_cards_version, int contextual_cards_version,
const std::string& home_country, const std::string& home_country,
int64_t previous_event_id, int64_t previous_event_id,
int previous_event_results) int previous_event_results,
bool is_exact_search)
: version(version), : version(version),
contextual_cards_version(contextual_cards_version), contextual_cards_version(contextual_cards_version),
home_country(home_country), home_country(home_country),
previous_event_id(previous_event_id), previous_event_id(previous_event_id),
previous_event_results(previous_event_results) {} previous_event_results(previous_event_results),
is_exact_search(is_exact_search) {}
TemplateURLRef::SearchTermsArgs::ContextualSearchParams::ContextualSearchParams( TemplateURLRef::SearchTermsArgs::ContextualSearchParams::ContextualSearchParams(
const ContextualSearchParams& other) = default; const ContextualSearchParams& other) = default;
...@@ -995,6 +993,8 @@ std::string TemplateURLRef::HandleReplacements( ...@@ -995,6 +993,8 @@ std::string TemplateURLRef::HandleReplacements(
args.push_back("ctxsl_per=" + args.push_back("ctxsl_per=" +
base::NumberToString(params.previous_event_results)); base::NumberToString(params.previous_event_results));
} }
if (params.is_exact_search)
args.push_back("ctxsl_exact=1");
HandleReplacement(std::string(), base::JoinString(args, "&"), *i, &url); HandleReplacement(std::string(), base::JoinString(args, "&"), *i, &url);
break; break;
......
...@@ -107,11 +107,17 @@ class TemplateURLRef { ...@@ -107,11 +107,17 @@ class TemplateURLRef {
// The |previous_event_results| are the results of the user-interaction of // The |previous_event_results| are the results of the user-interaction of
// that previous request. // that previous request.
// The "previous_xyz" parameters are documented in go/cs-sanitized. // The "previous_xyz" parameters are documented in go/cs-sanitized.
// The |is_exact_search| allows the search request to be narrowed down to
// an "exact" search only, meaning just search for X rather than X +
// whatever else is in the context. The returned search term should not
// be expanded, and the server will honor this along with creating a
// narrow Search Term.
ContextualSearchParams(int version, ContextualSearchParams(int version,
int contextual_cards_version, int contextual_cards_version,
const std::string& home_country, const std::string& home_country,
int64_t previous_event_id, int64_t previous_event_id,
int previous_event_results); int previous_event_results,
bool is_exact_search);
ContextualSearchParams(const ContextualSearchParams& other); ContextualSearchParams(const ContextualSearchParams& other);
~ContextualSearchParams(); ~ContextualSearchParams();
...@@ -120,11 +126,11 @@ class TemplateURLRef { ...@@ -120,11 +126,11 @@ class TemplateURLRef {
size_t EstimateMemoryUsage() const; size_t EstimateMemoryUsage() const;
// The version of contextual search. // The version of contextual search.
int version; int version = -1;
// The version of Contextual Cards data to request. // The version of Contextual Cards data to request.
// A value of 0 indicates no data needed. // A value of 0 indicates no data needed.
int contextual_cards_version; int contextual_cards_version = 0;
// The locale of the user's home country in an ISO country code format, // The locale of the user's home country in an ISO country code format,
// or an empty string if not available. This indicates where the user // or an empty string if not available. This indicates where the user
...@@ -133,11 +139,15 @@ class TemplateURLRef { ...@@ -133,11 +139,15 @@ class TemplateURLRef {
// An EventID from a previous interaction (sent by server, recorded by // An EventID from a previous interaction (sent by server, recorded by
// client). // client).
int64_t previous_event_id; int64_t previous_event_id = 0l;
// An encoded set of booleans that represent the interaction results from // An encoded set of booleans that represent the interaction results from
// the previous event. // the previous event.
int previous_event_results; int previous_event_results = 0;
// A flag that restricts the search to exactly match the selection rather
// than expanding the Search Term to include other words in the context.
bool is_exact_search = false;
}; };
// Estimates dynamic memory usage. // Estimates dynamic memory usage.
......
...@@ -1741,7 +1741,7 @@ TEST_F(TemplateURLTest, ContextualSearchParameters) { ...@@ -1741,7 +1741,7 @@ TEST_F(TemplateURLTest, ContextualSearchParameters) {
// Test the current common case, which uses no home country or previous // Test the current common case, which uses no home country or previous
// event. // event.
TemplateURLRef::SearchTermsArgs::ContextualSearchParams params( TemplateURLRef::SearchTermsArgs::ContextualSearchParams params(
2, 1, std::string(), 0, 0); 2, 1, std::string(), 0, 0, false);
search_terms_args.contextual_search_params = params; search_terms_args.contextual_search_params = params;
result = url.url_ref().ReplaceSearchTerms(search_terms_args, result = url.url_ref().ReplaceSearchTerms(search_terms_args,
search_terms_data_); search_terms_data_);
...@@ -1753,8 +1753,8 @@ TEST_F(TemplateURLTest, ContextualSearchParameters) { ...@@ -1753,8 +1753,8 @@ TEST_F(TemplateURLTest, ContextualSearchParameters) {
// Test the home country and non-zero event data case. // Test the home country and non-zero event data case.
search_terms_args.contextual_search_params = search_terms_args.contextual_search_params =
TemplateURLRef::SearchTermsArgs::ContextualSearchParams(2, 2, "CH", TemplateURLRef::SearchTermsArgs::ContextualSearchParams(
1657713458, 5); 2, 2, "CH", 1657713458, 5, false);
result = result =
url.url_ref().ReplaceSearchTerms(search_terms_args, search_terms_data_); url.url_ref().ReplaceSearchTerms(search_terms_args, search_terms_data_);
...@@ -1766,6 +1766,17 @@ TEST_F(TemplateURLTest, ContextualSearchParameters) { ...@@ -1766,6 +1766,17 @@ TEST_F(TemplateURLTest, ContextualSearchParameters) {
"ctxsl_pid=1657713458&" "ctxsl_pid=1657713458&"
"ctxsl_per=5", "ctxsl_per=5",
result); result);
// Test exact-search.
search_terms_args.contextual_search_params =
TemplateURLRef::SearchTermsArgs::ContextualSearchParams(
2, 1, std::string(), 0, 0, true);
result =
url.url_ref().ReplaceSearchTerms(search_terms_args, search_terms_data_);
// Find our param.
size_t found_pos = result.find("ctxsl_exact=1");
EXPECT_NE(found_pos, std::string::npos);
} }
TEST_F(TemplateURLTest, GenerateKeyword) { TEST_F(TemplateURLTest, GenerateKeyword) {
......
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