Commit e5fcee48 authored by groby's avatar groby Committed by Commit bot

[AiS] Use top local result for prefetch.

For answers prefetching, Chrome needs to know what the top search history
result for the current input is - _before_ issuing a search engine query
for that same input

BUG=406588

Review URL: https://codereview.chromium.org/470313004

Cr-Commit-Position: refs/heads/master@{#296873}
parent 83d08a29
...@@ -3409,16 +3409,22 @@ TEST_F(SearchProviderTest, AnswersCache) { ...@@ -3409,16 +3409,22 @@ TEST_F(SearchProviderTest, AnswersCache) {
provider_->RegisterDisplayedAnswers(result); provider_->RegisterDisplayedAnswers(result);
ASSERT_FALSE(provider_->answers_cache_.empty()); ASSERT_FALSE(provider_->answers_cache_.empty());
// Test that DoAnswersQuery retrieves data from cache. // Without scored results, no answers will be retrieved.
AutocompleteInput input(base::ASCIIToUTF16("weather l"), AnswersQueryData answer = provider_->FindAnswersPrefetchData();
base::string16::npos, base::string16(), GURL(), EXPECT_TRUE(answer.full_query_text.empty());
metrics::OmniboxEventProto::INVALID_SPEC, false, EXPECT_TRUE(answer.query_type.empty());
false, true, true,
ChromeAutocompleteSchemeClassifier(&profile_)); // Inject a scored result, which will trigger answer retrieval.
provider_->DoAnswersQuery(input); base::string16 query = base::ASCIIToUTF16("weather los angeles");
EXPECT_EQ(base::ASCIIToUTF16("weather los angeles"), SearchSuggestionParser::SuggestResult suggest_result(
provider_->prefetch_data_.full_query_text); query, AutocompleteMatchType::SEARCH_HISTORY, query, base::string16(),
EXPECT_EQ(base::ASCIIToUTF16("2334"), provider_->prefetch_data_.query_type); base::string16(), base::string16(), base::string16(), std::string(),
std::string(), false, 1200, false, false, query);
QueryForInput(ASCIIToUTF16("weather l"), false, false);
provider_->transformed_default_history_results_.push_back(suggest_result);
answer = provider_->FindAnswersPrefetchData();
EXPECT_EQ(base::ASCIIToUTF16("weather los angeles"), answer.full_query_text);
EXPECT_EQ(base::ASCIIToUTF16("2334"), answer.query_type);
} }
TEST_F(SearchProviderTest, RemoveExtraAnswers) { TEST_F(SearchProviderTest, RemoveExtraAnswers) {
......
This diff is collapsed.
...@@ -254,21 +254,35 @@ class SearchProvider : public BaseSearchProvider, ...@@ -254,21 +254,35 @@ class SearchProvider : public BaseSearchProvider,
const SearchSuggestionParser::NavigationResults& navigation_results, const SearchSuggestionParser::NavigationResults& navigation_results,
ACMatches* matches); ACMatches* matches);
// Adds a match for each result in |results| to |map|. |is_keyword| indicates // Adds a match for each result in |raw_default_history_results_| or
// whether the results correspond to the keyword provider or default provider. // |raw_keyword_history_results_| to |map|. |is_keyword| indicates
void AddHistoryResultsToMap(const HistoryResults& results, // which one of the two.
bool is_keyword, void AddRawHistoryResultsToMap(bool is_keyword,
int did_not_accept_suggestion, int did_not_accept_suggestion,
MatchMap* map); MatchMap* map);
// Adds a match for each transformed result in |results| to |map|.
void AddTransformedHistoryResultsToMap(
const SearchSuggestionParser::SuggestResults& results,
int did_not_accept_suggestion,
MatchMap* map);
// Calculates relevance scores for all |results|. // Calculates relevance scores for all |results|.
SearchSuggestionParser::SuggestResults ScoreHistoryResults( SearchSuggestionParser::SuggestResults ScoreHistoryResultsHelper(
const HistoryResults& results, const HistoryResults& results,
bool base_prevent_inline_autocomplete, bool base_prevent_inline_autocomplete,
bool input_multiple_words, bool input_multiple_words,
const base::string16& input_text, const base::string16& input_text,
bool is_keyword); bool is_keyword);
// Calculates relevance scores for |results|, adjusting for boundary
// conditions around multi-word queries. (See inline comments in function
// definition for more details.)
void ScoreHistoryResults(
const HistoryResults& results,
bool is_keyword,
SearchSuggestionParser::SuggestResults* scored_results);
// Adds matches for |results| to |map|. // Adds matches for |results| to |map|.
void AddSuggestResultsToMap( void AddSuggestResultsToMap(
const SearchSuggestionParser::SuggestResults& results, const SearchSuggestionParser::SuggestResults& results,
...@@ -321,9 +335,11 @@ class SearchProvider : public BaseSearchProvider, ...@@ -321,9 +335,11 @@ class SearchProvider : public BaseSearchProvider,
// Obtains a session token, regenerating if necessary. // Obtains a session token, regenerating if necessary.
std::string GetSessionToken(); std::string GetSessionToken();
// Answers prefetch handling - finds previously displayed answer matching the // Answers prefetch handling - finds the previously displayed answer matching
// current |input| and sets |prefetch_data_|. // the current top-scoring history result. If there is a previous answer,
void DoAnswersQuery(const AutocompleteInput& input); // returns the query data associated with it. Otherwise, returns an empty
// AnswersQueryData.
AnswersQueryData FindAnswersPrefetchData();
// The amount of time to wait before sending a new suggest request after the // The amount of time to wait before sending a new suggest request after the
// previous one. Non-const because some unittests modify this value. // previous one. Non-const because some unittests modify this value.
...@@ -345,8 +361,13 @@ class SearchProvider : public BaseSearchProvider, ...@@ -345,8 +361,13 @@ class SearchProvider : public BaseSearchProvider,
AutocompleteInput keyword_input_; AutocompleteInput keyword_input_;
// Searches in the user's history that begin with the input text. // Searches in the user's history that begin with the input text.
HistoryResults keyword_history_results_; HistoryResults raw_keyword_history_results_;
HistoryResults default_history_results_; HistoryResults raw_default_history_results_;
// Scored searches in the user's history - based on |keyword_history_results_|
// or |default_history_results_| as appropriate.
SearchSuggestionParser::SuggestResults transformed_keyword_history_results_;
SearchSuggestionParser::SuggestResults transformed_default_history_results_;
// A timer to start a query to the suggest server after the user has stopped // A timer to start a query to the suggest server after the user has stopped
// typing for long enough. // typing for long enough.
......
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