| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/history_url_provider.h" | 5 #include "chrome/browser/autocomplete/history_url_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 | 476 |
| 477 default: | 477 default: |
| 478 return 900 + static_cast<int>(match_number); | 478 return 900 + static_cast<int>(match_number); |
| 479 } | 479 } |
| 480 } | 480 } |
| 481 | 481 |
| 482 // static | 482 // static |
| 483 float HistoryURLProvider::CalculateConfidence( | 483 float HistoryURLProvider::CalculateConfidence( |
| 484 const history::HistoryMatch& match, | 484 const history::HistoryMatch& match, |
| 485 const history::HistoryMatches& matches) { | 485 const history::HistoryMatches& matches) { |
| 486 // TODO(dominich): Take into account bookmarked page? | 486 // Calculate a score based on typed count. |
| 487 // TODO(dominich): See CompareHistoryMatch for more measures to include. | 487 const float typed_numerator = match.url_info.typed_count(); |
| 488 // Using typed count in place of visit count as: | 488 float typed_denominator = 0.0f; |
| 489 for (history::HistoryMatches::const_iterator it = matches.begin(); |
| 490 it != matches.end(); ++it) { |
| 491 typed_denominator += it->url_info.typed_count(); |
| 492 } |
| 493 const float typed_score = (typed_denominator > 0.0f) ? |
| 494 (typed_numerator / typed_denominator) : 0.0f; |
| 495 |
| 496 // Calculate a score based on visit count |
| 497 const float visit_numerator = match.url_info.visit_count(); |
| 498 float visit_denominator = 0.0f; |
| 499 for (history::HistoryMatches::const_iterator it = matches.begin(); |
| 500 it != matches.end(); ++it) { |
| 501 visit_denominator += it->url_info.visit_count(); |
| 502 } |
| 503 const float visit_score = (visit_denominator > 0.0f) ? |
| 504 (visit_numerator / visit_denominator) : 0.0f; |
| 505 |
| 506 // Calculate a score based on innermost matching. |
| 507 const float innermost_score = (match.innermost_match ? 1.0f : 0.0f); |
| 508 |
| 509 // TODO(dominich): Add a boost for bookmarked pages? |
| 510 // Prefer typed count to visit count as: |
| 489 // - It's a better indicator of what the user wants to open given that they | 511 // - It's a better indicator of what the user wants to open given that they |
| 490 // are typing in the address bar (users tend to open certain URLs by typing | 512 // are typing in the address bar (users tend to open certain URLs by typing |
| 491 // and others by e.g. bookmarks, so visit_count is a good indicator of | 513 // and others by e.g. bookmarks, so visit_count is a good indicator of |
| 492 // overall interest but a bad one for specifically omnibox interest). | 514 // overall interest but a bad one for specifically omnibox interest). |
| 493 // - Since the DB query is sorted by typed_count, the results may be | 515 // - Since the DB query is sorted by typed_count, the results may be |
| 494 // effectively a random selection as far as visit_counts are concerned | 516 // effectively a random selection as far as visit_counts are concerned |
| 495 // (meaning many high-visit_count-URLs may be present in one query and | 517 // (meaning many high-visit_count-URLs may be present in one query and |
| 496 // absent in a similar one), leading to wild swings in confidence for the | 518 // absent in a similar one), leading to wild swings in confidence for the |
| 497 // same result across distinct queries. | 519 // same result across distinct queries. |
| 498 float numerator = match.url_info.typed_count(); | 520 // Add a boost for innermost matches (matches after scheme or 'www.'). |
| 499 float denominator = 0.0f; | 521 return (0.5f * typed_score) + (0.3f * visit_score) + (0.2f * innermost_score); |
| 500 for (history::HistoryMatches::const_iterator it = matches.begin(); | |
| 501 it != matches.end(); ++it) { | |
| 502 denominator += it->url_info.typed_count(); | |
| 503 } | |
| 504 if (denominator < 1) { | |
| 505 numerator = match.url_info.visit_count(); | |
| 506 for (history::HistoryMatches::const_iterator it = matches.begin(); | |
| 507 it != matches.end(); ++it) { | |
| 508 denominator += it->url_info.visit_count(); | |
| 509 } | |
| 510 } | |
| 511 return (denominator > 0.0f ? numerator / denominator : 0); | |
| 512 } | 522 } |
| 513 | 523 |
| 514 // static | 524 // static |
| 515 void HistoryURLProvider::PromoteOrCreateShorterSuggestion( | 525 void HistoryURLProvider::PromoteOrCreateShorterSuggestion( |
| 516 history::URLDatabase* db, | 526 history::URLDatabase* db, |
| 517 const HistoryURLProviderParams& params, | 527 const HistoryURLProviderParams& params, |
| 518 bool have_what_you_typed_match, | 528 bool have_what_you_typed_match, |
| 519 const AutocompleteMatch& what_you_typed_match, | 529 const AutocompleteMatch& what_you_typed_match, |
| 520 HistoryMatches* matches) { | 530 HistoryMatches* matches) { |
| 521 if (matches->empty()) | 531 if (matches->empty()) |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 &match.contents_class); | 868 &match.contents_class); |
| 859 } | 869 } |
| 860 match.description = info.title(); | 870 match.description = info.title(); |
| 861 AutocompleteMatch::ClassifyMatchInString(params->input.text(), | 871 AutocompleteMatch::ClassifyMatchInString(params->input.text(), |
| 862 info.title(), | 872 info.title(), |
| 863 ACMatchClassification::NONE, | 873 ACMatchClassification::NONE, |
| 864 &match.description_class); | 874 &match.description_class); |
| 865 | 875 |
| 866 return match; | 876 return match; |
| 867 } | 877 } |
| OLD | NEW |