| 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/scored_history_match.h" | 5 #include "chrome/browser/autocomplete/scored_history_match.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 // Pre-computed information to speed up calculating topicality scores. | 47 // Pre-computed information to speed up calculating topicality scores. |
| 48 // |raw_term_score_to_topicality_score| is a simple array mapping how raw terms | 48 // |raw_term_score_to_topicality_score| is a simple array mapping how raw terms |
| 49 // scores (a weighted sum of the number of hits for the term, weighted by how | 49 // scores (a weighted sum of the number of hits for the term, weighted by how |
| 50 // important the hit is: hostname, path, etc.) to the topicality score we should | 50 // important the hit is: hostname, path, etc.) to the topicality score we should |
| 51 // assign it. This allows easy lookups of scores without requiring math. This | 51 // assign it. This allows easy lookups of scores without requiring math. This |
| 52 // is initialized by InitRawTermScoreToTopicalityScoreArray() called from | 52 // is initialized by InitRawTermScoreToTopicalityScoreArray() called from |
| 53 // ScoredHistoryMatch::Init(). | 53 // ScoredHistoryMatch::Init(). |
| 54 float raw_term_score_to_topicality_score[kMaxRawTermScore]; | 54 float raw_term_score_to_topicality_score[kMaxRawTermScore]; |
| 55 | 55 |
| 56 // The maximum score that can be assigned to non-inlineable matches. This is | |
| 57 // useful because often we want inlineable matches to come first (even if they | |
| 58 // don't sometimes score as well as non-inlineable matches) because if a | |
| 59 // non-inlineable match comes first than all matches will get demoted later in | |
| 60 // HistoryQuickProvider to non-inlineable scores. Set to -1 to indicate no | |
| 61 // maximum score. | |
| 62 int max_assigned_score_for_non_inlineable_matches = -1; | |
| 63 | |
| 64 // Whether ScoredHistoryMatch::Init() has been called. | 56 // Whether ScoredHistoryMatch::Init() has been called. |
| 65 bool initialized = false; | 57 bool initialized = false; |
| 66 | 58 |
| 67 // Precalculates raw_term_score_to_topicality_score, used in | 59 // Precalculates raw_term_score_to_topicality_score, used in |
| 68 // GetTopicalityScore(). | 60 // GetTopicalityScore(). |
| 69 void InitRawTermScoreToTopicalityScoreArray() { | 61 void InitRawTermScoreToTopicalityScoreArray() { |
| 70 for (int term_score = 0; term_score < kMaxRawTermScore; ++term_score) { | 62 for (int term_score = 0; term_score < kMaxRawTermScore; ++term_score) { |
| 71 float topicality_score; | 63 float topicality_score; |
| 72 if (term_score < 10) { | 64 if (term_score < 10) { |
| 73 // If the term scores less than 10 points (no full-credit hit, or | 65 // If the term scores less than 10 points (no full-credit hit, or |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 if (!promote_to_inline && IsHostOnly()) | 271 if (!promote_to_inline && IsHostOnly()) |
| 280 hup_like_score++; | 272 hup_like_score++; |
| 281 | 273 |
| 282 // All the other logic to goes into hup-like-scoring happens in | 274 // All the other logic to goes into hup-like-scoring happens in |
| 283 // the tie-breaker case of MatchScoreGreater(). | 275 // the tie-breaker case of MatchScoreGreater(). |
| 284 | 276 |
| 285 // Incorporate hup_like_score into raw_score. | 277 // Incorporate hup_like_score into raw_score. |
| 286 raw_score = std::max(raw_score, hup_like_score); | 278 raw_score = std::max(raw_score, hup_like_score); |
| 287 } | 279 } |
| 288 | 280 |
| 289 // If this match is not inlineable and there's a cap on the maximum | |
| 290 // score that can be given to non-inlineable matches, apply the cap. | |
| 291 if (!can_inline && (max_assigned_score_for_non_inlineable_matches != -1)) { | |
| 292 raw_score = | |
| 293 std::min(raw_score, max_assigned_score_for_non_inlineable_matches); | |
| 294 } | |
| 295 | |
| 296 // Now that we're done processing this entry, correct the offsets of the | 281 // Now that we're done processing this entry, correct the offsets of the |
| 297 // matches in |url_matches| so they point to offsets in the original URL | 282 // matches in |url_matches| so they point to offsets in the original URL |
| 298 // spec, not the cleaned-up URL string that we used for matching. | 283 // spec, not the cleaned-up URL string that we used for matching. |
| 299 std::vector<size_t> offsets = OffsetsFromTermMatches(url_matches); | 284 std::vector<size_t> offsets = OffsetsFromTermMatches(url_matches); |
| 300 base::OffsetAdjuster::UnadjustOffsets(adjustments, &offsets); | 285 base::OffsetAdjuster::UnadjustOffsets(adjustments, &offsets); |
| 301 url_matches = ReplaceOffsetsInTermMatches(url_matches, offsets); | 286 url_matches = ReplaceOffsetsInTermMatches(url_matches, offsets); |
| 302 } | 287 } |
| 303 | 288 |
| 304 ScoredHistoryMatch::~ScoredHistoryMatch() { | 289 ScoredHistoryMatch::~ScoredHistoryMatch() { |
| 305 } | 290 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 // system; hence CurrentlyOn(UI thread) will fail.) | 370 // system; hence CurrentlyOn(UI thread) will fail.) |
| 386 using content::BrowserThread; | 371 using content::BrowserThread; |
| 387 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || | 372 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || |
| 388 BrowserThread::CurrentlyOn(BrowserThread::UI)); | 373 BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 389 | 374 |
| 390 if (initialized) | 375 if (initialized) |
| 391 return; | 376 return; |
| 392 | 377 |
| 393 initialized = true; | 378 initialized = true; |
| 394 | 379 |
| 395 // When doing HUP-like scoring, don't allow a non-inlineable match | |
| 396 // to beat the score of good inlineable matches. This is a problem | |
| 397 // because if a non-inlineable match ends up with the highest score | |
| 398 // from HistoryQuick provider, all HistoryQuick matches get demoted | |
| 399 // to non-inlineable scores (scores less than 1200). Without | |
| 400 // HUP-like-scoring, these results would actually come from the HUP | |
| 401 // and not be demoted, thus outscoring the demoted HQP results. | |
| 402 // When the HQP provides these, we need to clamp the non-inlineable | |
| 403 // results to preserve this behavior. | |
| 404 if (kAlsoDoHupLikeScoring) { | |
| 405 max_assigned_score_for_non_inlineable_matches = | |
| 406 HistoryURLProvider::kScoreForBestInlineableResult - 1; | |
| 407 } | |
| 408 bookmark_value_ = OmniboxFieldTrial::HQPBookmarkValue(); | 380 bookmark_value_ = OmniboxFieldTrial::HQPBookmarkValue(); |
| 409 fix_frequency_bugs_ = OmniboxFieldTrial::HQPFixFrequencyScoringBugs(); | 381 fix_frequency_bugs_ = OmniboxFieldTrial::HQPFixFrequencyScoringBugs(); |
| 410 allow_tld_matches_ = OmniboxFieldTrial::HQPAllowMatchInTLDValue(); | 382 allow_tld_matches_ = OmniboxFieldTrial::HQPAllowMatchInTLDValue(); |
| 411 allow_scheme_matches_ = OmniboxFieldTrial::HQPAllowMatchInSchemeValue(); | 383 allow_scheme_matches_ = OmniboxFieldTrial::HQPAllowMatchInSchemeValue(); |
| 412 num_title_words_to_allow_ = OmniboxFieldTrial::HQPNumTitleWordsToAllow(); | 384 num_title_words_to_allow_ = OmniboxFieldTrial::HQPNumTitleWordsToAllow(); |
| 413 | 385 |
| 414 InitRawTermScoreToTopicalityScoreArray(); | 386 InitRawTermScoreToTopicalityScoreArray(); |
| 415 InitDaysAgoToRecencyScoreArray(); | 387 InitDaysAgoToRecencyScoreArray(); |
| 416 InitHQPExperimentalParams(); | 388 InitHQPExperimentalParams(); |
| 417 } | 389 } |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 base::StringToDouble(it->first, &bucket.first); | 679 base::StringToDouble(it->first, &bucket.first); |
| 708 DCHECK(is_valid_intermediate_score); | 680 DCHECK(is_valid_intermediate_score); |
| 709 bool is_valid_hqp_score = base::StringToInt(it->second, &bucket.second); | 681 bool is_valid_hqp_score = base::StringToInt(it->second, &bucket.second); |
| 710 DCHECK(is_valid_hqp_score); | 682 DCHECK(is_valid_hqp_score); |
| 711 hqp_buckets->push_back(bucket); | 683 hqp_buckets->push_back(bucket); |
| 712 } | 684 } |
| 713 return true; | 685 return true; |
| 714 } | 686 } |
| 715 return false; | 687 return false; |
| 716 } | 688 } |
| OLD | NEW |