OLD | NEW |
---|---|
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/shortcuts_provider.h" | 5 #include "chrome/browser/autocomplete/shortcuts_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 }; | 48 }; |
49 | 49 |
50 } // namespace | 50 } // namespace |
51 | 51 |
52 ShortcutsProvider::ShortcutsProvider(AutocompleteProviderListener* listener, | 52 ShortcutsProvider::ShortcutsProvider(AutocompleteProviderListener* listener, |
53 Profile* profile) | 53 Profile* profile) |
54 : AutocompleteProvider(listener, profile, | 54 : AutocompleteProvider(listener, profile, |
55 AutocompleteProvider::TYPE_SHORTCUTS), | 55 AutocompleteProvider::TYPE_SHORTCUTS), |
56 languages_(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)), | 56 languages_(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)), |
57 initialized_(false), | 57 initialized_(false), |
58 max_relevance_(AutocompleteResult::kLowestDefaultScore - 1) { | 58 max_relevance_(AutocompleteResult::kLowestDefaultScore - 1), |
59 omnibox_will_reorder_for_legal_default_match_( | |
60 OmniboxFieldTrial::InReorderForLegalDefaultMatchGroup()) { | |
59 scoped_refptr<history::ShortcutsBackend> backend = | 61 scoped_refptr<history::ShortcutsBackend> backend = |
60 ShortcutsBackendFactory::GetForProfile(profile_); | 62 ShortcutsBackendFactory::GetForProfile(profile_); |
61 if (backend.get()) { | 63 if (backend.get()) { |
62 backend->AddObserver(this); | 64 backend->AddObserver(this); |
63 if (backend->initialized()) | 65 if (backend->initialized()) |
64 initialized_ = true; | 66 initialized_ = true; |
65 } | 67 } |
66 int max_relevance; | 68 int max_relevance; |
67 if (OmniboxFieldTrial::ShortcutsScoringMaxRelevance(&max_relevance)) | 69 if (OmniboxFieldTrial::ShortcutsScoringMaxRelevance(&max_relevance)) |
68 max_relevance_ = max_relevance; | 70 max_relevance_ = max_relevance; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 matches_.push_back(ShortcutToACMatch(relevance, term_string, it->second)); | 169 matches_.push_back(ShortcutToACMatch(relevance, term_string, it->second)); |
168 } | 170 } |
169 std::partial_sort(matches_.begin(), | 171 std::partial_sort(matches_.begin(), |
170 matches_.begin() + | 172 matches_.begin() + |
171 std::min(AutocompleteProvider::kMaxMatches, matches_.size()), | 173 std::min(AutocompleteProvider::kMaxMatches, matches_.size()), |
172 matches_.end(), &AutocompleteMatch::MoreRelevant); | 174 matches_.end(), &AutocompleteMatch::MoreRelevant); |
173 if (matches_.size() > AutocompleteProvider::kMaxMatches) { | 175 if (matches_.size() > AutocompleteProvider::kMaxMatches) { |
174 matches_.erase(matches_.begin() + AutocompleteProvider::kMaxMatches, | 176 matches_.erase(matches_.begin() + AutocompleteProvider::kMaxMatches, |
175 matches_.end()); | 177 matches_.end()); |
176 } | 178 } |
177 // Reset relevance scores to guarantee no results are given an | 179 // Reset relevance scores to guarantee no result is given a score that |
178 // inlineable score and all scores are decreasing (but not do assign | 180 // may allow it to become the highest ranked matches (= default match) |
msw
2013/07/18 06:23:57
nit: s/matches/match, also s/=/i.e. the/
Mark P
2013/07/21 20:31:05
Done.
| |
179 // any scores below 1). | 181 // unless the omnibox will reorder matches as necessary to correct the |
180 int max_relevance = AutocompleteResult::kLowestDefaultScore - 1; | 182 // problem. In the process of resetting scores, guarantee that all scores |
181 for (ACMatches::iterator it = matches_.begin(); it != matches_.end(); ++it) { | 183 // are decreasing (but not do assign any scores below 1). |
182 max_relevance = std::min(max_relevance, it->relevance); | 184 if (!omnibox_will_reorder_for_legal_default_match_) { |
183 it->relevance = max_relevance; | 185 int max_relevance = AutocompleteResult::kLowestDefaultScore - 1; |
184 if (max_relevance > 1) | 186 for (ACMatches::iterator it = matches_.begin(); it != matches_.end(); |
185 --max_relevance; | 187 ++it) { |
188 max_relevance = std::min(max_relevance, it->relevance); | |
189 it->relevance = max_relevance; | |
190 if (max_relevance > 1) | |
191 --max_relevance; | |
192 } | |
186 } | 193 } |
187 } | 194 } |
188 | 195 |
189 AutocompleteMatch ShortcutsProvider::ShortcutToACMatch( | 196 AutocompleteMatch ShortcutsProvider::ShortcutToACMatch( |
190 int relevance, | 197 int relevance, |
191 const string16& term_string, | 198 const string16& term_string, |
192 const history::ShortcutsBackend::Shortcut& shortcut) { | 199 const history::ShortcutsBackend::Shortcut& shortcut) { |
193 DCHECK(!term_string.empty()); | 200 DCHECK(!term_string.empty()); |
194 AutocompleteMatch match(this, relevance, true, | 201 AutocompleteMatch match(this, relevance, true, |
195 AutocompleteMatchType::HISTORY_TITLE); | 202 AutocompleteMatchType::HISTORY_TITLE); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. | 371 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. |
365 const double kMaxDecaySpeedDivisor = 5.0; | 372 const double kMaxDecaySpeedDivisor = 5.0; |
366 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; | 373 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; |
367 double decay_divisor = std::min(kMaxDecaySpeedDivisor, | 374 double decay_divisor = std::min(kMaxDecaySpeedDivisor, |
368 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / | 375 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / |
369 kNumUsesPerDecaySpeedDivisorIncrement); | 376 kNumUsesPerDecaySpeedDivisorIncrement); |
370 | 377 |
371 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + | 378 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + |
372 0.5); | 379 0.5); |
373 } | 380 } |
OLD | NEW |