diff options
-rw-r--r-- | chrome/app/generated_resources.grd | 6 | ||||
-rw-r--r-- | chrome/browser/about_flags.cc | 7 | ||||
-rw-r--r-- | chrome/browser/autocomplete/autocomplete.cc | 4 | ||||
-rw-r--r-- | chrome/browser/autocomplete/history_quick_provider.cc | 2 | ||||
-rw-r--r-- | chrome/browser/autocomplete/history_quick_provider_unittest.cc | 86 | ||||
-rw-r--r-- | chrome/browser/history/in_memory_url_index.cc | 55 | ||||
-rw-r--r-- | chrome/browser/history/in_memory_url_index.h | 3 |
7 files changed, 85 insertions, 78 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 94d7959..b71ce10 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -4165,12 +4165,6 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_DESCRIPTION" desc="Description of the 'Disable HTML5 interactive form validation' lab."> Disable showing validation messages and preventing form submission. </message> - <message name="IDS_FLAGS_ENABLE_HISTORY_QUICK_PROVIDER" desc="Name of the 'Enable better visit history matching in the omnibox' lab."> - Enable better omnibox history matching - </message> - <message name="IDS_FLAGS_ENABLE_HISTORY_QUICK_PROVIDER_DESCRIPTION" desc="Description of the 'Enable better visit history matching in the omnibox' lab."> - Enables substring and multi-fragment matching within URLs from history. - </message> <message name="IDS_FLAGS_NEW_TAB_PAGE_4_NAME" desc="Name of the new tab page 4 lab."> Experimental new tab page </message> diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc index 312f844..504b1b4 100644 --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -254,13 +254,6 @@ const Experiment kExperiments[] = { SINGLE_VALUE_TYPE(switches::kEnableWebAudio) }, { - "enable-history-quick-provider", - IDS_FLAGS_ENABLE_HISTORY_QUICK_PROVIDER, - IDS_FLAGS_ENABLE_HISTORY_QUICK_PROVIDER_DESCRIPTION, - kOsAll, - SINGLE_VALUE_TYPE(switches::kEnableHistoryQuickProvider) - }, - { "p2papi", IDS_FLAGS_P2P_API_NAME, IDS_FLAGS_P2P_API_DESCRIPTION, diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc index 101f373..6d2c6c9 100644 --- a/chrome/browser/autocomplete/autocomplete.cc +++ b/chrome/browser/autocomplete/autocomplete.cc @@ -787,9 +787,7 @@ AutocompleteController::AutocompleteController( in_start_(false) { search_provider_ = new SearchProvider(this, profile); providers_.push_back(search_provider_); - if (CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableHistoryQuickProvider) && - !CommandLine::ForCurrentProcess()->HasSwitch( + if (!CommandLine::ForCurrentProcess()->HasSwitch( switches::kDisableHistoryQuickProvider)) providers_.push_back(new HistoryQuickProvider(this, profile)); if (!CommandLine::ForCurrentProcess()->HasSwitch( diff --git a/chrome/browser/autocomplete/history_quick_provider.cc b/chrome/browser/autocomplete/history_quick_provider.cc index 3c368185..778d345 100644 --- a/chrome/browser/autocomplete/history_quick_provider.cc +++ b/chrome/browser/autocomplete/history_quick_provider.cc @@ -177,7 +177,7 @@ int HistoryQuickProvider::CalculateRelevance(int raw_score, return 1200; default: - return 900 + static_cast<int>(match_number); + return 400 + raw_score; } } diff --git a/chrome/browser/autocomplete/history_quick_provider_unittest.cc b/chrome/browser/autocomplete/history_quick_provider_unittest.cc index 5e577b1..4ecf7f1 100644 --- a/chrome/browser/autocomplete/history_quick_provider_unittest.cc +++ b/chrome/browser/autocomplete/history_quick_provider_unittest.cc @@ -13,6 +13,7 @@ #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/autocomplete/autocomplete.h" #include "chrome/browser/autocomplete/autocomplete_match.h" #include "chrome/browser/history/history.h" #include "chrome/browser/history/in_memory_url_index.h" @@ -46,25 +47,27 @@ struct TestURLInfo { {"http://foo.com/dir/another/", "Dir", 5, 1, 0}, {"http://foo.com/dir/another/again/", "Dir", 10, 0, 0}, {"http://foo.com/dir/another/again/myfile.html", "File", 10, 2, 0}, - {"http://startest.com/y/a", "A", 5, 2, 0}, - {"http://startest.com/y/b", "B", 1, 2, 0}, - {"http://startest.com/x/c", "C", 1, 1, 1}, - {"http://startest.com/x/d", "D", 1, 1, 1}, - {"http://startest.com/y/e", "E", 1, 1, 2}, - {"http://startest.com/y/f", "F", 1, 1, 2}, - {"http://startest.com/y/g", "G", 1, 1, 4}, - {"http://startest.com/y/h", "H", 1, 1, 4}, - {"http://startest.com/y/i", "I", 1, 1, 5}, - {"http://startest.com/y/j", "J", 1, 1, 5}, - {"http://startest.com/y/k", "K", 1, 1, 6}, - {"http://startest.com/y/l", "L", 1, 1, 6}, - {"http://startest.com/y/m", "M", 1, 1, 6}, - {"http://abcdefghixyzjklmnopqrstuvw.com/a", "An XYZ", 1, 1, 0}, + {"http://visitedest.com/y/a", "VA", 5, 1, 0}, + {"http://visitedest.com/y/b", "VB", 4, 1, 0}, + {"http://visitedest.com/x/c", "VC", 3, 1, 0}, + {"http://visitedest.com/x/d", "VD", 2, 1, 0}, + {"http://visitedest.com/y/e", "VE", 1, 1, 0}, + {"http://typeredest.com/y/a", "TA", 3, 5, 0}, + {"http://typeredest.com/y/b", "TB", 3, 4, 0}, + {"http://typeredest.com/x/c", "TC", 3, 3, 0}, + {"http://typeredest.com/x/d", "TD", 3, 2, 0}, + {"http://typeredest.com/y/e", "TE", 3, 1, 0}, + {"http://daysagoest.com/y/a", "DA", 1, 1, 0}, + {"http://daysagoest.com/y/b", "DB", 1, 1, 1}, + {"http://daysagoest.com/x/c", "DC", 1, 1, 2}, + {"http://daysagoest.com/x/d", "DD", 1, 1, 3}, + {"http://daysagoest.com/y/e", "DE", 1, 1, 4}, + {"http://abcdefghixyzjklmnopqrstuvw.com/a", "", 1, 1, 0}, {"http://spaces.com/path%20with%20spaces/foo.html", "Spaces", 2, 2, 0}, - {"http://abcdefghijklxyzmnopqrstuvw.com/a", "An XYZ", 1, 1, 0}, - {"http://abcdefxyzghijklmnopqrstuvw.com/a", "An XYZ", 1, 1, 0}, - {"http://abcxyzdefghijklmnopqrstuvw.com/a", "An XYZ", 1, 1, 0}, - {"http://xyzabcdefghijklmnopqrstuvw.com/a", "An XYZ", 1, 1, 0}, + {"http://abcdefghijklxyzmnopqrstuvw.com/a", "", 1, 1, 0}, + {"http://abcdefxyzghijklmnopqrstuvw.com/a", "", 1, 1, 0}, + {"http://abcxyzdefghijklmnopqrstuvw.com/a", "", 1, 1, 0}, + {"http://xyzabcdefghijklmnopqrstuvw.com/a", "", 1, 1, 0}, {"http://cda.com/Dogs%20Cats%20Gorillas%20Sea%20Slugs%20and%20Mice", "Dogs & Cats & Mice", 1, 1, 0}, }; @@ -183,6 +186,10 @@ void HistoryQuickProviderTest::RunTest(const string16 text, EXPECT_TRUE(provider_->done()); ac_matches_ = provider_->matches(); + + // We should have gotten back at most AutocompleteProvider::kMaxMatches. + EXPECT_LE(ac_matches_.size(), AutocompleteProvider::kMaxMatches); + // If the number of expected and actual matches aren't equal then we need // test no further, but let's do anyway so that we know which URLs failed. EXPECT_EQ(expected_urls.size(), ac_matches_.size()); @@ -192,7 +199,7 @@ void HistoryQuickProviderTest::RunTest(const string16 text, std::set<std::string> leftovers = for_each(expected_urls.begin(), expected_urls.end(), SetShouldContain(ac_matches_)).LeftOvers(); - EXPECT_TRUE(leftovers.empty()); + EXPECT_EQ(0U, leftovers.size()); // See if we got the expected top scorer. if (!ac_matches_.empty()) { @@ -213,12 +220,12 @@ TEST_F(HistoryQuickProviderTest, SimpleSingleMatch) { TEST_F(HistoryQuickProviderTest, MultiMatch) { string16 text(ASCIIToUTF16("foo")); std::vector<std::string> expected_urls; + // Scores high because of completion length. expected_urls.push_back("http://foo.com/"); - expected_urls.push_back("http://foo.com/dir/"); - expected_urls.push_back("http://foo.com/dir/another/"); + // Scores high because of visit count. expected_urls.push_back("http://foo.com/dir/another/again/"); + // Scores high because of visit count but less match span. expected_urls.push_back("http://foo.com/dir/another/again/myfile.html"); - expected_urls.push_back("http://spaces.com/path%20with%20spaces/foo.html"); RunTest(text, expected_urls, "http://foo.com/"); } @@ -228,21 +235,34 @@ TEST_F(HistoryQuickProviderTest, StartRelativeMatch) { expected_urls.push_back("http://xyzabcdefghijklmnopqrstuvw.com/a"); expected_urls.push_back("http://abcxyzdefghijklmnopqrstuvw.com/a"); expected_urls.push_back("http://abcdefxyzghijklmnopqrstuvw.com/a"); - expected_urls.push_back("http://abcdefghixyzjklmnopqrstuvw.com/a"); - expected_urls.push_back("http://abcdefghijklxyzmnopqrstuvw.com/a"); RunTest(text, expected_urls, "http://xyzabcdefghijklmnopqrstuvw.com/a"); } -TEST_F(HistoryQuickProviderTest, RecencyMatch) { - string16 text(ASCIIToUTF16("startest")); +TEST_F(HistoryQuickProviderTest, VisitCountMatches) { + string16 text(ASCIIToUTF16("visitedest")); + std::vector<std::string> expected_urls; + expected_urls.push_back("http://visitedest.com/y/a"); + expected_urls.push_back("http://visitedest.com/y/b"); + expected_urls.push_back("http://visitedest.com/x/c"); + RunTest(text, expected_urls, "http://visitedest.com/y/a"); +} + +TEST_F(HistoryQuickProviderTest, TypedCountMatches) { + string16 text(ASCIIToUTF16("typeredest")); + std::vector<std::string> expected_urls; + expected_urls.push_back("http://typeredest.com/y/a"); + expected_urls.push_back("http://typeredest.com/y/b"); + expected_urls.push_back("http://typeredest.com/x/c"); + RunTest(text, expected_urls, "http://typeredest.com/y/a"); +} + +TEST_F(HistoryQuickProviderTest, DaysAgoMatches) { + string16 text(ASCIIToUTF16("daysagoest")); std::vector<std::string> expected_urls; - expected_urls.push_back("http://startest.com/y/a"); - expected_urls.push_back("http://startest.com/y/b"); - expected_urls.push_back("http://startest.com/x/c"); - expected_urls.push_back("http://startest.com/x/d"); - expected_urls.push_back("http://startest.com/y/e"); - expected_urls.push_back("http://startest.com/y/f"); - RunTest(text, expected_urls, "http://startest.com/y/a"); + expected_urls.push_back("http://daysagoest.com/y/a"); + expected_urls.push_back("http://daysagoest.com/y/b"); + expected_urls.push_back("http://daysagoest.com/x/c"); + RunTest(text, expected_urls, "http://daysagoest.com/y/a"); } TEST_F(HistoryQuickProviderTest, EncodingLimitMatch) { diff --git a/chrome/browser/history/in_memory_url_index.cc b/chrome/browser/history/in_memory_url_index.cc index 9d52aa2..67546a2 100644 --- a/chrome/browser/history/in_memory_url_index.cc +++ b/chrome/browser/history/in_memory_url_index.cc @@ -15,6 +15,7 @@ #include "base/string_util.h" #include "base/time.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/autocomplete/autocomplete.h" #include "chrome/browser/autocomplete/history_provider_util.h" #include "chrome/browser/history/url_database.h" #include "chrome/browser/profiles/profile.h" @@ -52,12 +53,12 @@ const size_t InMemoryURLIndex::kNoCachedResultForTerm = -1; const float kOrderMaxValue = 50.0; const float kStartMaxValue = 50.0; const size_t kMaxSignificantStart = 20; -const float kCompleteMaxValue = 50.0; -const float kLastVisitMaxValue = 50.0; +const float kCompleteMaxValue = 100.0; +const float kLastVisitMaxValue = 200.0; const base::TimeDelta kMaxSignificantDay = base::TimeDelta::FromDays(30); -const float kVisitCountMaxValue = 50.0; +const float kVisitCountMaxValue = 100.0; const int kMaxSignificantVisits = 20; -const float kTypedCountMaxValue = 50.0; +const float kTypedCountMaxValue = 300.0; const int kMaxSignificantTyped = 20; const float kMaxRawScore = kOrderMaxValue + kStartMaxValue + kCompleteMaxValue + kLastVisitMaxValue + kVisitCountMaxValue + kTypedCountMaxValue; @@ -74,6 +75,12 @@ ScoredHistoryMatch::ScoredHistoryMatch(const URLRow& url_info) ScoredHistoryMatch::~ScoredHistoryMatch() {} +// Comparison function for sorting ScoredMatches by their scores. +bool ScoredHistoryMatch::MatchScoreGreater(const ScoredHistoryMatch& m1, + const ScoredHistoryMatch& m2) { + return m1.raw_score >= m2.raw_score; +} + struct InMemoryURLIndex::TermCharWordSet { TermCharWordSet() // Required for STL resize(). : char_(0), @@ -95,7 +102,7 @@ struct InMemoryURLIndex::TermCharWordSet { }; // Comparison function for sorting TermMatches by their offsets. -bool CompareMatchOffset(const TermMatch& m1, const TermMatch& m2) { +bool MatchOffsetLess(const TermMatch& m1, const TermMatch& m2) { return m1.offset < m2.offset; } @@ -335,6 +342,18 @@ ScoredHistoryMatches InMemoryURLIndex::HistoryItemsForTerms( // substring match, inserting those which pass in order by score. scored_items = std::for_each(history_id_set.begin(), history_id_set.end(), AddHistoryMatch(*this, lower_terms)).ScoredMatches(); + // Select and sort only the top kMaxMatches results. + if (scored_items.size() > AutocompleteProvider::kMaxMatches) { + std::partial_sort(scored_items.begin(), + scored_items.begin() + + AutocompleteProvider::kMaxMatches, + scored_items.end(), + ScoredHistoryMatch::MatchScoreGreater); + scored_items.resize(AutocompleteProvider::kMaxMatches); + } else { + std::sort(scored_items.begin(), scored_items.end(), + ScoredHistoryMatch::MatchScoreGreater); + } } } @@ -614,7 +633,7 @@ TermMatches InMemoryURLIndex::SortAndDeoverlap(const TermMatches& matches) { return matches; TermMatches sorted_matches = matches; std::sort(sorted_matches.begin(), sorted_matches.end(), - CompareMatchOffset); + MatchOffsetLess); TermMatches clean_matches; TermMatch last_match = sorted_matches[0]; clean_matches.push_back(last_match); @@ -741,7 +760,6 @@ int InMemoryURLIndex::RawScoreForMatches(const TermMatches& matches, float complete_value = (static_cast<float>(term_length_total) / static_cast<float>(max_length)) * kStartMaxValue; - return static_cast<int>(order_value + start_value + complete_value); } @@ -764,27 +782,8 @@ void InMemoryURLIndex::AddHistoryMatch::operator()( if (hist_pos != index_.history_info_map_.end()) { const URLRow& hist_item = hist_pos->second; ScoredHistoryMatch match(ScoredMatchForURL(hist_item, lower_terms_)); - if (match.raw_score != 0) { - // We only retain the top 10 highest scoring results so - // see if this one fits into the top 10 and, if so, where. - ScoredHistoryMatches::iterator scored_iter = scored_matches_.begin(); - while (scored_iter != scored_matches_.end() && - (*scored_iter).raw_score > match.raw_score) - ++scored_iter; - if ((scored_matches_.size() < 10) || - (scored_iter != scored_matches_.end())) { - // Insert the new item. - if (!scored_matches_.empty()) - scored_matches_.insert(scored_iter, match); - else - scored_matches_.push_back(match); - // Trim any entries beyond 10. - if (scored_matches_.size() > 10) { - scored_matches_.erase(scored_matches_.begin() + 10, - scored_matches_.end()); - } - } - } + if (match.raw_score > 0) + scored_matches_.push_back(match); } } diff --git a/chrome/browser/history/in_memory_url_index.h b/chrome/browser/history/in_memory_url_index.h index 2e570cc..e50b07f 100644 --- a/chrome/browser/history/in_memory_url_index.h +++ b/chrome/browser/history/in_memory_url_index.h @@ -62,6 +62,9 @@ struct ScoredHistoryMatch : public HistoryMatch { explicit ScoredHistoryMatch(const URLRow& url_info); ~ScoredHistoryMatch(); + static bool MatchScoreGreater(const ScoredHistoryMatch& m1, + const ScoredHistoryMatch& m2); + // An interim score taking into consideration location and completeness // of the match. int raw_score; |