diff options
author | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-06 06:13:52 +0000 |
---|---|---|
committer | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-06 06:13:52 +0000 |
commit | 382a064036206876b25fdd9052fe073721bebbb5 (patch) | |
tree | 1b4ab515727bde72960e9d644cfe42056f15fcf0 | |
parent | 7f7dfdd479fea677669311cbc918236c1173b32d (diff) | |
download | chromium_src-382a064036206876b25fdd9052fe073721bebbb5.zip chromium_src-382a064036206876b25fdd9052fe073721bebbb5.tar.gz chromium_src-382a064036206876b25fdd9052fe073721bebbb5.tar.bz2 |
Enforce a minimum score for the top SearchProvider match.
Disregard suggested verbatimrelevance if top score < SWYT.
SWYT: the classically calculated verbatim relevance.
Update SearchProviderTest.SuggestRelevanceExperiment.
Rename CalculateRelevanceForVerbatim, add GetVerbatimRelevance.
BUG=125871
TEST=SearchProviderTest.SuggestRelevanceExperiment; manual.
Review URL: https://chromiumcodereview.appspot.com/10544017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140713 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/autocomplete/search_provider.cc | 34 | ||||
-rw-r--r-- | chrome/browser/autocomplete/search_provider.h | 8 | ||||
-rw-r--r-- | chrome/browser/autocomplete/search_provider_unittest.cc | 158 |
3 files changed, 128 insertions, 72 deletions
diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc index d9d5529..1a1ca34 100644 --- a/chrome/browser/autocomplete/search_provider.cc +++ b/chrome/browser/autocomplete/search_provider.cc @@ -162,8 +162,7 @@ void SearchProvider::FinalizeInstantQuery(const string16& input_text, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE : TemplateURLRef::NO_SUGGESTION_CHOSEN; MatchMap match_map; - AddMatchToMap(text, adjusted_input_text, - CalculateRelevanceForWhatYouTyped() + 1, + AddMatchToMap(text, adjusted_input_text, GetVerbatimRelevance() + 1, AutocompleteMatch::SEARCH_SUGGEST, did_not_accept_default_suggestion, false, &match_map); if (!match_map.empty()) { @@ -699,7 +698,7 @@ void SearchProvider::ConvertResultsToAutocompleteMatches() { TemplateURLRef::NO_SUGGESTION_CHOSEN; // Keyword what you typed results are handled by the KeywordProvider. - int verbatim_relevance = CalculateRelevanceForWhatYouTyped(); + int verbatim_relevance = GetVerbatimRelevance(); int did_not_accept_default_suggestion = default_suggest_results_.empty() ? TemplateURLRef::NO_SUGGESTIONS_AVAILABLE : TemplateURLRef::NO_SUGGESTION_CHOSEN; @@ -740,15 +739,27 @@ void SearchProvider::ConvertResultsToAutocompleteMatches() { if (matches_.size() > max_total_matches) matches_.erase(matches_.begin() + max_total_matches, matches_.end()); - // The top result must be inlinable; apply calculated scores if it is not. + // Check constraints that may be violated by suggested relevances. if (!matches_.empty() && (has_suggested_relevance_ || verbatim_relevance_ >= 0) && (matches_.front().type == AutocompleteMatch::SEARCH_SUGGEST || - matches_.front().type == AutocompleteMatch::NAVSUGGEST) && - matches_.front().inline_autocomplete_offset == string16::npos && - matches_.front().fill_into_edit != input_.text()) { - ApplyCalculatedRelevance(); - ConvertResultsToAutocompleteMatches(); + matches_.front().type == AutocompleteMatch::NAVSUGGEST)) { + bool reconstruct_matches = false; + if (matches_.front().inline_autocomplete_offset == string16::npos && + matches_.front().fill_into_edit != input_.text()) { + // Disregard all suggested relevances if the top result is not inlinable. + ApplyCalculatedRelevance(); + reconstruct_matches = true; + } else if (matches_.front().relevance < CalculateRelevanceForVerbatim()) { + // Disregard the suggested verbatim relevance if the top score is + // potentially lower than other providers' non-inlinable suggestions. + verbatim_relevance_ = -1; + reconstruct_matches = true; + } + if (reconstruct_matches) { + ConvertResultsToAutocompleteMatches(); + return; + } } UpdateStarredStateOfMatches(); @@ -878,10 +889,13 @@ void SearchProvider::AddSuggestResultsToMap(const SuggestResults& results, } } -int SearchProvider::CalculateRelevanceForWhatYouTyped() const { +int SearchProvider::GetVerbatimRelevance() const { if (verbatim_relevance_ >= 0 && !input_.prevent_inline_autocomplete()) return verbatim_relevance_; + return CalculateRelevanceForVerbatim(); +} +int SearchProvider::CalculateRelevanceForVerbatim() const { if (!providers_.keyword_provider().empty()) return 250; diff --git a/chrome/browser/autocomplete/search_provider.h b/chrome/browser/autocomplete/search_provider.h index 6fcabee..025aed6 100644 --- a/chrome/browser/autocomplete/search_provider.h +++ b/chrome/browser/autocomplete/search_provider.h @@ -280,9 +280,11 @@ class SearchProvider : public AutocompleteProvider, bool is_keyword, MatchMap* map); - // Determines the relevance for a particular match. We use different scoring - // algorithms for the different types of matches. - int CalculateRelevanceForWhatYouTyped() const; + // Get the relevance score for the verbatim result; this value may be provided + // by the suggest server; otherwise it is calculated locally. + int GetVerbatimRelevance() const; + // Calculate the relevance score for the verbatim result. + int CalculateRelevanceForVerbatim() const; // |time| is the time at which this query was last seen. |is_keyword| // indicates whether the results correspond to the keyword provider or default // provider. |prevent_inline_autocomplete| is true if we should not inline diff --git a/chrome/browser/autocomplete/search_provider_unittest.cc b/chrome/browser/autocomplete/search_provider_unittest.cc index 2842f97..5b702d5 100644 --- a/chrome/browser/autocomplete/search_provider_unittest.cc +++ b/chrome/browser/autocomplete/search_provider_unittest.cc @@ -720,99 +720,137 @@ TEST_F(SearchProviderTest, SuggestRelevance) { TEST_F(SearchProviderTest, SuggestRelevanceExperiment) { const std::string kNotApplicable("Not Applicable"); struct { - const std::string input; const std::string json; const std::string matches[4]; } cases[] = { // Ensure that suggestrelevance scores reorder matches. - { "a", "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]", + { "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]", { "a", "c", "b", kNotApplicable } }, - { "a", "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[]," - "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," - "\"google:suggestrelevance\":[1, 2]}]", + { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[]," + "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," + "\"google:suggestrelevance\":[1, 2]}]", { "a", "c.com", kNotApplicable, kNotApplicable } }, // Ensure that verbatimrelevance scores reorder or suppress what-you-typed. // Negative values will have no effect; the calculated value will be used. - { "a", "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":1}]", + { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999," + "\"google:suggestrelevance\":[9998]}]", + { "a", "a1", kNotApplicable, kNotApplicable } }, + { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998," + "\"google:suggestrelevance\":[9999]}]", { "a1", "a", kNotApplicable, kNotApplicable } }, - { "a", "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]", + { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0," + "\"google:suggestrelevance\":[9999]}]", { "a1", kNotApplicable, kNotApplicable, kNotApplicable } }, - { "a", "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1}]", - { "a", "a1", kNotApplicable, kNotApplicable } }, - { "a", "[\"a\",[\"http://a.com\"],[],[]," - "{\"google:suggesttype\":[\"NAVIGATION\"]," - "\"google:verbatimrelevance\":1}]", + { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1," + "\"google:suggestrelevance\":[9999]}]", + { "a1", "a", kNotApplicable, kNotApplicable } }, + { "[\"a\",[\"http://a.com\"],[],[]," + "{\"google:suggesttype\":[\"NAVIGATION\"]," + "\"google:verbatimrelevance\":9999," + "\"google:suggestrelevance\":[9998]}]", + { "a", "a.com", kNotApplicable, kNotApplicable } }, + { "[\"a\",[\"http://a.com\"],[],[]," + "{\"google:suggesttype\":[\"NAVIGATION\"]," + "\"google:verbatimrelevance\":9998," + "\"google:suggestrelevance\":[9999]}]", { "a.com", "a", kNotApplicable, kNotApplicable } }, - { "a", "[\"a\",[\"http://a.com\"],[],[]," - "{\"google:suggesttype\":[\"NAVIGATION\"]," - "\"google:verbatimrelevance\":0}]", + { "[\"a\",[\"http://a.com\"],[],[]," + "{\"google:suggesttype\":[\"NAVIGATION\"]," + "\"google:verbatimrelevance\":0," + "\"google:suggestrelevance\":[9999]}]", { "a.com", kNotApplicable, kNotApplicable, kNotApplicable } }, - { "a", "[\"a\",[\"http://a.com\"],[],[]," - "{\"google:suggesttype\":[\"NAVIGATION\"]," - "\"google:verbatimrelevance\":-1}]", - { "a", "a.com", kNotApplicable, kNotApplicable } }, + { "[\"a\",[\"http://a.com\"],[],[]," + "{\"google:suggesttype\":[\"NAVIGATION\"]," + "\"google:verbatimrelevance\":-1," + "\"google:suggestrelevance\":[9999]}]", + { "a.com", "a", kNotApplicable, kNotApplicable } }, // Ensure that both types of relevance scores reorder matches together. - { "a", "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[3, 1]," - "\"google:verbatimrelevance\":2}]", + { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997]," + "\"google:verbatimrelevance\":9998}]", { "a1", "a", "a2", kNotApplicable } }, // Ensure that only inlinable matches may be ranked as the highest result. - // If the server suggests relevance scores that violate this constraint, - // then all other matches are ranked lower than the what-you-typed result. - { "a", "[\"a\",[\"b\"],[],[],{\"google:verbatimrelevance\":0}]", - { "a", "b", kNotApplicable, kNotApplicable } }, - { "a", "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]", + // Ignore all suggested relevance scores if this constraint is violated. + { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]", { "a", "b", kNotApplicable, kNotApplicable } }, - { "a", "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]," - "\"google:verbatimrelevance\":0}]", + { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]," + "\"google:verbatimrelevance\":0}]", { "a", "b", kNotApplicable, kNotApplicable } }, - { "a", "[\"a\",[\"http://b.com\"],[],[]," - "{\"google:suggesttype\":[\"NAVIGATION\"]," - "\"google:verbatimrelevance\":0}]", + { "[\"a\",[\"http://b.com\"],[],[]," + "{\"google:suggesttype\":[\"NAVIGATION\"]," + "\"google:suggestrelevance\":[9999]}]", { "a", "b.com", kNotApplicable, kNotApplicable } }, - { "a", "[\"a\",[\"http://b.com\"],[],[]," - "{\"google:suggesttype\":[\"NAVIGATION\"]," - "\"google:suggestrelevance\":[9999]}]", - { "a", "b.com", kNotApplicable, kNotApplicable } }, - { "a", "[\"a\",[\"http://b.com\"],[],[]," - "{\"google:suggesttype\":[\"NAVIGATION\"]," - "\"google:suggestrelevance\":[9999]," - "\"google:verbatimrelevance\":0}]", + { "[\"a\",[\"http://b.com\"],[],[]," + "{\"google:suggesttype\":[\"NAVIGATION\"]," + "\"google:suggestrelevance\":[9999]," + "\"google:verbatimrelevance\":0}]", { "a", "b.com", kNotApplicable, kNotApplicable } }, + // Ensure that the top result is ranked as highly as calculated verbatim. + // Ignore the suggested verbatim relevance if this constraint is violated. + { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]", + { "a", "a1", kNotApplicable, kNotApplicable } }, + { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":1}]", + { "a", "a1", kNotApplicable, kNotApplicable } }, + { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[1]," + "\"google:verbatimrelevance\":0}]", + { "a", "a1", kNotApplicable, kNotApplicable } }, + { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2]," + "\"google:verbatimrelevance\":0}]", + { "a", "a2", "a1", kNotApplicable } }, + { "[\"a\",[\"http://a.com\"],[],[]," + "{\"google:suggesttype\":[\"NAVIGATION\"]," + "\"google:suggestrelevance\":[1]," + "\"google:verbatimrelevance\":0}]", + { "a", "a.com", kNotApplicable, kNotApplicable } }, + { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," + "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," + "\"google:suggestrelevance\":[1, 2]," + "\"google:verbatimrelevance\":0}]", + { "a", "a2.com", kNotApplicable, kNotApplicable } }, + // Ensure that all suggestions are considered, regardless of order. - { "a", "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[]," - "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", + { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[]," + "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", { "a", "h", "g", "f" } }, - { "a", "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\"," - "\"http://e.com\", \"http://f.com\", \"http://g.com\"," - "\"http://h.com\"],[],[]," - "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"," - "\"NAVIGATION\", \"NAVIGATION\"," - "\"NAVIGATION\", \"NAVIGATION\"," - "\"NAVIGATION\"]," - "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", + { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\"," + "\"http://e.com\", \"http://f.com\", \"http://g.com\"," + "\"http://h.com\"],[],[]," + "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"," + "\"NAVIGATION\", \"NAVIGATION\"," + "\"NAVIGATION\", \"NAVIGATION\"," + "\"NAVIGATION\"]," + "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", { "a", "h.com", kNotApplicable, kNotApplicable } }, // Ensure that incorrectly sized suggestion relevance lists are ignored. - { "a", "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]", + { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]", { "a", "a1", "a2", kNotApplicable } }, - { "a", "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]", + { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]", { "a", "a1", kNotApplicable, kNotApplicable } }, - { "a", "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," - "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," - "\"google:suggestrelevance\":[1]}]", + { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," + "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," + "\"google:suggestrelevance\":[1]}]", { "a", "a1.com", kNotApplicable, kNotApplicable } }, - { "a", "[\"a\",[\"http://a1.com\"],[],[]," - "{\"google:suggesttype\":[\"NAVIGATION\"]," - "\"google:suggestrelevance\":[9999, 1]}]", + { "[\"a\",[\"http://a1.com\"],[],[]," + "{\"google:suggesttype\":[\"NAVIGATION\"]," + "\"google:suggestrelevance\":[9999, 1]}]", { "a", "a1.com", kNotApplicable, kNotApplicable } }, + + // Ensure that all 'verbatim' results are merged with their maximum score. + { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," + "{\"google:suggestrelevance\":[9998, 9997, 9999]}]", + { "a2", "a", "a1", kNotApplicable } }, + { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," + "{\"google:suggestrelevance\":[9998, 9997, 9999]," + "\"google:verbatimrelevance\":0}]", + { "a2", "a", "a1", kNotApplicable } }, }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { - QueryForInput(ASCIIToUTF16(cases[i].input), false); + QueryForInput(ASCIIToUTF16("a"), false); TestURLFetcher* fetcher = test_factory_.GetFetcherByID( SearchProvider::kDefaultProviderURLFetcherID); fetcher->set_response_code(200); @@ -821,10 +859,12 @@ TEST_F(SearchProviderTest, SuggestRelevanceExperiment) { RunTillProviderDone(); const ACMatches& matches = provider_->matches(); + // The top match must inline and score as highly as calculated verbatim. EXPECT_NE(string16::npos, matches[0].inline_autocomplete_offset); + EXPECT_GE(matches[0].relevance, 1300); size_t j = 0; - // Ensure that the supplied matches equal the expectations. + // Ensure that the returned matches equal the expectations. for (; j < matches.size(); ++j) EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j]), matches[j].contents); // Ensure that no expected matches are missing. |