Chromium Code Reviews| 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 typedef std::pair<double, int> ScoreMaxRelevance; |
| 30 | 30 |
| 31 // Required for STL, we don't use this directly. | 31 // Required for STL, we don't use this directly. |
| 32 ScoredHistoryMatch(); | 32 ScoredHistoryMatch(); |
| 33 ScoredHistoryMatch(const ScoredHistoryMatch& other); | 33 ScoredHistoryMatch(const ScoredHistoryMatch& other); |
| 34 | 34 |
| 35 // Initializes the ScoredHistoryMatch with a raw score calculated for the | 35 // Initializes the ScoredHistoryMatch with a raw score calculated for the |
| 36 // history item given in |row| with recent visits as indicated in |visits|. It | 36 // 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 | 37 // first determines if the row qualifies by seeing if all of the terms in |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 | 121 |
| 122 // Examines the first |max_visits_to_score_| and returns a score (higher is | 122 // 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 | 123 // better) based the rate of visits, whether the page is bookmarked, and |
| 124 // how often those visits are typed navigations (i.e., explicitly | 124 // how often those visits are typed navigations (i.e., explicitly |
| 125 // invoked by the user). |now| is passed in to avoid unnecessarily | 125 // invoked by the user). |now| is passed in to avoid unnecessarily |
| 126 // recomputing it frequently. | 126 // recomputing it frequently. |
| 127 float GetFrequency(const base::Time& now, | 127 float GetFrequency(const base::Time& now, |
| 128 const bool bookmarked, | 128 const bool bookmarked, |
| 129 const VisitInfoVector& visits) const; | 129 const VisitInfoVector& visits) const; |
| 130 | 130 |
| 131 // Combines the two component scores into a final score that's | 131 // 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 | 132 // value to use as a relevancy score. |
| 133 // specified through |hqp_relevance_buckets|. Please see the function | 133 static float GetFinalRelevancyScore(float topicality_score, |
| 134 // implementation for more details. | 134 float frequency_score); |
| 135 static float GetFinalRelevancyScore( | |
| 136 float topicality_score, | |
| 137 float frequency_score, | |
| 138 const std::vector<ScoreMaxRelevance>& hqp_relevance_buckets); | |
| 139 | 135 |
| 140 // Initializes the HQP experimental params: |hqp_relevance_buckets_| | 136 // Helper function that returns the string containing the scoring buckets |
| 141 // to default buckets. If hqp experimental scoring is enabled, it | 137 // (either the default ones or ones specified in an experiment). |
| 142 // fetches the |hqp_experimental_scoring_enabled_|, |topicality_threshold_| | 138 static std::vector<ScoreMaxRelevance> GetHQPBuckets(); |
|
Peter Kasting
2016/12/08 01:29:21
I don't love how often "std::vector<ScoreMaxReleva
Mark P
2016/12/09 20:40:56
Done.
| |
| 143 // and |hqp_relevance_buckets_| from omnibox field trials. | |
| 144 static void InitHQPExperimentalParams(); | |
| 145 | 139 |
| 146 // Helper function to parse the string containing the scoring buckets. | 140 // Helper function to parse the string containing the scoring buckets and |
| 147 // For example, | 141 // return the results. For example, with |bucket_str| as |
|
Peter Kasting
2016/12/08 01:29:21
Nit: buckets
Mark P
2016/12/09 20:40:56
Done.
| |
| 148 // String: "0.0:400,1.5:600,12.0:1300,20.0:1399" | 142 // "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)] | 143 // (12.0, 1300), (20.0, 1399)]. It returns an empty list in the case of a |
|
Peter Kasting
2016/12/08 01:29:22
Nit: list -> vector
Mark P
2016/12/09 20:40:56
Done.
| |
| 150 // Returns false, in case if it fail to parse the string. | 144 // malformed |buckets_str|. |
| 151 static bool GetHQPBucketsFromString( | 145 static std::vector<ScoreMaxRelevance> GetHQPBucketsFromString( |
| 152 const std::string& buckets_str, | 146 const std::string& buckets_str); |
| 153 std::vector<ScoreMaxRelevance>* hqp_buckets); | |
| 154 | 147 |
| 155 // If true, assign raw scores to be max(whatever it normally would be, a | 148 // 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). | 149 // score that's similar to the score HistoryURL provider would assign). |
| 157 static bool also_do_hup_like_scoring_; | 150 static bool also_do_hup_like_scoring_; |
| 158 | 151 |
| 159 // Untyped visits to bookmarked pages score this, compared to 1 for | 152 // Untyped visits to bookmarked pages score this, compared to 1 for |
| 160 // untyped visits to non-bookmarked pages and |typed_value_| for typed visits. | 153 // untyped visits to non-bookmarked pages and |typed_value_| for typed visits. |
| 161 static float bookmark_value_; | 154 static float bookmark_value_; |
| 162 | 155 |
| 163 // Typed visits to page score this, compared to 1 for untyped visits. | 156 // 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"). | 170 // If true, we allow input terms to match in the TLD (e.g., ".com"). |
| 178 static bool allow_tld_matches_; | 171 static bool allow_tld_matches_; |
| 179 | 172 |
| 180 // If true, we allow input terms to match in the scheme (e.g., "http://"). | 173 // If true, we allow input terms to match in the scheme (e.g., "http://"). |
| 181 static bool allow_scheme_matches_; | 174 static bool allow_scheme_matches_; |
| 182 | 175 |
| 183 // The number of title words examined when computing topicality scores. | 176 // The number of title words examined when computing topicality scores. |
| 184 // Words beyond this number are ignored. | 177 // Words beyond this number are ignored. |
| 185 static size_t num_title_words_to_allow_; | 178 static size_t num_title_words_to_allow_; |
| 186 | 179 |
| 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. | 180 // |topicality_threshold_| is used to control the topicality scoring. |
| 191 // If |topicality_threshold_| > 0, then URLs with topicality-score < threshold | 181 // 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. | 182 // the threshold are given topicality score of 0. |
| 193 static float topicality_threshold_; | 183 static float topicality_threshold_; |
| 194 | 184 |
| 195 // |hqp_relevance_buckets_str_| is used to control the hqp score ranges. | 185 // Used for testing. This is a pointer to the static local variable |
| 196 // It is the string representation of |hqp_relevance_buckets_|. | 186 // |relevance_buckets| declared in GetFinalRelevancyScore(). It's not valid |
| 197 static char hqp_relevance_buckets_str_[]; | 187 // until after the first call to GetFinalRelevancyScore(). |
| 198 | 188 static std::vector<ScoreMaxRelevance>* relevance_buckets_; |
| 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 }; | 189 }; |
| 204 typedef std::vector<ScoredHistoryMatch> ScoredHistoryMatches; | 190 typedef std::vector<ScoredHistoryMatch> ScoredHistoryMatches; |
| 205 | 191 |
| 206 #endif // COMPONENTS_OMNIBOX_BROWSER_SCORED_HISTORY_MATCH_H_ | 192 #endif // COMPONENTS_OMNIBOX_BROWSER_SCORED_HISTORY_MATCH_H_ |
| OLD | NEW |