Commit 7e3b77f5 authored by mpearson@chromium.org's avatar mpearson@chromium.org

Omnibox: Don't Call Classify() Repeatedly

Tested:
* Search for "qrty.com" repeatedly.  Verify that when you type "q", a search for "qrty.com" does not get inline autocompleted.  This is the same as the behavior before this changelist.  Without the Classify() code, this suppression of the inline autocompletion does not happen.
* Check speed.  Search for "testing 1", "testing 2", ... "testing 13", ...  i.e., create a lot of searches starting with "t".  Restart browser.  Open seven blank new tabs and two separate tabs of about:histograms.  In each blank tab, type "t"; don't hit return.  Reload one of the histograms tabs.  Compare the Omnibox.ProviderTime.Search histogram in the  non-reloaded histograms tab with the reloaded histograms tab.
  - in current chrome (before this patch), I see a difference in the laggy section of the histogram.  In my testing, I see 7 new entries in the 129-204ms bucket.  Ugh.
  - in chrome built with this patch, I see a difference in the 13-21ms bucket; no different in higher buckets.

BUG=393956, 262263

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285456 0039d316-1c4b-4281-b951-d872f2087c98
parent f5a2563d
......@@ -891,8 +891,6 @@ SearchProvider::SuggestResults SearchProvider::ScoreHistoryResults(
bool input_multiple_words,
const base::string16& input_text,
bool is_keyword) {
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;
......@@ -912,28 +910,6 @@ SearchProvider::SuggestResults SearchProvider::ScoreHistoryResults(
(!input_multiple_words && (i->visits < 2) &&
HasMultipleWords(trimmed_suggestion));
// Don't autocomplete search terms that would normally be treated as URLs
// when typed. For example, if the user searched for "google.com" and types
// "goog", don't autocomplete to the search term "google.com". Otherwise,
// the input will look like a URL but act like a search, which is confusing.
// NOTE: We don't check this in the following cases:
// * When inline autocomplete is disabled, we won't be inline
// autocompleting this term, so we don't need to worry about confusion as
// much. This also prevents calling Classify() again from inside the
// classifier (which will corrupt state and likely crash), since the
// classifier always disables inline autocomplete.
// * When the user has typed the whole term, the "what you typed" history
// match will outrank us for URL-like inputs anyway, so we need not do
// anything special.
if (!prevent_inline_autocomplete && classifier &&
(trimmed_suggestion != trimmed_input)) {
AutocompleteMatch match;
classifier->Classify(trimmed_suggestion, false, false,
input_.current_page_classification(), &match, NULL);
prevent_inline_autocomplete =
!AutocompleteMatch::IsSearchType(match.type);
}
int relevance = CalculateRelevanceForHistory(
i->time, is_keyword, !prevent_inline_autocomplete,
prevent_search_history_inlining);
......@@ -962,10 +938,55 @@ SearchProvider::SuggestResults SearchProvider::ScoreHistoryResults(
(found_what_you_typed_match ? 1 : 0),
scored_results.end(),
CompareScoredResults());
// Don't autocomplete to search terms that would normally be treated as URLs
// when typed. For example, if the user searched for "google.com" and types
// "goog", don't autocomplete to the search term "google.com". Otherwise,
// the input will look like a URL but act like a search, which is confusing.
// The 1200 relevance score threshold in the test below is the lowest
// possible score in CalculateRelevanceForHistory()'s aggressive-scoring
// curve. This is an appropriate threshold to use to decide if we're overly
// aggressively inlining because, if we decide the answer is yes, the
// way we resolve it it to not use the aggressive-scoring curve.
// NOTE: We don't check for autocompleting to URLs in the following cases:
// * When inline autocomplete is disabled, we won't be inline autocompleting
// this term, so we don't need to worry about confusion as much. This
// also prevents calling Classify() again from inside the classifier
// (which will corrupt state and likely crash), since the classifier
// always disables inline autocomplete.
// * When the user has typed the whole string before as a query, then it's
// likely the user has no expectation that term should be interpreted as
// as a URL, so we need not do anything special to preserve user
// expectation.
AutocompleteClassifier* classifier =
AutocompleteClassifierFactory::GetForProfile(profile_);
int last_relevance = 0;
if (!base_prevent_inline_autocomplete && !found_what_you_typed_match &&
classifier && (scored_results.front().relevance() >= 1200)) {
AutocompleteMatch match;
classifier->Classify(scored_results.front().suggestion(), false, false,
input_.current_page_classification(), &match, NULL);
// Demote this match that would normally be interpreted as a URL to have
// the highest score a previously-issued search query could have when
// scoring with the non-aggressive method. A consequence of demoting
// by revising |last_relevance| is that this match and all following
// matches get demoted; the relative order of matches is preserved.
// One could imagine demoting only those matches that might cause
// confusion (which, by the way, might change the relative order of
// matches. We have decided to go with the simple demote-all approach
// because selective demotion requires multiple Classify() calls and
// such calls can be expensive (as expensive as running the whole
// autocomplete system).
if (!AutocompleteMatch::IsSearchType(match.type)) {
last_relevance = CalculateRelevanceForHistory(
base::Time::Now(), is_keyword, false,
prevent_search_history_inlining);
}
}
for (SuggestResults::iterator i(scored_results.begin());
i != scored_results.end(); ++i) {
if ((i != scored_results.begin()) && (i->relevance() >= last_relevance))
if ((last_relevance != 0) && (i->relevance() >= last_relevance))
i->set_relevance(last_relevance - 1);
last_relevance = i->relevance();
}
......
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