| 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/history/in_memory_url_index.h" | 5 #include "chrome/browser/history/in_memory_url_index.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <iterator> | 9 #include <iterator> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 match.can_inline = | 741 match.can_inline = |
| 742 match.url_matches.size() == 1 && match.url_matches[0].offset == 0; | 742 match.url_matches.size() == 1 && match.url_matches[0].offset == 0; |
| 743 | 743 |
| 744 // Get partial scores based on term matching. Note that the score for | 744 // Get partial scores based on term matching. Note that the score for |
| 745 // each of the URL and title are adjusted by the fraction of the | 745 // each of the URL and title are adjusted by the fraction of the |
| 746 // terms appearing in each. | 746 // terms appearing in each. |
| 747 int url_score = ScoreComponentForMatches(match.url_matches, url.size()) * | 747 int url_score = ScoreComponentForMatches(match.url_matches, url.size()) * |
| 748 match.url_matches.size() / terms.size(); | 748 match.url_matches.size() / terms.size(); |
| 749 int title_score = | 749 int title_score = |
| 750 ScoreComponentForMatches(match.title_matches, title.size()) * | 750 ScoreComponentForMatches(match.title_matches, title.size()) * |
| 751 static_cast<int>(match.title_matches.size()) / | 751 match.title_matches.size() / terms.size(); |
| 752 static_cast<int>(terms.size()); | |
| 753 // Arbitrarily pick the best. | 752 // Arbitrarily pick the best. |
| 754 // TODO(mrossetti): It might make sense that a term which appears in both the | 753 // TODO(mrossetti): It might make sense that a term which appears in both the |
| 755 // URL and the Title should boost the score a bit. | 754 // URL and the Title should boost the score a bit. |
| 756 int term_score = std::max(url_score, title_score); | 755 int term_score = std::max(url_score, title_score); |
| 757 if (term_score == 0) | 756 if (term_score == 0) |
| 758 return match; | 757 return match; |
| 759 | 758 |
| 760 // Determine scoring factors for the recency of visit, visit count and typed | 759 // Determine scoring factors for the recency of visit, visit count and typed |
| 761 // count attributes of the URLRow. | 760 // count attributes of the URLRow. |
| 762 const int kDaysAgoLevel[] = { 0, 10, 20, 30 }; | 761 const int kDaysAgoLevel[] = { 0, 10, 20, 30 }; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 const int kStartMaxValue = 250; | 820 const int kStartMaxValue = 250; |
| 822 int start_value = (kMaxSignificantStart - | 821 int start_value = (kMaxSignificantStart - |
| 823 std::min(kMaxSignificantStart, matches[0].offset)) * kStartMaxValue / | 822 std::min(kMaxSignificantStart, matches[0].offset)) * kStartMaxValue / |
| 824 kMaxSignificantStart; | 823 kMaxSignificantStart; |
| 825 | 824 |
| 826 // Score component for how much of the matched string the input terms cover. | 825 // Score component for how much of the matched string the input terms cover. |
| 827 // kCompleteMaxValue points times the fraction of the URL/page title string | 826 // kCompleteMaxValue points times the fraction of the URL/page title string |
| 828 // that was matched. | 827 // that was matched. |
| 829 size_t term_length_total = std::accumulate(matches.begin(), matches.end(), | 828 size_t term_length_total = std::accumulate(matches.begin(), matches.end(), |
| 830 0, AccumulateMatchLength); | 829 0, AccumulateMatchLength); |
| 830 const size_t kMaxSignificantLength = 50; |
| 831 size_t max_significant_length = |
| 832 std::min(max_length, std::max(term_length_total, kMaxSignificantLength)); |
| 831 const int kCompleteMaxValue = 500; | 833 const int kCompleteMaxValue = 500; |
| 832 int complete_value = term_length_total * kCompleteMaxValue / max_length; | 834 int complete_value = |
| 835 term_length_total * kCompleteMaxValue / max_significant_length; |
| 833 | 836 |
| 834 int raw_score = order_value + start_value + complete_value; | 837 int raw_score = order_value + start_value + complete_value; |
| 835 const int kTermScoreLevel[] = { 1000, 650, 500, 200 }; | 838 const int kTermScoreLevel[] = { 1000, 650, 500, 200 }; |
| 836 | 839 |
| 837 // Scale the sum of the three components above into a single score component | 840 // Scale the sum of the three components above into a single score component |
| 838 // on the same scale as that used in ScoredMatchForURL(). | 841 // on the same scale as that used in ScoredMatchForURL(). |
| 839 return ScoreForValue(raw_score, kTermScoreLevel); | 842 return ScoreForValue(raw_score, kTermScoreLevel); |
| 840 } | 843 } |
| 841 | 844 |
| 842 InMemoryURLIndex::AddHistoryMatch::AddHistoryMatch( | 845 InMemoryURLIndex::AddHistoryMatch::AddHistoryMatch( |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 if (iter->has_title()) { | 1083 if (iter->has_title()) { |
| 1081 string16 title(UTF8ToUTF16(iter->title())); | 1084 string16 title(UTF8ToUTF16(iter->title())); |
| 1082 url_row.set_title(title); | 1085 url_row.set_title(title); |
| 1083 } | 1086 } |
| 1084 history_info_map_[history_id] = url_row; | 1087 history_info_map_[history_id] = url_row; |
| 1085 } | 1088 } |
| 1086 return true; | 1089 return true; |
| 1087 } | 1090 } |
| 1088 | 1091 |
| 1089 } // namespace history | 1092 } // namespace history |
| OLD | NEW |