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 #ifndef CHROME_BROWSER_HISTORY_SCORED_HISTORY_MATCH_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_SCORED_HISTORY_MATCH_H_ |
6 #define CHROME_BROWSER_HISTORY_SCORED_HISTORY_MATCH_H_ | 6 #define CHROME_BROWSER_HISTORY_SCORED_HISTORY_MATCH_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 #include "chrome/browser/autocomplete/history_provider_util.h" | 13 #include "chrome/browser/autocomplete/history_provider_util.h" |
14 #include "chrome/browser/history/history_types.h" | 14 #include "chrome/browser/history/history_types.h" |
15 #include "chrome/browser/history/in_memory_url_index_types.h" | 15 #include "chrome/browser/history/in_memory_url_index_types.h" |
16 #include "testing/gtest/include/gtest/gtest_prod.h" | 16 #include "testing/gtest/include/gtest/gtest_prod.h" |
17 | 17 |
18 class BookmarkService; | 18 class BookmarkService; |
19 | 19 |
20 namespace history { | 20 namespace history { |
21 | 21 |
22 class ScoredHistoryMatchTest; | 22 class ScoredHistoryMatchTest; |
23 | 23 |
24 // An HistoryMatch that has a score as well as metrics defining where in the | 24 // An HistoryMatch that has a score as well as metrics defining where in the |
25 // history item's URL and/or page title matches have occurred. | 25 // history item's URL and/or page title matches have occurred. |
26 class ScoredHistoryMatch : public history::HistoryMatch { | 26 class ScoredHistoryMatch : public history::HistoryMatch { |
27 public: | 27 public: |
28 // The maximum number of recent visits to examine in GetFrecency(). | 28 // The maximum number of recent visits to examine in GetFrequency(). |
29 // Public so url_index_private_data.cc knows how many visits it is | 29 // Public so url_index_private_data.cc knows how many visits it is |
30 // expected to deliver (at minimum) to this class. | 30 // expected to deliver (at minimum) to this class. |
31 static const size_t kMaxVisitsToScore; | 31 static const size_t kMaxVisitsToScore; |
32 | 32 |
33 ScoredHistoryMatch(); // Required by STL. | 33 ScoredHistoryMatch(); // Required by STL. |
34 | 34 |
35 // Creates a new match with a raw score calculated for the history item | 35 // Creates a new match with a raw score calculated for the history item |
36 // given in |row| with recent visits as indicated in |visits|. First | 36 // given in |row| with recent visits as indicated in |visits|. First |
37 // determines if the row qualifies by seeing if all of the terms in | 37 // determines if the row qualifies by seeing if all of the terms in |
38 // |terms_vector| occur in |row|. If so, calculates a raw score. This raw | 38 // |terms_vector| occur in |row|. If so, calculates a raw score. This raw |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 116 |
117 // Pre-calculates days_ago_to_recency_numerator_, used in | 117 // Pre-calculates days_ago_to_recency_numerator_, used in |
118 // GetRecencyScore(). | 118 // GetRecencyScore(). |
119 static void FillInDaysAgoToRecencyScoreArray(); | 119 static void FillInDaysAgoToRecencyScoreArray(); |
120 | 120 |
121 // Examines the first kMaxVisitsToScore and return a score (higher is | 121 // Examines the first kMaxVisitsToScore and return a score (higher is |
122 // better) based the rate of visits, whether the page is bookmarked, and | 122 // better) based the rate of visits, whether the page is bookmarked, and |
123 // how often those visits are typed navigations (i.e., explicitly | 123 // how often those visits are typed navigations (i.e., explicitly |
124 // invoked by the user). |now| is passed in to avoid unnecessarily | 124 // invoked by the user). |now| is passed in to avoid unnecessarily |
125 // recomputing it frequently. | 125 // recomputing it frequently. |
126 static float GetFrecency(const base::Time& now, | 126 static float GetFrequency(const base::Time& now, |
127 const bool bookmarked, | 127 const bool bookmarked, |
128 const VisitInfoVector& visits); | 128 const VisitInfoVector& visits); |
129 | 129 |
130 // Combines the two component scores into a final score that's | 130 // Combines the two component scores into a final score that's |
131 // an appropriate value to use as a relevancy score. | 131 // an appropriate value to use as a relevancy score. |
132 static float GetFinalRelevancyScore( | 132 static float GetFinalRelevancyScore( |
133 float topicality_score, | 133 float topicality_score, |
134 float frecency_score); | 134 float frequency_score); |
135 | 135 |
136 // Sets |also_do_hup_like_scoring_|, | 136 // Sets |also_do_hup_like_scoring_|, |
137 // |max_assigned_score_for_non_inlineable_matches_|, |bookmark_value_|, | 137 // |max_assigned_score_for_non_inlineable_matches_|, |bookmark_value_|, |
138 // |allow_tld_matches_|, and |allow_scheme_matches_| based on the field | 138 // |allow_tld_matches_|, and |allow_scheme_matches_| based on the field |
139 // trial state. | 139 // trial state. |
140 static void Init(); | 140 static void Init(); |
141 | 141 |
142 // An interim score taking into consideration location and completeness | 142 // An interim score taking into consideration location and completeness |
143 // of the match. | 143 // of the match. |
144 int raw_score_; | 144 int raw_score_; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 // matches) because if a non-inlineable match comes first than all matches | 200 // matches) because if a non-inlineable match comes first than all matches |
201 // will get demoted later in HistoryQuickProvider to non-inlineable scores. | 201 // will get demoted later in HistoryQuickProvider to non-inlineable scores. |
202 // Set to -1 to indicate no maximum score. | 202 // Set to -1 to indicate no maximum score. |
203 static int max_assigned_score_for_non_inlineable_matches_; | 203 static int max_assigned_score_for_non_inlineable_matches_; |
204 }; | 204 }; |
205 typedef std::vector<ScoredHistoryMatch> ScoredHistoryMatches; | 205 typedef std::vector<ScoredHistoryMatch> ScoredHistoryMatches; |
206 | 206 |
207 } // namespace history | 207 } // namespace history |
208 | 208 |
209 #endif // CHROME_BROWSER_HISTORY_SCORED_HISTORY_MATCH_H_ | 209 #endif // CHROME_BROWSER_HISTORY_SCORED_HISTORY_MATCH_H_ |
OLD | NEW |