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 COMPONENTS_OMNIBOX_BROWSER_SCORED_HISTORY_MATCH_H_ | 5 #ifndef COMPONENTS_OMNIBOX_BROWSER_SCORED_HISTORY_MATCH_H_ |
6 #define COMPONENTS_OMNIBOX_BROWSER_SCORED_HISTORY_MATCH_H_ | 6 #define COMPONENTS_OMNIBOX_BROWSER_SCORED_HISTORY_MATCH_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "components/history/core/browser/history_match.h" | 16 #include "components/history/core/browser/history_match.h" |
17 #include "components/history/core/browser/history_types.h" | 17 #include "components/history/core/browser/history_types.h" |
18 #include "components/omnibox/browser/in_memory_url_index_types.h" | 18 #include "components/omnibox/browser/in_memory_url_index_types.h" |
19 | 19 |
20 class ScoredHistoryMatchTest; | 20 class ScoredHistoryMatchTest; |
21 | 21 |
22 // An HistoryMatch that has a score as well as metrics defining where in the | 22 // An HistoryMatch that has a score as well as metrics defining where in the |
23 // history item's URL and/or page title matches have occurred. | 23 // history item's URL and/or page title matches have occurred. |
24 struct ScoredHistoryMatch : public history::HistoryMatch { | 24 struct ScoredHistoryMatch : public history::HistoryMatch { |
25 // ScoreMaxRelevance maps from an intermediate-score to the maximum | 25 // ScoreMaxRelevance maps from an intermediate-score to the maximum |
26 // final-relevance score given to a URL for this intermediate score. | 26 // final-relevance score given to a URL for this intermediate score. |
27 // This is used to store the score ranges of HQP relevance buckets. | 27 // This is used to store the score ranges of relevance buckets. |
28 // Please see GetFinalRelevancyScore() for details. | 28 // Please see GetFinalRelevancyScore() for details. |
29 typedef std::pair<double, int> ScoreMaxRelevance; | 29 using ScoreMaxRelevance = std::pair<double, int>; |
| 30 |
| 31 // A sorted vector of ScoreMaxRelevance entries, used by taking a score and |
| 32 // interpolating between consecutive buckets. See GetFinalRelevancyScore() |
| 33 // for details. |
| 34 using ScoreMaxRelevances = std::vector<ScoreMaxRelevance>; |
30 | 35 |
31 // Required for STL, we don't use this directly. | 36 // Required for STL, we don't use this directly. |
32 ScoredHistoryMatch(); | 37 ScoredHistoryMatch(); |
33 ScoredHistoryMatch(const ScoredHistoryMatch& other); | 38 ScoredHistoryMatch(const ScoredHistoryMatch& other); |
34 | 39 |
35 // Initializes the ScoredHistoryMatch with a raw score calculated for the | 40 // Initializes the ScoredHistoryMatch with a raw score calculated for the |
36 // history item given in |row| with recent visits as indicated in |visits|. It | 41 // history item given in |row| with recent visits as indicated in |visits|. It |
37 // first determines if the row qualifies by seeing if all of the terms in | 42 // first 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 | 43 // |terms_vector| occur in |row|. If so, calculates a raw score. This raw |
39 // score is in part determined by whether the matches occur at word | 44 // score is in part determined by whether the matches occur at word |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 126 |
122 // Examines the first |max_visits_to_score_| and returns a score (higher is | 127 // Examines the first |max_visits_to_score_| and returns a score (higher is |
123 // better) based the rate of visits, whether the page is bookmarked, and | 128 // better) based the rate of visits, whether the page is bookmarked, and |
124 // how often those visits are typed navigations (i.e., explicitly | 129 // how often those visits are typed navigations (i.e., explicitly |
125 // invoked by the user). |now| is passed in to avoid unnecessarily | 130 // invoked by the user). |now| is passed in to avoid unnecessarily |
126 // recomputing it frequently. | 131 // recomputing it frequently. |
127 float GetFrequency(const base::Time& now, | 132 float GetFrequency(const base::Time& now, |
128 const bool bookmarked, | 133 const bool bookmarked, |
129 const VisitInfoVector& visits) const; | 134 const VisitInfoVector& visits) const; |
130 | 135 |
131 // Combines the two component scores into a final score that's | 136 // Combines the two component scores into a final score that's an appropriate |
132 // an appropriate value to use as a relevancy score. Scoring buckets are | 137 // value to use as a relevancy score. |
133 // specified through |hqp_relevance_buckets|. Please see the function | 138 static float GetFinalRelevancyScore(float topicality_score, |
134 // implementation for more details. | 139 float frequency_score); |
135 static float GetFinalRelevancyScore( | |
136 float topicality_score, | |
137 float frequency_score, | |
138 const std::vector<ScoreMaxRelevance>& hqp_relevance_buckets); | |
139 | 140 |
140 // Initializes the HQP experimental params: |hqp_relevance_buckets_| | 141 // Helper function that returns the string containing the scoring buckets |
141 // to default buckets. If hqp experimental scoring is enabled, it | 142 // (either the default ones or ones specified in an experiment). |
142 // fetches the |hqp_experimental_scoring_enabled_|, |topicality_threshold_| | 143 static ScoreMaxRelevances GetHQPBuckets(); |
143 // and |hqp_relevance_buckets_| from omnibox field trials. | |
144 static void InitHQPExperimentalParams(); | |
145 | 144 |
146 // Helper function to parse the string containing the scoring buckets. | 145 // Helper function to parse the string containing the scoring buckets and |
147 // For example, | 146 // return the results. For example, with |buckets_str| as |
148 // String: "0.0:400,1.5:600,12.0:1300,20.0:1399" | 147 // "0.0:400,1.5:600,12.0:1300,20.0:1399", it returns [(0.0, 400), (1.5, 600), |
149 // Buckets: vector[(0.0, 400),(1.5,600),(12.0,1300),(20.0,1399)] | 148 // (12.0, 1300), (20.0, 1399)]. It returns an empty vector in the case of a |
150 // Returns false, in case if it fail to parse the string. | 149 // malformed |buckets_str|. |
151 static bool GetHQPBucketsFromString( | 150 static ScoreMaxRelevances GetHQPBucketsFromString( |
152 const std::string& buckets_str, | 151 const std::string& buckets_str); |
153 std::vector<ScoreMaxRelevance>* hqp_buckets); | |
154 | 152 |
155 // If true, assign raw scores to be max(whatever it normally would be, a | 153 // If true, assign raw scores to be max(whatever it normally would be, a |
156 // score that's similar to the score HistoryURL provider would assign). | 154 // score that's similar to the score HistoryURL provider would assign). |
157 static bool also_do_hup_like_scoring_; | 155 static bool also_do_hup_like_scoring_; |
158 | 156 |
159 // Untyped visits to bookmarked pages score this, compared to 1 for | 157 // Untyped visits to bookmarked pages score this, compared to 1 for |
160 // untyped visits to non-bookmarked pages and |typed_value_| for typed visits. | 158 // untyped visits to non-bookmarked pages and |typed_value_| for typed visits. |
161 static float bookmark_value_; | 159 static float bookmark_value_; |
162 | 160 |
163 // Typed visits to page score this, compared to 1 for untyped visits. | 161 // Typed visits to page score this, compared to 1 for untyped visits. |
(...skipping 13 matching lines...) Expand all Loading... |
177 // If true, we allow input terms to match in the TLD (e.g., ".com"). | 175 // If true, we allow input terms to match in the TLD (e.g., ".com"). |
178 static bool allow_tld_matches_; | 176 static bool allow_tld_matches_; |
179 | 177 |
180 // If true, we allow input terms to match in the scheme (e.g., "http://"). | 178 // If true, we allow input terms to match in the scheme (e.g., "http://"). |
181 static bool allow_scheme_matches_; | 179 static bool allow_scheme_matches_; |
182 | 180 |
183 // The number of title words examined when computing topicality scores. | 181 // The number of title words examined when computing topicality scores. |
184 // Words beyond this number are ignored. | 182 // Words beyond this number are ignored. |
185 static size_t num_title_words_to_allow_; | 183 static size_t num_title_words_to_allow_; |
186 | 184 |
187 // True, if hqp experimental scoring is enabled. | |
188 static bool hqp_experimental_scoring_enabled_; | |
189 | |
190 // |topicality_threshold_| is used to control the topicality scoring. | 185 // |topicality_threshold_| is used to control the topicality scoring. |
191 // If |topicality_threshold_| > 0, then URLs with topicality-score < threshold | 186 // If |topicality_threshold_| > 0, then URLs with topicality-score less than |
192 // are given topicality score of 0. By default it is initalized to -1. | 187 // the threshold are given topicality score of 0. |
193 static float topicality_threshold_; | 188 static float topicality_threshold_; |
194 | 189 |
195 // |hqp_relevance_buckets_str_| is used to control the hqp score ranges. | 190 // Used for testing. A possibly null pointer to a vector. If set, |
196 // It is the string representation of |hqp_relevance_buckets_|. | 191 // overrides the static local variable |relevance_buckets| declared in |
197 static char hqp_relevance_buckets_str_[]; | 192 // GetFinalRelevancyScore(). |
198 | 193 static ScoreMaxRelevances* relevance_buckets_override_; |
199 // |hqp_relevance_buckets_| gives mapping from (topicality*frequency) | |
200 // to the final relevance scoring. Please see GetFinalRelevancyScore() | |
201 // for more details and scoring method. | |
202 static std::vector<ScoreMaxRelevance>* hqp_relevance_buckets_; | |
203 }; | 194 }; |
204 typedef std::vector<ScoredHistoryMatch> ScoredHistoryMatches; | 195 typedef std::vector<ScoredHistoryMatch> ScoredHistoryMatches; |
205 | 196 |
206 #endif // COMPONENTS_OMNIBOX_BROWSER_SCORED_HISTORY_MATCH_H_ | 197 #endif // COMPONENTS_OMNIBOX_BROWSER_SCORED_HISTORY_MATCH_H_ |
OLD | NEW |