| 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 19 matching lines...) Expand all Loading... |
| 30 // static | 30 // static |
| 31 const size_t ScoredHistoryMatch::kMaxVisitsToScore = 10; | 31 const size_t ScoredHistoryMatch::kMaxVisitsToScore = 10; |
| 32 const int ScoredHistoryMatch::kDaysToPrecomputeRecencyScoresFor = 366; | 32 const int ScoredHistoryMatch::kDaysToPrecomputeRecencyScoresFor = 366; |
| 33 const int ScoredHistoryMatch::kMaxRawTermScore = 30; | 33 const int ScoredHistoryMatch::kMaxRawTermScore = 30; |
| 34 float* ScoredHistoryMatch::raw_term_score_to_topicality_score_ = NULL; | 34 float* ScoredHistoryMatch::raw_term_score_to_topicality_score_ = NULL; |
| 35 float* ScoredHistoryMatch::days_ago_to_recency_score_ = NULL; | 35 float* ScoredHistoryMatch::days_ago_to_recency_score_ = NULL; |
| 36 bool ScoredHistoryMatch::initialized_ = false; | 36 bool ScoredHistoryMatch::initialized_ = false; |
| 37 int ScoredHistoryMatch::bookmark_value_ = 1; | 37 int ScoredHistoryMatch::bookmark_value_ = 1; |
| 38 bool ScoredHistoryMatch::allow_tld_matches_ = false; | 38 bool ScoredHistoryMatch::allow_tld_matches_ = false; |
| 39 bool ScoredHistoryMatch::allow_scheme_matches_ = false; | 39 bool ScoredHistoryMatch::allow_scheme_matches_ = false; |
| 40 bool ScoredHistoryMatch::also_do_hup_like_scoring_ = false; | |
| 41 int ScoredHistoryMatch::max_assigned_score_for_non_inlineable_matches_ = -1; | |
| 42 | 40 |
| 43 ScoredHistoryMatch::ScoredHistoryMatch() | 41 ScoredHistoryMatch::ScoredHistoryMatch() |
| 44 : raw_score_(0), | 42 : raw_score_(0), |
| 45 can_inline_(false) { | 43 can_inline_(false) { |
| 46 Init(); | 44 Init(); |
| 47 } | 45 } |
| 48 | 46 |
| 49 ScoredHistoryMatch::ScoredHistoryMatch( | 47 ScoredHistoryMatch::ScoredHistoryMatch( |
| 50 const URLRow& row, | 48 const URLRow& row, |
| 51 const VisitInfoVector& visits, | 49 const VisitInfoVector& visits, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 } | 149 } |
| 152 | 150 |
| 153 const float topicality_score = GetTopicalityScore( | 151 const float topicality_score = GetTopicalityScore( |
| 154 terms.size(), url, terms_to_word_starts_offsets, word_starts); | 152 terms.size(), url, terms_to_word_starts_offsets, word_starts); |
| 155 const float frequency_score = GetFrequency( | 153 const float frequency_score = GetFrequency( |
| 156 now, (history_client && history_client->IsBookmarked(gurl)), visits); | 154 now, (history_client && history_client->IsBookmarked(gurl)), visits); |
| 157 raw_score_ = GetFinalRelevancyScore(topicality_score, frequency_score); | 155 raw_score_ = GetFinalRelevancyScore(topicality_score, frequency_score); |
| 158 raw_score_ = | 156 raw_score_ = |
| 159 (raw_score_ <= kint32max) ? static_cast<int>(raw_score_) : kint32max; | 157 (raw_score_ <= kint32max) ? static_cast<int>(raw_score_) : kint32max; |
| 160 | 158 |
| 161 if (also_do_hup_like_scoring_ && can_inline_) { | |
| 162 // HistoryURL-provider-like scoring gives any match that is | |
| 163 // capable of being inlined a certain minimum score. Some of these | |
| 164 // are given a higher score that lets them be shown in inline. | |
| 165 // This test here derives from the test in | |
| 166 // HistoryURLProvider::PromoteMatchForInlineAutocomplete(). | |
| 167 const bool promote_to_inline = (row.typed_count() > 1) || | |
| 168 (IsHostOnly() && (row.typed_count() == 1)); | |
| 169 int hup_like_score = promote_to_inline ? | |
| 170 HistoryURLProvider::kScoreForBestInlineableResult : | |
| 171 HistoryURLProvider::kBaseScoreForNonInlineableResult; | |
| 172 | |
| 173 // Also, if the user types the hostname of a host with a typed | |
| 174 // visit, then everything from that host get given inlineable scores | |
| 175 // (because the URL-that-you-typed will go first and everything | |
| 176 // else will be assigned one minus the previous score, as coded | |
| 177 // at the end of HistoryURLProvider::DoAutocomplete(). | |
| 178 if (base::UTF8ToUTF16(gurl.host()) == terms[0]) | |
| 179 hup_like_score = HistoryURLProvider::kScoreForBestInlineableResult; | |
| 180 | |
| 181 // HistoryURLProvider has the function PromoteOrCreateShorterSuggestion() | |
| 182 // that's meant to promote prefixes of the best match (if they've | |
| 183 // been visited enough related to the best match) or | |
| 184 // create/promote host-only suggestions (even if they've never | |
| 185 // been typed). The code is complicated and we don't try to | |
| 186 // duplicate the logic here. Instead, we handle a simple case: in | |
| 187 // low-typed-count ranges, give host-only matches (i.e., | |
| 188 // http://www.foo.com/ vs. http://www.foo.com/bar.html) a boost so | |
| 189 // that the host-only match outscores all the other matches that | |
| 190 // would normally have the same base score. This behavior is not | |
| 191 // identical to what happens in HistoryURLProvider even in these | |
| 192 // low typed count ranges--sometimes it will create/promote when | |
| 193 // this test does not (indeed, we cannot create matches like HUP | |
| 194 // can) and vice versa--but the underlying philosophy is similar. | |
| 195 if (!promote_to_inline && IsHostOnly()) | |
| 196 hup_like_score++; | |
| 197 | |
| 198 // All the other logic to goes into hup-like-scoring happens in | |
| 199 // the tie-breaker case of MatchScoreGreater(). | |
| 200 | |
| 201 // Incorporate hup_like_score into raw_score. | |
| 202 raw_score_ = std::max(raw_score_, hup_like_score); | |
| 203 } | |
| 204 | |
| 205 // If this match is not inlineable and there's a cap on the maximum | |
| 206 // score that can be given to non-inlineable matches, apply the cap. | |
| 207 if (!can_inline_ && (max_assigned_score_for_non_inlineable_matches_ != -1)) { | |
| 208 raw_score_ = std::min(max_assigned_score_for_non_inlineable_matches_, | |
| 209 raw_score_); | |
| 210 } | |
| 211 | |
| 212 // Now that we're done processing this entry, correct the offsets of the | 159 // Now that we're done processing this entry, correct the offsets of the |
| 213 // matches in |url_matches_| so they point to offsets in the original URL | 160 // matches in |url_matches_| so they point to offsets in the original URL |
| 214 // spec, not the cleaned-up URL string that we used for matching. | 161 // spec, not the cleaned-up URL string that we used for matching. |
| 215 std::vector<size_t> offsets = OffsetsFromTermMatches(url_matches_); | 162 std::vector<size_t> offsets = OffsetsFromTermMatches(url_matches_); |
| 216 base::OffsetAdjuster::UnadjustOffsets(adjustments, &offsets); | 163 base::OffsetAdjuster::UnadjustOffsets(adjustments, &offsets); |
| 217 url_matches_ = ReplaceOffsetsInTermMatches(url_matches_, offsets); | 164 url_matches_ = ReplaceOffsetsInTermMatches(url_matches_, offsets); |
| 218 } | 165 } |
| 219 | 166 |
| 220 ScoredHistoryMatch::~ScoredHistoryMatch() {} | 167 ScoredHistoryMatch::~ScoredHistoryMatch() {} |
| 221 | 168 |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 // in the URL and/or title and that are visited practically all | 525 // in the URL and/or title and that are visited practically all |
| 579 // the time using typed visits. We don't attempt to distinguish | 526 // the time using typed visits. We don't attempt to distinguish |
| 580 // between these very good results.) | 527 // between these very good results.) |
| 581 const float slope = (1399 - 1300) / (20.0f - 12.0f); | 528 const float slope = (1399 - 1300) / (20.0f - 12.0f); |
| 582 return std::min(1399.0, 1300 + slope * (intermediate_score - 12.0)); | 529 return std::min(1399.0, 1300 + slope * (intermediate_score - 12.0)); |
| 583 } | 530 } |
| 584 | 531 |
| 585 void ScoredHistoryMatch::Init() { | 532 void ScoredHistoryMatch::Init() { |
| 586 if (initialized_) | 533 if (initialized_) |
| 587 return; | 534 return; |
| 588 also_do_hup_like_scoring_ = false; | |
| 589 // When doing HUP-like scoring, don't allow a non-inlineable match | |
| 590 // to beat the score of good inlineable matches. This is a problem | |
| 591 // because if a non-inlineable match ends up with the highest score | |
| 592 // from HistoryQuick provider, all HistoryQuick matches get demoted | |
| 593 // to non-inlineable scores (scores less than 1200). Without | |
| 594 // HUP-like-scoring, these results would actually come from the HUP | |
| 595 // and not be demoted, thus outscoring the demoted HQP results. | |
| 596 // When the HQP provides these, we need to clamp the non-inlineable | |
| 597 // results to preserve this behavior. | |
| 598 if (also_do_hup_like_scoring_) { | |
| 599 max_assigned_score_for_non_inlineable_matches_ = | |
| 600 HistoryURLProvider::kScoreForBestInlineableResult - 1; | |
| 601 } | |
| 602 bookmark_value_ = OmniboxFieldTrial::HQPBookmarkValue(); | 535 bookmark_value_ = OmniboxFieldTrial::HQPBookmarkValue(); |
| 603 allow_tld_matches_ = OmniboxFieldTrial::HQPAllowMatchInTLDValue(); | 536 allow_tld_matches_ = OmniboxFieldTrial::HQPAllowMatchInTLDValue(); |
| 604 allow_scheme_matches_ = OmniboxFieldTrial::HQPAllowMatchInSchemeValue(); | 537 allow_scheme_matches_ = OmniboxFieldTrial::HQPAllowMatchInSchemeValue(); |
| 605 initialized_ = true; | 538 initialized_ = true; |
| 606 } | 539 } |
| 607 | 540 |
| 608 } // namespace history | 541 } // namespace history |
| OLD | NEW |