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/history/url_index_private_data.h" | 5 #include "chrome/browser/history/url_index_private_data.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <iterator> | 9 #include <iterator> |
10 #include <limits> | 10 #include <limits> |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
523 match.title_matches.insert(match.title_matches.end(), | 523 match.title_matches.insert(match.title_matches.end(), |
524 title_term_matches.begin(), | 524 title_term_matches.begin(), |
525 title_term_matches.end()); | 525 title_term_matches.end()); |
526 } | 526 } |
527 | 527 |
528 // Sort matches by offset and eliminate any which overlap. | 528 // Sort matches by offset and eliminate any which overlap. |
529 match.url_matches = SortAndDeoverlapMatches(match.url_matches); | 529 match.url_matches = SortAndDeoverlapMatches(match.url_matches); |
530 match.title_matches = SortAndDeoverlapMatches(match.title_matches); | 530 match.title_matches = SortAndDeoverlapMatches(match.title_matches); |
531 | 531 |
532 // We can inline autocomplete a result if: | 532 // We can inline autocomplete a result if: |
533 // 1) the search term starts at the beginning of the candidate URL, OR | 533 // 1) there is only one search term |
534 // 2) the candidate URL has one of the standard 'ftp' or 'http[s]' | 534 // 2) AND EITHER: |
535 // prefixes. | 535 // 2a) the first match starts at the beginning of the candidate URL, OR |
536 match.can_inline = match.url_matches.size() && | 536 // 2b) the candidate URL starts with one of the standard URL prefixes with |
537 // the URL match immediately following that prefix. | |
538 // 4) AND the search string does not end in whitespace (making it look to | |
Peter Kasting
2012/01/26 23:04:30
Nit: 4 -> 3
mrossetti
2012/01/26 23:09:37
Done.
| |
539 // the IMUI as though there is a single search term when actually there | |
540 // is a second, empty term). | |
541 match.can_inline = match.url_matches.size() > 0 && | |
Peter Kasting
2012/01/26 23:04:30
Nit: !empty()
mrossetti
2012/01/26 23:09:37
Done.
| |
542 terms.size() == 1 && | |
537 (match.url_matches[0].offset == 0 || | 543 (match.url_matches[0].offset == 0 || |
538 IsInlineablePrefix(url.substr(0, match.url_matches[0].offset))); | 544 IsInlineablePrefix(url.substr(0, match.url_matches[0].offset))) && |
545 !IsWhitespace(*(lower_string.rbegin())); | |
539 | 546 |
540 // Get partial scores based on term matching. Note that the score for | 547 // Get partial scores based on term matching. Note that the score for |
541 // each of the URL and title are adjusted by the fraction of the | 548 // each of the URL and title are adjusted by the fraction of the |
542 // terms appearing in each. | 549 // terms appearing in each. |
543 int url_score = ScoreComponentForMatches(match.url_matches, url.length()) * | 550 int url_score = ScoreComponentForMatches(match.url_matches, url.length()) * |
544 std::min(match.url_matches.size(), terms.size()) / terms.size(); | 551 std::min(match.url_matches.size(), terms.size()) / terms.size(); |
545 int title_score = | 552 int title_score = |
546 ScoreComponentForMatches(match.title_matches, title.length()) * | 553 ScoreComponentForMatches(match.title_matches, title.length()) * |
547 std::min(match.title_matches.size(), terms.size()) / terms.size(); | 554 std::min(match.title_matches.size(), terms.size()) / terms.size(); |
548 // Arbitrarily pick the best. | 555 // Arbitrarily pick the best. |
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1134 if (iter->has_title()) { | 1141 if (iter->has_title()) { |
1135 string16 title(UTF8ToUTF16(iter->title())); | 1142 string16 title(UTF8ToUTF16(iter->title())); |
1136 url_row.set_title(title); | 1143 url_row.set_title(title); |
1137 } | 1144 } |
1138 history_info_map_[history_id] = url_row; | 1145 history_info_map_[history_id] = url_row; |
1139 } | 1146 } |
1140 return true; | 1147 return true; |
1141 } | 1148 } |
1142 | 1149 |
1143 } // namespace history | 1150 } // namespace history |
OLD | NEW |