summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete
diff options
context:
space:
mode:
authormpearson@chromium.org <mpearson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-16 14:39:35 +0000
committermpearson@chromium.org <mpearson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-16 14:39:35 +0000
commited1e3950641ca52188ddc8c84b3628b5d7ba78e3 (patch)
treeb868658813043d43f3427d85d5b7b9e1e935ef75 /chrome/browser/autocomplete
parentba0e58006093d571ecd6465cdadd18cedc290510 (diff)
downloadchromium_src-ed1e3950641ca52188ddc8c84b3628b5d7ba78e3.zip
chromium_src-ed1e3950641ca52188ddc8c84b3628b5d7ba78e3.tar.gz
chromium_src-ed1e3950641ca52188ddc8c84b3628b5d7ba78e3.tar.bz2
Improve HistoryURL scoring by making it more aggressive.
Score the first pass (roughly) as usual. Something may become an INLINE_AUTOCOMPLETE match or an UNVISITED_INTRANET match or simply a URL_WHAT_YOU_TYPED match. All the results we add in the second pass are given decreasing scores starting with whatever the highest score we've assigned thus far. For instance, if there is an INLINE_AUTOCOMPLETE match (scores around 1410), all other history matches will have scores around 1410 (instead of the previous 900 or so). As another example, if no match qualifies as INLINE_AUTOCOMPLETE or UNVISITED_INTRANET, and the highest match we get from the first pass is the URL_WHAT_YOU_TYPED match (scores around 1210), then all history URL results if there are any will get similar scores (rather than the earlier 900). There may not be any history URL results; I imagine it's rare that history URL has results but none qualify as INLINE_AUTOCOMPLETE. This is a temporary changelist for feedback. I have not touched the unittests. BUG= TEST= Review URL: http://codereview.chromium.org/8757006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114800 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r--chrome/browser/autocomplete/autocomplete.h24
-rw-r--r--chrome/browser/autocomplete/history_url_provider.cc54
-rw-r--r--chrome/browser/autocomplete/history_url_provider.h24
3 files changed, 60 insertions, 42 deletions
diff --git a/chrome/browser/autocomplete/autocomplete.h b/chrome/browser/autocomplete/autocomplete.h
index 8c96837..cc8f52f 100644
--- a/chrome/browser/autocomplete/autocomplete.h
+++ b/chrome/browser/autocomplete/autocomplete.h
@@ -44,16 +44,16 @@
// --------------------------------------------------------------------|-----
// Keyword (non-substituting or in keyword UI mode, exact match) | 1500
// Extension App (exact match) | 1425
-// HistoryURL (exact or inline autocomplete match) | 1410
-// HistoryURL intranet url never visited | 1400
+// HistoryURL (good exact or inline autocomplete matches, some inexact)| 1410++
+// HistoryURL (intranet url never visited match, some inexact matches) | 1400++
// Search Primary Provider (past query in history within 2 days) | 1399**
// Search Primary Provider (what you typed) | 1300
-// HistoryURL (what you typed) | 1200
+// HistoryURL (what you typed, some inexact matches) | 1200++
// Extension App (inexact match) | 1175*~
// Keyword (substituting, exact match) | 1100
// Search Primary Provider (past query in history older than 2 days) | 1050--
// HistoryContents (any match in title of starred page) | 1000++
-// HistoryURL (inexact match) | 900++
+// HistoryURL (some inexact matches) | 900++
// Search Primary Provider (navigational suggestion) | 800++
// HistoryContents (any match in title of nonstarred page) | 700++
// Search Primary Provider (suggestion) | 600++
@@ -70,16 +70,16 @@
// --------------------------------------------------------------------|-----
// Keyword (non-substituting or in keyword UI mode, exact match) | 1500
// Extension App (exact match) | 1425
-// HistoryURL (exact or inline autocomplete match) | 1410
-// HistoryURL intranet url never visited | 1400
+// HistoryURL (good exact or inline autocomplete matches, some inexact)| 1410++
+// HistoryURL (intranet url never visited match, some inexact matches) | 1400++
// Search Primary Provider (past query in history within 2 days) | 1399**
-// HistoryURL (what you typed) | 1200
+// HistoryURL (what you typed, some inexact matches) | 1200++
// Extension App (inexact match) | 1175*~
// Search Primary Provider (what you typed) | 1150
// Keyword (substituting, exact match) | 1100
// Search Primary Provider (past query in history older than 2 days) | 1050--
// HistoryContents (any match in title of starred page) | 1000++
-// HistoryURL (inexact match) | 900++
+// HistoryURL (some inexact matches) | 900++
// Search Primary Provider (navigational suggestion) | 800++
// HistoryContents (any match in title of nonstarred page) | 700++
// Search Primary Provider (suggestion) | 600++
@@ -96,12 +96,12 @@
// --------------------------------------------------------------------|-----
// Keyword (non-substituting or in keyword UI mode, exact match) | 1500
// Extension App (exact match) | 1425
-// HistoryURL (exact or inline autocomplete match) | 1410
-// HistoryURL intranet url never visited | 1400
-// HistoryURL (what you typed) | 1200
+// HistoryURL (good exact or inline autocomplete matches, some inexact)| 1410++
+// HistoryURL (intranet url never visited match, some inexact matches) | 1400++
+// HistoryURL (what you typed, some inexact matches) | 1200++
// Extension App (inexact match) | 1175*~
// Keyword (substituting, exact match) | 1100
-// HistoryURL (inexact match) | 900++
+// HistoryURL (some inexact matches) | 900++
// Search Primary Provider (what you typed) | 850
// Search Primary Provider (navigational suggestion) | 800++
// Search Primary Provider (past query in history) | 750--
diff --git a/chrome/browser/autocomplete/history_url_provider.cc b/chrome/browser/autocomplete/history_url_provider.cc
index 692587b..d272965 100644
--- a/chrome/browser/autocomplete/history_url_provider.cc
+++ b/chrome/browser/autocomplete/history_url_provider.cc
@@ -8,6 +8,7 @@
#include "base/basictypes.h"
#include "base/bind.h"
+#include "base/command_line.h"
#include "base/message_loop.h"
#include "base/metrics/histogram.h"
#include "base/string_util.h"
@@ -20,6 +21,7 @@
#include "chrome/browser/net/url_fixer_upper.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "googleurl/src/gurl.h"
@@ -311,7 +313,9 @@ HistoryURLProvider::HistoryURLProvider(ACProviderListener* listener,
Profile* profile)
: HistoryProvider(listener, profile, "HistoryURL"),
prefixes_(GetPrefixes()),
- params_(NULL) {
+ params_(NULL),
+ enable_aggressive_scoring_(CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableOmniboxAggressiveHistoryURL)) {
}
void HistoryURLProvider::Start(const AutocompleteInput& input,
@@ -448,6 +452,13 @@ void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend,
if (!backend)
return;
+ // Determine relevancy of highest scoring match, if any.
+ int relevance = -1;
+ for (ACMatches::const_iterator it = params->matches.begin();
+ it != params->matches.end(); ++it) {
+ relevance = std::max(relevance, it->relevance);
+ }
+
// Remove redirects and trim list to size. We want to provide up to
// kMaxMatches results plus the What You Typed result, if it was added to
// |history_matches| above.
@@ -459,9 +470,13 @@ void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend,
DCHECK(!have_what_you_typed_match ||
(match.url_info.url() !=
GURL(params->matches.front().destination_url)));
- AutocompleteMatch ac_match =
- HistoryMatchToACMatch(params, match, history_matches, NORMAL,
- history_matches.size() - 1 - i);
+ // With aggressive scoring, we assume that the results are all of similar
+ // quality, so we give them consecutively decreasing scores.
+ relevance = (enable_aggressive_scoring_ && (relevance > 0)) ?
+ (relevance - 1) :
+ CalculateRelevance(NORMAL, history_matches.size() - 1 - i);
+ AutocompleteMatch ac_match = HistoryMatchToACMatch(params, match,
+ NORMAL, relevance);
params->matches.push_back(ac_match);
}
}
@@ -519,21 +534,21 @@ history::Prefixes HistoryURLProvider::GetPrefixes() {
return prefixes;
}
-// static
-int HistoryURLProvider::CalculateRelevance(AutocompleteInput::Type input_type,
- MatchType match_type,
- size_t match_number) {
+int HistoryURLProvider::CalculateRelevance(MatchType match_type,
+ size_t match_number) const {
+ int shift = enable_aggressive_scoring_ ? kMaxMatches : 0;
+
switch (match_type) {
case INLINE_AUTOCOMPLETE:
- return 1410;
+ return 1410 + shift;
case UNVISITED_INTRANET:
- return 1400;
+ return 1400 + shift;
case WHAT_YOU_TYPED:
- return 1200;
+ return 1200 + shift;
- default:
+ default: // NORMAL
return 900 + static_cast<int>(match_number);
}
}
@@ -636,8 +651,7 @@ const history::Prefix* HistoryURLProvider::BestPrefix(
AutocompleteMatch HistoryURLProvider::SuggestExactInput(
const AutocompleteInput& input,
bool trim_http) {
- AutocompleteMatch match(this,
- CalculateRelevance(input.type(), WHAT_YOU_TYPED, 0), false,
+ AutocompleteMatch match(this, CalculateRelevance(WHAT_YOU_TYPED, 0), false,
AutocompleteMatch::URL_WHAT_YOU_TYPED);
const GURL& url = input.canonicalized_url();
@@ -721,7 +735,7 @@ bool HistoryURLProvider::FixupExactSuggestion(
break;
}
- match->relevance = CalculateRelevance(input.type(), type, 0);
+ match->relevance = CalculateRelevance(type, 0);
if (type == UNVISITED_INTRANET && !matches->empty()) {
// If there are any other matches, then don't promote this match here, in
@@ -777,8 +791,8 @@ bool HistoryURLProvider::PromoteMatchForInlineAutocomplete(
// there's no way to know about "foo/", make reaching this point prevent any
// future pass from suggesting the exact input as a better match.
params->dont_suggest_exact_input = true;
- params->matches.push_back(HistoryMatchToACMatch(params, match, matches,
- INLINE_AUTOCOMPLETE, 0));
+ params->matches.push_back(HistoryMatchToACMatch(params, match,
+ INLINE_AUTOCOMPLETE, CalculateRelevance(INLINE_AUTOCOMPLETE, 0)));
return true;
}
@@ -889,12 +903,10 @@ size_t HistoryURLProvider::RemoveSubsequentMatchesOf(
AutocompleteMatch HistoryURLProvider::HistoryMatchToACMatch(
HistoryURLProviderParams* params,
const history::HistoryMatch& history_match,
- const history::HistoryMatches& history_matches,
MatchType match_type,
- size_t match_number) {
+ int relevance) {
const history::URLRow& info = history_match.url_info;
- AutocompleteMatch match(this,
- CalculateRelevance(params->input.type(), match_type, match_number),
+ AutocompleteMatch match(this, relevance,
!!info.visit_count(), AutocompleteMatch::HISTORY_URL);
match.destination_url = info.url();
DCHECK(match.destination_url.is_valid());
diff --git a/chrome/browser/autocomplete/history_url_provider.h b/chrome/browser/autocomplete/history_url_provider.h
index 2fa6e77..c7a1a4f 100644
--- a/chrome/browser/autocomplete/history_url_provider.h
+++ b/chrome/browser/autocomplete/history_url_provider.h
@@ -146,6 +146,7 @@ class HistoryURLProvider : public HistoryProvider {
: HistoryProvider(listener, profile, "History"),
prefixes_(GetPrefixes()),
params_(NULL),
+ enable_aggressive_scoring_(false),
languages_(languages) {}
#endif
@@ -187,13 +188,15 @@ class HistoryURLProvider : public HistoryProvider {
// Returns the set of prefixes to use for prefixes_.
static history::Prefixes GetPrefixes();
- // Determines the relevance for some input, given its type and which match it
- // is. If |match_type| is NORMAL, |match_number| is a number
- // [0, kMaxSuggestions) indicating the relevance of the match (higher == more
- // relevant). For other values of |match_type|, |match_number| is ignored.
- static int CalculateRelevance(AutocompleteInput::Type input_type,
- MatchType match_type,
- size_t match_number);
+ // Determines the relevance for a match, given its type. Behavior
+ // depends on enable_aggressive_scoring_. If |match_type| is
+ // NORMAL, |match_number| is a number [0, kMaxSuggestions)
+ // indicating the relevance of the match (higher == more relevant).
+ // For other values of |match_type|, |match_number| is ignored.
+ // Only called some of the time; for some matches, relevancy scores
+ // are assigned consecutively decreasing (1416, 1415, 1414, ...).
+ int CalculateRelevance(MatchType match_type,
+ size_t match_number) const;
// Helper function that actually launches the two autocomplete passes.
void RunAutocompletePasses(const AutocompleteInput& input,
@@ -267,9 +270,8 @@ class HistoryURLProvider : public HistoryProvider {
AutocompleteMatch HistoryMatchToACMatch(
HistoryURLProviderParams* params,
const history::HistoryMatch& history_match,
- const history::HistoryMatches& history_matches,
MatchType match_type,
- size_t match_number);
+ int relevance);
// Prefixes to try appending to user input when looking for a match.
const history::Prefixes prefixes_;
@@ -280,6 +282,10 @@ class HistoryURLProvider : public HistoryProvider {
// keep this member is so we can set the cancel bit on it.
HistoryURLProviderParams* params_;
+ // Command line flag omnibox-aggressive-with-history-urls.
+ // We examine and cache the value in the constructor.
+ bool enable_aggressive_scoring_;
+
// Only used by unittests; if non-empty, overrides accept-languages in the
// profile's pref system.
std::string languages_;