Chromium Code Reviews| 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> |
| 11 #include <set> | 11 #include <set> |
| 12 | 12 |
| 13 #include <math.h> | 13 #include <math.h> |
| 14 | 14 |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "chrome/browser/autocomplete/history_url_provider.h" | |
| 20 #include "chrome/browser/autocomplete/url_prefix.h" | 19 #include "chrome/browser/autocomplete/url_prefix.h" |
| 21 #include "chrome/browser/omnibox/omnibox_field_trial.h" | 20 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
| 22 #include "components/bookmarks/browser/bookmark_utils.h" | 21 #include "components/bookmarks/browser/bookmark_utils.h" |
| 23 #include "components/history/core/browser/history_client.h" | 22 #include "components/history/core/browser/history_client.h" |
| 24 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 25 | 24 |
| 25 namespace { | |
| 26 | |
| 27 // These magic numbers are duplicated from HistoryURLProvider | |
| 28 const int kScoreForBestInlineableResult = 1413; | |
| 29 const int kBaseScoreForNonInlineableResult = 900; | |
| 30 | |
| 31 } // namespace | |
| 32 | |
| 26 namespace history { | 33 namespace history { |
| 27 | 34 |
| 28 // ScoredHistoryMatch ---------------------------------------------------------- | 35 // ScoredHistoryMatch ---------------------------------------------------------- |
| 29 | 36 |
| 30 // static | 37 // static |
| 31 const size_t ScoredHistoryMatch::kMaxVisitsToScore = 10; | 38 const size_t ScoredHistoryMatch::kMaxVisitsToScore = 10; |
| 32 const int ScoredHistoryMatch::kDaysToPrecomputeRecencyScoresFor = 366; | 39 const int ScoredHistoryMatch::kDaysToPrecomputeRecencyScoresFor = 366; |
| 33 const int ScoredHistoryMatch::kMaxRawTermScore = 30; | 40 const int ScoredHistoryMatch::kMaxRawTermScore = 30; |
| 34 float* ScoredHistoryMatch::raw_term_score_to_topicality_score_ = NULL; | 41 float* ScoredHistoryMatch::raw_term_score_to_topicality_score_ = NULL; |
| 35 float* ScoredHistoryMatch::days_ago_to_recency_score_ = NULL; | 42 float* ScoredHistoryMatch::days_ago_to_recency_score_ = NULL; |
| 36 bool ScoredHistoryMatch::initialized_ = false; | 43 bool ScoredHistoryMatch::initialized_ = false; |
| 37 int ScoredHistoryMatch::bookmark_value_ = 1; | 44 int ScoredHistoryMatch::bookmark_value_ = 1; |
| 38 bool ScoredHistoryMatch::allow_tld_matches_ = false; | 45 bool ScoredHistoryMatch::allow_tld_matches_ = false; |
| 39 bool ScoredHistoryMatch::allow_scheme_matches_ = false; | 46 bool ScoredHistoryMatch::allow_scheme_matches_ = false; |
| 40 bool ScoredHistoryMatch::also_do_hup_like_scoring_ = false; | 47 bool ScoredHistoryMatch::also_do_hup_like_scoring_ = false; |
| 41 int ScoredHistoryMatch::max_assigned_score_for_non_inlineable_matches_ = -1; | |
| 42 | 48 |
| 43 ScoredHistoryMatch::ScoredHistoryMatch() | 49 ScoredHistoryMatch::ScoredHistoryMatch() |
| 44 : raw_score_(0), | 50 : raw_score_(0), |
| 45 can_inline_(false) { | 51 can_inline_(false) { |
| 46 Init(); | 52 Init(); |
| 47 } | 53 } |
| 48 | 54 |
| 49 ScoredHistoryMatch::ScoredHistoryMatch( | 55 ScoredHistoryMatch::ScoredHistoryMatch( |
| 50 const URLRow& row, | 56 const URLRow& row, |
| 51 const VisitInfoVector& visits, | 57 const VisitInfoVector& visits, |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 (raw_score_ <= kint32max) ? static_cast<int>(raw_score_) : kint32max; | 165 (raw_score_ <= kint32max) ? static_cast<int>(raw_score_) : kint32max; |
| 160 | 166 |
| 161 if (also_do_hup_like_scoring_ && can_inline_) { | 167 if (also_do_hup_like_scoring_ && can_inline_) { |
| 162 // HistoryURL-provider-like scoring gives any match that is | 168 // HistoryURL-provider-like scoring gives any match that is |
| 163 // capable of being inlined a certain minimum score. Some of these | 169 // capable of being inlined a certain minimum score. Some of these |
| 164 // are given a higher score that lets them be shown in inline. | 170 // are given a higher score that lets them be shown in inline. |
| 165 // This test here derives from the test in | 171 // This test here derives from the test in |
| 166 // HistoryURLProvider::PromoteMatchForInlineAutocomplete(). | 172 // HistoryURLProvider::PromoteMatchForInlineAutocomplete(). |
| 167 const bool promote_to_inline = (row.typed_count() > 1) || | 173 const bool promote_to_inline = (row.typed_count() > 1) || |
| 168 (IsHostOnly() && (row.typed_count() == 1)); | 174 (IsHostOnly() && (row.typed_count() == 1)); |
| 169 int hup_like_score = promote_to_inline ? | 175 int hup_like_score = promote_to_inline ? kScoreForBestInlineableResult |
| 170 HistoryURLProvider::kScoreForBestInlineableResult : | 176 : kBaseScoreForNonInlineableResult; |
| 171 HistoryURLProvider::kBaseScoreForNonInlineableResult; | |
| 172 | 177 |
| 173 // Also, if the user types the hostname of a host with a typed | 178 // Also, if the user types the hostname of a host with a typed |
| 174 // visit, then everything from that host get given inlineable scores | 179 // visit, then everything from that host get given inlineable scores |
| 175 // (because the URL-that-you-typed will go first and everything | 180 // (because the URL-that-you-typed will go first and everything |
| 176 // else will be assigned one minus the previous score, as coded | 181 // else will be assigned one minus the previous score, as coded |
| 177 // at the end of HistoryURLProvider::DoAutocomplete(). | 182 // at the end of HistoryURLProvider::DoAutocomplete(). |
| 178 if (base::UTF8ToUTF16(gurl.host()) == terms[0]) | 183 if (base::UTF8ToUTF16(gurl.host()) == terms[0]) |
| 179 hup_like_score = HistoryURLProvider::kScoreForBestInlineableResult; | 184 hup_like_score = kScoreForBestInlineableResult; |
| 180 | 185 |
| 181 // HistoryURLProvider has the function PromoteOrCreateShorterSuggestion() | 186 // HistoryURLProvider has the function PromoteOrCreateShorterSuggestion() |
| 182 // that's meant to promote prefixes of the best match (if they've | 187 // that's meant to promote prefixes of the best match (if they've |
| 183 // been visited enough related to the best match) or | 188 // been visited enough related to the best match) or |
| 184 // create/promote host-only suggestions (even if they've never | 189 // create/promote host-only suggestions (even if they've never |
| 185 // been typed). The code is complicated and we don't try to | 190 // been typed). The code is complicated and we don't try to |
| 186 // duplicate the logic here. Instead, we handle a simple case: in | 191 // duplicate the logic here. Instead, we handle a simple case: in |
| 187 // low-typed-count ranges, give host-only matches (i.e., | 192 // 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 | 193 // 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 | 194 // that the host-only match outscores all the other matches that |
| 190 // would normally have the same base score. This behavior is not | 195 // would normally have the same base score. This behavior is not |
| 191 // identical to what happens in HistoryURLProvider even in these | 196 // identical to what happens in HistoryURLProvider even in these |
| 192 // low typed count ranges--sometimes it will create/promote when | 197 // low typed count ranges--sometimes it will create/promote when |
| 193 // this test does not (indeed, we cannot create matches like HUP | 198 // this test does not (indeed, we cannot create matches like HUP |
| 194 // can) and vice versa--but the underlying philosophy is similar. | 199 // can) and vice versa--but the underlying philosophy is similar. |
| 195 if (!promote_to_inline && IsHostOnly()) | 200 if (!promote_to_inline && IsHostOnly()) |
| 196 hup_like_score++; | 201 hup_like_score++; |
| 197 | 202 |
| 198 // All the other logic to goes into hup-like-scoring happens in | 203 // All the other logic to goes into hup-like-scoring happens in |
| 199 // the tie-breaker case of MatchScoreGreater(). | 204 // the tie-breaker case of MatchScoreGreater(). |
| 200 | 205 |
| 201 // Incorporate hup_like_score into raw_score. | 206 // Incorporate hup_like_score into raw_score. |
| 202 raw_score_ = std::max(raw_score_, hup_like_score); | 207 raw_score_ = std::max(raw_score_, hup_like_score); |
| 203 } | 208 } |
| 204 | 209 |
| 205 // If this match is not inlineable and there's a cap on the maximum | |
|
blundell
2014/06/11 18:17:36
Why did this code go away?
nshaik
2014/06/11 20:46:50
That code is applicable only if max_assigned_score
| |
| 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 | 210 // 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 | 211 // 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. | 212 // spec, not the cleaned-up URL string that we used for matching. |
| 215 std::vector<size_t> offsets = OffsetsFromTermMatches(url_matches_); | 213 std::vector<size_t> offsets = OffsetsFromTermMatches(url_matches_); |
| 216 base::OffsetAdjuster::UnadjustOffsets(adjustments, &offsets); | 214 base::OffsetAdjuster::UnadjustOffsets(adjustments, &offsets); |
| 217 url_matches_ = ReplaceOffsetsInTermMatches(url_matches_, offsets); | 215 url_matches_ = ReplaceOffsetsInTermMatches(url_matches_, offsets); |
| 218 } | 216 } |
| 219 | 217 |
| 220 ScoredHistoryMatch::~ScoredHistoryMatch() {} | 218 ScoredHistoryMatch::~ScoredHistoryMatch() {} |
| 221 | 219 |
| (...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 | 576 // in the URL and/or title and that are visited practically all |
| 579 // the time using typed visits. We don't attempt to distinguish | 577 // the time using typed visits. We don't attempt to distinguish |
| 580 // between these very good results.) | 578 // between these very good results.) |
| 581 const float slope = (1399 - 1300) / (20.0f - 12.0f); | 579 const float slope = (1399 - 1300) / (20.0f - 12.0f); |
| 582 return std::min(1399.0, 1300 + slope * (intermediate_score - 12.0)); | 580 return std::min(1399.0, 1300 + slope * (intermediate_score - 12.0)); |
| 583 } | 581 } |
| 584 | 582 |
| 585 void ScoredHistoryMatch::Init() { | 583 void ScoredHistoryMatch::Init() { |
| 586 if (initialized_) | 584 if (initialized_) |
| 587 return; | 585 return; |
| 588 also_do_hup_like_scoring_ = false; | |
|
blundell
2014/06/11 18:17:36
This assignment has to stay I would think?
nshaik
2014/06/11 20:46:50
It is always assigned to false. So I deleted it.
I
| |
| 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(); | 586 bookmark_value_ = OmniboxFieldTrial::HQPBookmarkValue(); |
| 603 allow_tld_matches_ = OmniboxFieldTrial::HQPAllowMatchInTLDValue(); | 587 allow_tld_matches_ = OmniboxFieldTrial::HQPAllowMatchInTLDValue(); |
| 604 allow_scheme_matches_ = OmniboxFieldTrial::HQPAllowMatchInSchemeValue(); | 588 allow_scheme_matches_ = OmniboxFieldTrial::HQPAllowMatchInSchemeValue(); |
| 605 initialized_ = true; | 589 initialized_ = true; |
| 606 } | 590 } |
| 607 | 591 |
| 608 } // namespace history | 592 } // namespace history |
| OLD | NEW |