Commit ab5fd2fd authored by mpearson@chromium.org's avatar mpearson@chromium.org

Omnibox: Don't Autocomplete Previously-Issued Search Queries

If I type an exact query that I issued before, SearchProvider shouldn't
offer an extension to the autocompletion, even if that I issued that longer
query more recently.  This is counter to user's expectations: if I issued
the query before and type it again and hit enter, I should get that query.

I do not plan to bother running an experiment for this change.

BUG=246411

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283836 0039d316-1c4b-4281-b951-d872f2087c98
parent ced4e7a9
......@@ -894,6 +894,8 @@ SearchProvider::SuggestResults SearchProvider::ScoreHistoryResults(
AutocompleteClassifier* classifier =
AutocompleteClassifierFactory::GetForProfile(profile_);
SuggestResults scored_results;
// True if the user has asked this exact query previously.
bool found_what_you_typed_match = false;
const bool prevent_search_history_inlining =
OmniboxFieldTrial::SearchHistoryPreventInlining(
input_.current_page_classification());
......@@ -935,7 +937,15 @@ SearchProvider::SuggestResults SearchProvider::ScoreHistoryResults(
int relevance = CalculateRelevanceForHistory(
i->time, is_keyword, !prevent_inline_autocomplete,
prevent_search_history_inlining);
scored_results.push_back(SuggestResult(
// Add the match to |scored_results| by putting the what-you-typed match
// on the front and appending all other matches. We want the what-you-
// typed match to always be first.
SuggestResults::iterator insertion_position = scored_results.end();
if (trimmed_suggestion == trimmed_input) {
found_what_you_typed_match = true;
insertion_position = scored_results.begin();
}
scored_results.insert(insertion_position, SuggestResult(
trimmed_suggestion, AutocompleteMatchType::SEARCH_HISTORY,
trimmed_suggestion, base::string16(), base::string16(),
base::string16(), base::string16(), std::string(), std::string(),
......@@ -943,11 +953,14 @@ SearchProvider::SuggestResults SearchProvider::ScoreHistoryResults(
}
// History returns results sorted for us. However, we may have docked some
// results' scores, so things are no longer in order. Do a stable sort to get
// results' scores, so things are no longer in order. While keeping the
// what-you-typed match at the front (if it exists), do a stable sort to get
// things back in order without otherwise disturbing results with equal
// scores, then force the scores to be unique, so that the order in which
// they're shown is deterministic.
std::stable_sort(scored_results.begin(), scored_results.end(),
std::stable_sort(scored_results.begin() +
(found_what_you_typed_match ? 1 : 0),
scored_results.end(),
CompareScoredResults());
int last_relevance = 0;
for (SuggestResults::iterator i(scored_results.begin());
......
......@@ -818,35 +818,58 @@ TEST_F(SearchProviderTest, ScoreNewerSearchesHigher) {
}
// An autocompleted multiword search should not be replaced by a different
// autocompletion while the user is still typing a valid prefix.
// autocompletion while the user is still typing a valid prefix unless the
// user has typed the prefix as a query before.
TEST_F(SearchProviderTest, DontReplacePreviousAutocompletion) {
GURL term_url_a(AddSearchToHistory(default_t_url_,
ASCIIToUTF16("four searches aaa"), 2));
ASCIIToUTF16("four searches aaa"), 3));
GURL term_url_b(AddSearchToHistory(default_t_url_,
ASCIIToUTF16("four searches bbb"), 1));
GURL term_url_c(AddSearchToHistory(default_t_url_,
ASCIIToUTF16("four searches"), 1));
profile_.BlockUntilHistoryProcessesPendingRequests();
AutocompleteMatch wyt_match;
ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("fo"),
&wyt_match));
ASSERT_EQ(3u, provider_->matches().size());
ASSERT_EQ(4u, provider_->matches().size());
AutocompleteMatch term_match_a;
EXPECT_TRUE(FindMatchWithDestination(term_url_a, &term_match_a));
AutocompleteMatch term_match_b;
EXPECT_TRUE(FindMatchWithDestination(term_url_b, &term_match_b));
AutocompleteMatch term_match_c;
EXPECT_TRUE(FindMatchWithDestination(term_url_c, &term_match_c));
EXPECT_GT(term_match_a.relevance, wyt_match.relevance);
// We don't care about the relative order of b and c.
EXPECT_GT(wyt_match.relevance, term_match_b.relevance);
EXPECT_GT(wyt_match.relevance, term_match_c.relevance);
EXPECT_TRUE(term_match_a.allowed_to_be_default_match);
EXPECT_TRUE(term_match_b.allowed_to_be_default_match);
EXPECT_TRUE(term_match_c.allowed_to_be_default_match);
EXPECT_TRUE(wyt_match.allowed_to_be_default_match);
ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("four se"),
&wyt_match));
ASSERT_EQ(3u, provider_->matches().size());
ASSERT_EQ(4u, provider_->matches().size());
EXPECT_TRUE(FindMatchWithDestination(term_url_a, &term_match_a));
EXPECT_TRUE(FindMatchWithDestination(term_url_b, &term_match_b));
EXPECT_TRUE(FindMatchWithDestination(term_url_c, &term_match_c));
EXPECT_GT(term_match_a.relevance, wyt_match.relevance);
EXPECT_GT(wyt_match.relevance, term_match_b.relevance);
EXPECT_GT(wyt_match.relevance, term_match_c.relevance);
EXPECT_TRUE(term_match_a.allowed_to_be_default_match);
EXPECT_TRUE(term_match_b.allowed_to_be_default_match);
EXPECT_TRUE(term_match_c.allowed_to_be_default_match);
EXPECT_TRUE(wyt_match.allowed_to_be_default_match);
// For the exact previously-issued query, the what-you-typed match should win.
ASSERT_NO_FATAL_FAILURE(
QueryForInputAndSetWYTMatch(ASCIIToUTF16("four searches"), &wyt_match));
ASSERT_EQ(3u, provider_->matches().size());
EXPECT_TRUE(FindMatchWithDestination(term_url_a, &term_match_a));
EXPECT_TRUE(FindMatchWithDestination(term_url_b, &term_match_b));
EXPECT_GT(wyt_match.relevance, term_match_a.relevance);
EXPECT_GT(wyt_match.relevance, term_match_b.relevance);
EXPECT_TRUE(term_match_a.allowed_to_be_default_match);
EXPECT_TRUE(term_match_b.allowed_to_be_default_match);
EXPECT_TRUE(wyt_match.allowed_to_be_default_match);
......
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