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 "components/omnibox/shortcuts_provider.h" | 5 #include "components/omnibox/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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 for (ShortcutsBackend::ShortcutMap::const_iterator it = | 135 for (ShortcutsBackend::ShortcutMap::const_iterator it = |
136 FindFirstMatch(term_string, backend.get()); | 136 FindFirstMatch(term_string, backend.get()); |
137 it != backend->shortcuts_map().end() && | 137 it != backend->shortcuts_map().end() && |
138 base::StartsWith(it->first, term_string, true); | 138 base::StartsWith(it->first, term_string, true); |
139 ++it) { | 139 ++it) { |
140 // Don't return shortcuts with zero relevance. | 140 // Don't return shortcuts with zero relevance. |
141 int relevance = CalculateScore(term_string, it->second, max_relevance); | 141 int relevance = CalculateScore(term_string, it->second, max_relevance); |
142 if (relevance) { | 142 if (relevance) { |
143 matches_.push_back(ShortcutToACMatch(it->second, relevance, input, | 143 matches_.push_back(ShortcutToACMatch(it->second, relevance, input, |
144 fixed_up_input)); | 144 fixed_up_input)); |
145 matches_.back().ComputeStrippedDestinationURL(template_url_service); | 145 matches_.back().ComputeStrippedDestinationURL(input, |
| 146 template_url_service); |
146 } | 147 } |
147 } | 148 } |
148 // Remove duplicates. Duplicates don't need to be preserved in the matches | 149 // Remove duplicates. This is important because it's common to have multiple |
149 // because they are only used for deletions, and shortcuts deletes matches | 150 // shortcuts pointing to the same URL, e.g., ma, mai, and mail all pointing |
150 // based on the URL. | 151 // to mail.google.com, so typing "m" will return them all. If we then simply |
| 152 // clamp to kMaxMatches and let the AutocompleteResult take care of |
| 153 // collapsing the duplicates, we'll effectively only be returning one match, |
| 154 // instead of several possibilities. |
| 155 // |
| 156 // Note that while removing duplicates, we don't populate a match's |
| 157 // |duplicate_matches| field--duplicates don't need to be preserved in the |
| 158 // matches because they are only used for deletions, and this provider |
| 159 // deletes matches based on the URL. |
151 AutocompleteResult::DedupMatchesByDestination( | 160 AutocompleteResult::DedupMatchesByDestination( |
152 input.current_page_classification(), false, &matches_); | 161 input.current_page_classification(), false, &matches_); |
153 // Find best matches. | 162 // Find best matches. |
154 std::partial_sort(matches_.begin(), | 163 std::partial_sort(matches_.begin(), |
155 matches_.begin() + | 164 matches_.begin() + |
156 std::min(AutocompleteProvider::kMaxMatches, matches_.size()), | 165 std::min(AutocompleteProvider::kMaxMatches, matches_.size()), |
157 matches_.end(), &AutocompleteMatch::MoreRelevant); | 166 matches_.end(), &AutocompleteMatch::MoreRelevant); |
158 if (matches_.size() > AutocompleteProvider::kMaxMatches) { | 167 if (matches_.size() > AutocompleteProvider::kMaxMatches) { |
159 matches_.erase(matches_.begin() + AutocompleteProvider::kMaxMatches, | 168 matches_.erase(matches_.begin() + AutocompleteProvider::kMaxMatches, |
160 matches_.end()); | 169 matches_.end()); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 URLPrefix::GetInlineAutocompleteOffset( | 227 URLPrefix::GetInlineAutocompleteOffset( |
219 input.text(), fixed_up_input_text, true, match.fill_into_edit); | 228 input.text(), fixed_up_input_text, true, match.fill_into_edit); |
220 if (inline_autocomplete_offset != base::string16::npos) { | 229 if (inline_autocomplete_offset != base::string16::npos) { |
221 match.inline_autocompletion = | 230 match.inline_autocompletion = |
222 match.fill_into_edit.substr(inline_autocomplete_offset); | 231 match.fill_into_edit.substr(inline_autocomplete_offset); |
223 match.allowed_to_be_default_match = | 232 match.allowed_to_be_default_match = |
224 !HistoryProvider::PreventInlineAutocomplete(input) || | 233 !HistoryProvider::PreventInlineAutocomplete(input) || |
225 match.inline_autocompletion.empty(); | 234 match.inline_autocompletion.empty(); |
226 } | 235 } |
227 } | 236 } |
228 match.EnsureUWYTIsAllowedToBeDefault(input.canonicalized_url(), | 237 match.EnsureUWYTIsAllowedToBeDefault(input, |
229 client_->GetTemplateURLService()); | 238 client_->GetTemplateURLService()); |
230 | 239 |
231 // Try to mark pieces of the contents and description as matches if they | 240 // Try to mark pieces of the contents and description as matches if they |
232 // appear in |input.text()|. | 241 // appear in |input.text()|. |
233 const base::string16 term_string = base::i18n::ToLower(input.text()); | 242 const base::string16 term_string = base::i18n::ToLower(input.text()); |
234 WordMap terms_map(CreateWordMapForString(term_string)); | 243 WordMap terms_map(CreateWordMapForString(term_string)); |
235 if (!terms_map.empty()) { | 244 if (!terms_map.empty()) { |
236 match.contents_class = ClassifyAllMatchesInString(term_string, terms_map, | 245 match.contents_class = ClassifyAllMatchesInString(term_string, terms_map, |
237 match.contents, match.contents_class); | 246 match.contents, match.contents_class); |
238 match.description_class = ClassifyAllMatchesInString(term_string, terms_map, | 247 match.description_class = ClassifyAllMatchesInString(term_string, terms_map, |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. | 400 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. |
392 const double kMaxDecaySpeedDivisor = 5.0; | 401 const double kMaxDecaySpeedDivisor = 5.0; |
393 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; | 402 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; |
394 double decay_divisor = std::min(kMaxDecaySpeedDivisor, | 403 double decay_divisor = std::min(kMaxDecaySpeedDivisor, |
395 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / | 404 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / |
396 kNumUsesPerDecaySpeedDivisorIncrement); | 405 kNumUsesPerDecaySpeedDivisorIncrement); |
397 | 406 |
398 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + | 407 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + |
399 0.5); | 408 0.5); |
400 } | 409 } |
OLD | NEW |