| 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/scored_history_match.h" | 5 #include "chrome/browser/history/scored_history_match.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <iterator> | 9 #include <iterator> |
| 10 #include <numeric> | 10 #include <numeric> |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 raw_score_(0), | 61 raw_score_(0), |
| 62 can_inline_(false) { | 62 can_inline_(false) { |
| 63 Init(); | 63 Init(); |
| 64 | 64 |
| 65 GURL gurl = row.url(); | 65 GURL gurl = row.url(); |
| 66 if (!gurl.is_valid()) | 66 if (!gurl.is_valid()) |
| 67 return; | 67 return; |
| 68 | 68 |
| 69 // Figure out where each search term appears in the URL and/or page title | 69 // Figure out where each search term appears in the URL and/or page title |
| 70 // so that we can score as well as provide autocomplete highlighting. | 70 // so that we can score as well as provide autocomplete highlighting. |
| 71 base::string16 url = bookmark_utils::CleanUpUrlForMatching(gurl, languages); | 71 base::OffsetAdjuster::Adjustments adjustments; |
| 72 base::string16 url = |
| 73 bookmark_utils::CleanUpUrlForMatching(gurl, languages, &adjustments); |
| 72 base::string16 title = bookmark_utils::CleanUpTitleForMatching(row.title()); | 74 base::string16 title = bookmark_utils::CleanUpTitleForMatching(row.title()); |
| 73 int term_num = 0; | 75 int term_num = 0; |
| 74 for (String16Vector::const_iterator iter = terms.begin(); iter != terms.end(); | 76 for (String16Vector::const_iterator iter = terms.begin(); iter != terms.end(); |
| 75 ++iter, ++term_num) { | 77 ++iter, ++term_num) { |
| 76 base::string16 term = *iter; | 78 base::string16 term = *iter; |
| 77 TermMatches url_term_matches = MatchTermInString(term, url, term_num); | 79 TermMatches url_term_matches = MatchTermInString(term, url, term_num); |
| 78 TermMatches title_term_matches = MatchTermInString(term, title, term_num); | 80 TermMatches title_term_matches = MatchTermInString(term, title, term_num); |
| 79 if (url_term_matches.empty() && title_term_matches.empty()) | 81 if (url_term_matches.empty() && title_term_matches.empty()) |
| 80 return; // A term was not found in either URL or title - reject. | 82 return; // A term was not found in either URL or title - reject. |
| 81 url_matches_.insert(url_matches_.end(), url_term_matches.begin(), | 83 url_matches_.insert(url_matches_.end(), url_term_matches.begin(), |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 // Incorporate hup_like_score into raw_score. | 202 // Incorporate hup_like_score into raw_score. |
| 201 raw_score_ = std::max(raw_score_, hup_like_score); | 203 raw_score_ = std::max(raw_score_, hup_like_score); |
| 202 } | 204 } |
| 203 | 205 |
| 204 // If this match is not inlineable and there's a cap on the maximum | 206 // If this match is not inlineable and there's a cap on the maximum |
| 205 // score that can be given to non-inlineable matches, apply the cap. | 207 // score that can be given to non-inlineable matches, apply the cap. |
| 206 if (!can_inline_ && (max_assigned_score_for_non_inlineable_matches_ != -1)) { | 208 if (!can_inline_ && (max_assigned_score_for_non_inlineable_matches_ != -1)) { |
| 207 raw_score_ = std::min(max_assigned_score_for_non_inlineable_matches_, | 209 raw_score_ = std::min(max_assigned_score_for_non_inlineable_matches_, |
| 208 raw_score_); | 210 raw_score_); |
| 209 } | 211 } |
| 212 |
| 213 // Now that we're done processing this entry, correct the offsets of the |
| 214 // matches in |url_matches_| so they point to offsets in the original URL |
| 215 // spec, not the cleaned-up URL string that we used for matching. |
| 216 std::vector<size_t> offsets = OffsetsFromTermMatches(url_matches_); |
| 217 base::OffsetAdjuster::UnadjustOffsets(adjustments, &offsets); |
| 218 url_matches_ = ReplaceOffsetsInTermMatches(url_matches_, offsets); |
| 210 } | 219 } |
| 211 | 220 |
| 212 ScoredHistoryMatch::~ScoredHistoryMatch() {} | 221 ScoredHistoryMatch::~ScoredHistoryMatch() {} |
| 213 | 222 |
| 214 // Comparison function for sorting ScoredMatches by their scores with | 223 // Comparison function for sorting ScoredMatches by their scores with |
| 215 // intelligent tie-breaking. | 224 // intelligent tie-breaking. |
| 216 bool ScoredHistoryMatch::MatchScoreGreater(const ScoredHistoryMatch& m1, | 225 bool ScoredHistoryMatch::MatchScoreGreater(const ScoredHistoryMatch& m1, |
| 217 const ScoredHistoryMatch& m2) { | 226 const ScoredHistoryMatch& m2) { |
| 218 if (m1.raw_score_ != m2.raw_score_) | 227 if (m1.raw_score_ != m2.raw_score_) |
| 219 return m1.raw_score_ > m2.raw_score_; | 228 return m1.raw_score_ > m2.raw_score_; |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 max_assigned_score_for_non_inlineable_matches_ = | 600 max_assigned_score_for_non_inlineable_matches_ = |
| 592 HistoryURLProvider::kScoreForBestInlineableResult - 1; | 601 HistoryURLProvider::kScoreForBestInlineableResult - 1; |
| 593 } | 602 } |
| 594 bookmark_value_ = OmniboxFieldTrial::HQPBookmarkValue(); | 603 bookmark_value_ = OmniboxFieldTrial::HQPBookmarkValue(); |
| 595 allow_tld_matches_ = OmniboxFieldTrial::HQPAllowMatchInTLDValue(); | 604 allow_tld_matches_ = OmniboxFieldTrial::HQPAllowMatchInTLDValue(); |
| 596 allow_scheme_matches_ = OmniboxFieldTrial::HQPAllowMatchInSchemeValue(); | 605 allow_scheme_matches_ = OmniboxFieldTrial::HQPAllowMatchInSchemeValue(); |
| 597 initialized_ = true; | 606 initialized_ = true; |
| 598 } | 607 } |
| 599 | 608 |
| 600 } // namespace history | 609 } // namespace history |
| OLD | NEW |