| 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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 // Try to mark pieces of the contents and description as matches if they | 242 // Try to mark pieces of the contents and description as matches if they |
| 243 // appear in |input.text()|. | 243 // appear in |input.text()|. |
| 244 const base::string16 term_string = base::i18n::ToLower(input.text()); | 244 const base::string16 term_string = base::i18n::ToLower(input.text()); |
| 245 WordMap terms_map(CreateWordMapForString(term_string)); | 245 WordMap terms_map(CreateWordMapForString(term_string)); |
| 246 if (!terms_map.empty()) { | 246 if (!terms_map.empty()) { |
| 247 match.contents_class = ClassifyAllMatchesInString(term_string, terms_map, | 247 match.contents_class = ClassifyAllMatchesInString(term_string, terms_map, |
| 248 match.contents, match.contents_class); | 248 match.contents, match.contents_class); |
| 249 match.description_class = ClassifyAllMatchesInString(term_string, terms_map, | 249 match.description_class = ClassifyAllMatchesInString(term_string, terms_map, |
| 250 match.description, match.description_class); | 250 match.description, match.description_class); |
| 251 } | 251 } |
| 252 match.PossiblySwapContentsAndDescriptionForURLSuggestion(input); |
| 252 return match; | 253 return match; |
| 253 } | 254 } |
| 254 | 255 |
| 255 // static | 256 // static |
| 256 ShortcutsProvider::WordMap ShortcutsProvider::CreateWordMapForString( | 257 ShortcutsProvider::WordMap ShortcutsProvider::CreateWordMapForString( |
| 257 const base::string16& text) { | 258 const base::string16& text) { |
| 258 // First, convert |text| to a vector of the unique words in it. | 259 // First, convert |text| to a vector of the unique words in it. |
| 259 WordMap word_map; | 260 WordMap word_map; |
| 260 base::i18n::BreakIterator word_iter(text, | 261 base::i18n::BreakIterator word_iter(text, |
| 261 base::i18n::BreakIterator::BREAK_WORD); | 262 base::i18n::BreakIterator::BREAK_WORD); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. | 402 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. |
| 402 const double kMaxDecaySpeedDivisor = 5.0; | 403 const double kMaxDecaySpeedDivisor = 5.0; |
| 403 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; | 404 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; |
| 404 double decay_divisor = std::min(kMaxDecaySpeedDivisor, | 405 double decay_divisor = std::min(kMaxDecaySpeedDivisor, |
| 405 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / | 406 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / |
| 406 kNumUsesPerDecaySpeedDivisorIncrement); | 407 kNumUsesPerDecaySpeedDivisorIncrement); |
| 407 | 408 |
| 408 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + | 409 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + |
| 409 0.5); | 410 0.5); |
| 410 } | 411 } |
| OLD | NEW |