Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: chrome/browser/autocomplete/autocomplete_result.cc

Issue 55413002: Don't demote top match for certain match types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/autocomplete/autocomplete_result.h" 5 #include "chrome/browser/autocomplete/autocomplete_result.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 29 matching lines...) Expand all
40 CompareWithDemoteByType::CompareWithDemoteByType( 40 CompareWithDemoteByType::CompareWithDemoteByType(
41 AutocompleteInput::PageClassification current_page_classification) { 41 AutocompleteInput::PageClassification current_page_classification) {
42 OmniboxFieldTrial::GetDemotionsByType(current_page_classification, 42 OmniboxFieldTrial::GetDemotionsByType(current_page_classification,
43 &demotions_); 43 &demotions_);
44 } 44 }
45 45
46 int CompareWithDemoteByType::GetDemotedRelevance( 46 int CompareWithDemoteByType::GetDemotedRelevance(
47 const AutocompleteMatch& match) { 47 const AutocompleteMatch& match) {
48 OmniboxFieldTrial::DemotionMultipliers::const_iterator demotion_it = 48 OmniboxFieldTrial::DemotionMultipliers::const_iterator demotion_it =
49 demotions_.find(match.type); 49 demotions_.find(match.type);
50 return (demotion_it == demotions_.end()) ? 50 return (demotion_it == demotions_.end() || !match.demoteable) ?
51 match.relevance : (match.relevance * demotion_it->second); 51 match.relevance : (match.relevance * demotion_it->second);
52 } 52 }
53 53
54 bool CompareWithDemoteByType::operator()(const AutocompleteMatch& elem1, 54 bool CompareWithDemoteByType::operator()(const AutocompleteMatch& elem1,
55 const AutocompleteMatch& elem2) { 55 const AutocompleteMatch& elem2) {
56 // Compute demoted relevance scores for each match. 56 // Compute demoted relevance scores for each match.
57 const int demoted_relevance1 = GetDemotedRelevance(elem1); 57 const int demoted_relevance1 = GetDemotedRelevance(elem1);
58 const int demoted_relevance2 = GetDemotedRelevance(elem2); 58 const int demoted_relevance2 = GetDemotedRelevance(elem2);
59 // For equal-relevance matches, we sort alphabetically, so that providers 59 // For equal-relevance matches, we sort alphabetically, so that providers
60 // who return multiple elements at the same priority get a "stable" sort 60 // who return multiple elements at the same priority get a "stable" sort
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) 147 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i)
148 i->ComputeStrippedDestinationURL(profile); 148 i->ComputeStrippedDestinationURL(profile);
149 149
150 // Remove duplicates. 150 // Remove duplicates.
151 std::sort(matches_.begin(), matches_.end(), 151 std::sort(matches_.begin(), matches_.end(),
152 &AutocompleteMatch::DestinationSortFunc); 152 &AutocompleteMatch::DestinationSortFunc);
153 matches_.erase(std::unique(matches_.begin(), matches_.end(), 153 matches_.erase(std::unique(matches_.begin(), matches_.end(),
154 &AutocompleteMatch::DestinationsEqual), 154 &AutocompleteMatch::DestinationsEqual),
155 matches_.end()); 155 matches_.end());
156 156
157 // Don't demote the top match if applicable.
158 OmniboxFieldTrial::UndemotableTopMatchTypes undemotable_top_types;
159 OmniboxFieldTrial::GetUndemotableTopTypes(input.current_page_classification(),
160 &undemotable_top_types);
161 if (!matches_.empty() &&
162 undemotable_top_types.find(matches_.begin()->type) !=
163 undemotable_top_types.end()) {
164 matches_.begin()->demoteable = false;
Peter Kasting 2013/10/31 23:27:59 Is this basically only used by code called from th
H Fung 2013/11/01 23:42:56 Yes, thanks. I've made the change.
165 }
166
157 // Sort and trim to the most relevant kMaxMatches matches. 167 // Sort and trim to the most relevant kMaxMatches matches.
158 size_t max_num_matches = std::min(kMaxMatches, matches_.size()); 168 size_t max_num_matches = std::min(kMaxMatches, matches_.size());
159 CompareWithDemoteByType comparing_object(input.current_page_classification()); 169 CompareWithDemoteByType comparing_object(input.current_page_classification());
160 std::sort(matches_.begin(), matches_.end(), comparing_object); 170 std::sort(matches_.begin(), matches_.end(), comparing_object);
161 if (!matches_.empty() && !matches_.begin()->allowed_to_be_default_match && 171 if (!matches_.empty() && !matches_.begin()->allowed_to_be_default_match &&
162 OmniboxFieldTrial::ReorderForLegalDefaultMatch( 172 OmniboxFieldTrial::ReorderForLegalDefaultMatch(
163 input.current_page_classification())) { 173 input.current_page_classification())) {
164 // Top match is not allowed to be the default match. Find the most 174 // Top match is not allowed to be the default match. Find the most
165 // relevant legal match and shift it to the front. 175 // relevant legal match and shift it to the front.
166 for (AutocompleteResult::iterator it = matches_.begin() + 1; 176 for (AutocompleteResult::iterator it = matches_.begin() + 1;
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 i != old_matches.rend() && delta > 0; ++i) { 372 i != old_matches.rend() && delta > 0; ++i) {
363 if (!HasMatchByDestination(*i, new_matches)) { 373 if (!HasMatchByDestination(*i, new_matches)) {
364 AutocompleteMatch match = *i; 374 AutocompleteMatch match = *i;
365 match.relevance = std::min(max_relevance, match.relevance); 375 match.relevance = std::min(max_relevance, match.relevance);
366 match.from_previous = true; 376 match.from_previous = true;
367 AddMatch(page_classification, match); 377 AddMatch(page_classification, match);
368 delta--; 378 delta--;
369 } 379 }
370 } 380 }
371 } 381 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_match.cc ('k') | chrome/browser/omnibox/omnibox_field_trial.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698