Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: chrome/browser/history/scored_history_match.h

Issue 67553002: Omnibox Field Trial: Make HQP Score Bookmarks More Highly (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minor cleanup Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 17
17 class BookmarkService; 18 class BookmarkService;
18 19
19 namespace history { 20 namespace history {
20 21
21 class ScoredHistoryMatchTest; 22 class ScoredHistoryMatchTest;
22 23
23 // 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
24 // history item's URL and/or page title matches have occurred. 25 // history item's URL and/or page title matches have occurred.
25 class ScoredHistoryMatch : public history::HistoryMatch { 26 class ScoredHistoryMatch : public history::HistoryMatch {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 const ScoredHistoryMatch& m2); 59 const ScoredHistoryMatch& m2);
59 60
60 // Accessors: 61 // Accessors:
61 int raw_score() const { return raw_score_; } 62 int raw_score() const { return raw_score_; }
62 const TermMatches& url_matches() const { return url_matches_; } 63 const TermMatches& url_matches() const { return url_matches_; }
63 const TermMatches& title_matches() const { return title_matches_; } 64 const TermMatches& title_matches() const { return title_matches_; }
64 bool can_inline() const { return can_inline_; } 65 bool can_inline() const { return can_inline_; }
65 66
66 private: 67 private:
67 friend class ScoredHistoryMatchTest; 68 friend class ScoredHistoryMatchTest;
69 FRIEND_TEST(ScoredHistoryMatchTest, ScoringBookmarks);
Peter Kasting 2013/11/26 02:33:48 Nit: Any way to add accessors to the base test cla
Mark P 2013/11/26 19:31:57 Yes. Done. (Not that I think we should bother ad
68 70
69 // The number of days of recency scores to precompute. 71 // The number of days of recency scores to precompute.
70 static const int kDaysToPrecomputeRecencyScoresFor; 72 static const int kDaysToPrecomputeRecencyScoresFor;
71 73
72 // The number of raw term score buckets use; raw term scores 74 // The number of raw term score buckets use; raw term scores
73 // greater this are capped at the score of the largest bucket. 75 // greater this are capped at the score of the largest bucket.
74 static const int kMaxRawTermScore; 76 static const int kMaxRawTermScore;
75 77
76 // Return a topicality score based on how many matches appear in the 78 // Return a topicality score based on how many matches appear in the
77 // url and the page's title and where they are (e.g., at word 79 // url and the page's title and where they are (e.g., at word
78 // boundaries). Revises |url_matches_| and |title_matches_| in the 80 // boundaries). Revises |url_matches_| and |title_matches_| in the
79 // process so they only reflect matches used for scoring. (For 81 // process so they only reflect matches used for scoring. (For
80 // instance, some mid-word matches are not given credit in scoring.) 82 // instance, some mid-word matches are not given credit in scoring.)
81 float GetTopicalityScore(const int num_terms, 83 float GetTopicalityScore(const int num_terms,
82 const string16& cleaned_up_url, 84 const string16& cleaned_up_url,
83 const RowWordStarts& word_starts); 85 const RowWordStarts& word_starts);
84 86
85 // Helper function for GetTopicalityScore(). 87 // Helper function for GetTopicalityScore().
86 // Returns |term_matches| after removing all matches that are not at a 88 // Returns |term_matches| after removing all matches that are not at a
87 // word break that starts after position |start_pos|. If |start_pos| is 89 // word break that starts after position |start_pos|. If |start_pos| is
88 // string::npos, does no filtering and simply returns |term_matches|. 90 // string::npos, does no filtering and simply returns |term_matches|.
89 static TermMatches FilterTermMatchesByWordStarts( 91 static TermMatches FilterTermMatchesByWordStarts(
90 const TermMatches& term_matches, 92 const TermMatches& term_matches,
91 const WordStarts& word_starts, 93 const WordStarts& word_starts,
92 const size_t start_pos); 94 const size_t start_pos);
93 95
94 // Precalculates raw_term_score_to_topicality_score, used in 96 // Precalculates raw_term_score_to_topicality_score_, used in
95 // GetTopicalityScore(). 97 // GetTopicalityScore().
96 static void FillInTermScoreToTopicalityScoreArray(); 98 static void FillInTermScoreToTopicalityScoreArray();
97 99
98 // Returns a recency score based on |last_visit_days_ago|, which is 100 // Returns a recency score based on |last_visit_days_ago|, which is
99 // how many days ago the page was last visited. 101 // how many days ago the page was last visited.
100 static float GetRecencyScore(int last_visit_days_ago); 102 static float GetRecencyScore(int last_visit_days_ago);
101 103
102 // Pre-calculates days_ago_to_recency_numerator_, used in 104 // Pre-calculates days_ago_to_recency_numerator_, used in
103 // GetRecencyScore(). 105 // GetRecencyScore().
104 static void FillInDaysAgoToRecencyScoreArray(); 106 static void FillInDaysAgoToRecencyScoreArray();
105 107
106 // Examines the first kMaxVisitsToScore and return a score (higher is 108 // Examines the first kMaxVisitsToScore and return a score (higher is
107 // better) based the rate of visits and how often those visits are 109 // better) based the rate of visits, whether the page is bookmarked, and
108 // typed navigations (i.e., explicitly invoked by the user). 110 // how often those visits are typed navigations (i.e., explicitly
109 // |now| is passed in to avoid unnecessarily recomputing it frequently. 111 // invoked by the user). |now| is passed in to avoid unnecessarily
112 // recomputing it frequently.
110 static float GetFrecency(const base::Time& now, 113 static float GetFrecency(const base::Time& now,
114 const bool bookmarked,
111 const VisitInfoVector& visits); 115 const VisitInfoVector& visits);
112 116
113 // Combines the two component scores into a final score that's 117 // Combines the two component scores into a final score that's
114 // an appropriate value to use as a relevancy score. 118 // an appropriate value to use as a relevancy score.
115 static float GetFinalRelevancyScore( 119 static float GetFinalRelevancyScore(
116 float topicality_score, 120 float topicality_score,
117 float frecency_score); 121 float frecency_score);
118 122
119 // Sets also_do_hup_like_scoring and 123 // Sets also_do_hup_like_scoring_ and
120 // max_assigned_score_for_non_inlineable_matches based on the field 124 // max_assigned_score_for_non_inlineable_matches_ based on the field
121 // trial state. 125 // trial state.
122 static void InitializeAlsoDoHUPLikeScoringFieldAndMaxScoreField(); 126 static void InitializeAlsoDoHUPLikeScoringFieldAndMaxScoreField();
123 127
128 // Sets |bookmark_value_| based on the field trial state.
129 static void InitializeBookmarkValue();
130
124 // An interim score taking into consideration location and completeness 131 // An interim score taking into consideration location and completeness
125 // of the match. 132 // of the match.
126 int raw_score_; 133 int raw_score_;
127 134
128 // Both these TermMatches contain the set of matches that are considered 135 // Both these TermMatches contain the set of matches that are considered
129 // important. At this time, that means they exclude mid-word matches 136 // important. At this time, that means they exclude mid-word matches
130 // except in the hostname of the URL. (Technically, during early 137 // except in the hostname of the URL. (Technically, during early
131 // construction of ScoredHistoryMatch, they may contain all matches, but 138 // construction of ScoredHistoryMatch, they may contain all matches, but
132 // unimportant matches are eliminated by GetTopicalityScore(), called 139 // unimportant matches are eliminated by GetTopicalityScore(), called
133 // during construction.) 140 // during construction.)
134 // Term matches within the URL. 141 // Term matches within the URL.
135 TermMatches url_matches_; 142 TermMatches url_matches_;
136 // Term matches within the page title. 143 // Term matches within the page title.
137 TermMatches title_matches_; 144 TermMatches title_matches_;
138 145
139 // True if this is a candidate for in-line autocompletion. 146 // True if this is a candidate for in-line autocompletion.
140 bool can_inline_; 147 bool can_inline_;
141 148
142 // Pre-computed information to speed up calculating recency scores. 149 // Pre-computed information to speed up calculating recency scores.
143 // |days_ago_to_recency_score| is a simple array mapping how long 150 // |days_ago_to_recency_score_| is a simple array mapping how long
144 // ago a page was visited (in days) to the recency score we should 151 // ago a page was visited (in days) to the recency score we should
145 // assign it. This allows easy lookups of scores without requiring 152 // assign it. This allows easy lookups of scores without requiring
146 // math. This is initialized upon first use of GetRecencyScore(), 153 // math. This is initialized upon first use of GetRecencyScore(),
147 // which calls FillInDaysAgoToRecencyScoreArray(), 154 // which calls FillInDaysAgoToRecencyScoreArray(),
148 static float* days_ago_to_recency_score_; 155 static float* days_ago_to_recency_score_;
149 156
150 // Pre-computed information to speed up calculating topicality 157 // Pre-computed information to speed up calculating topicality
151 // scores. |raw_term_score_to_topicality_score| is a simple array 158 // scores. |raw_term_score_to_topicality_score_| is a simple array
152 // mapping how raw terms scores (a weighted sum of the number of 159 // mapping how raw terms scores (a weighted sum of the number of
153 // hits for the term, weighted by how important the hit is: 160 // hits for the term, weighted by how important the hit is:
154 // hostname, path, etc.) to the topicality score we should assign 161 // hostname, path, etc.) to the topicality score we should assign
155 // it. This allows easy lookups of scores without requiring math. 162 // it. This allows easy lookups of scores without requiring math.
156 // This is initialized upon first use of GetTopicalityScore(), 163 // This is initialized upon first use of GetTopicalityScore(),
157 // which calls FillInTermScoreToTopicalityScoreArray(). 164 // which calls FillInTermScoreToTopicalityScoreArray().
158 static float* raw_term_score_to_topicality_score_; 165 static float* raw_term_score_to_topicality_score_;
159 166
160 // Used so we initialize static variables only once (on first use). 167 // Used so we initialize static variables only once (on first use).
161 static bool initialized_; 168 static bool initialized_;
162 169
170 // Untyped visits to bookmarked pages score this, compared to 1 for
171 // untyped visits to non-bookmarked pages and 20 for typed visits.
172 static int bookmark_value_;
173
163 // If true, assign raw scores to be max(whatever it normally would be, 174 // If true, assign raw scores to be max(whatever it normally would be,
164 // a score that's similar to the score HistoryURL provider would assign). 175 // a score that's similar to the score HistoryURL provider would assign).
165 // This variable is set in the constructor by examining the field trial 176 // This variable is set in the constructor by examining the field trial
166 // state. 177 // state.
167 static bool also_do_hup_like_scoring_; 178 static bool also_do_hup_like_scoring_;
168 179
169 // The maximum score that can be assigned to non-inlineable matches. 180 // The maximum score that can be assigned to non-inlineable matches.
170 // This is useful because often we want inlineable matches to come 181 // This is useful because often we want inlineable matches to come
171 // first (even if they don't sometimes score as well as non-inlineable 182 // first (even if they don't sometimes score as well as non-inlineable
172 // matches) because if a non-inlineable match comes first than all matches 183 // matches) because if a non-inlineable match comes first than all matches
173 // will get demoted later in HistoryQuickProvider to non-inlineable scores. 184 // will get demoted later in HistoryQuickProvider to non-inlineable scores.
174 // Set to -1 to indicate no maximum score. 185 // Set to -1 to indicate no maximum score.
175 static int max_assigned_score_for_non_inlineable_matches_; 186 static int max_assigned_score_for_non_inlineable_matches_;
176 }; 187 };
177 typedef std::vector<ScoredHistoryMatch> ScoredHistoryMatches; 188 typedef std::vector<ScoredHistoryMatch> ScoredHistoryMatches;
178 189
179 } // namespace history 190 } // namespace history
180 191
181 #endif // CHROME_BROWSER_HISTORY_SCORED_HISTORY_MATCH_H_ 192 #endif // CHROME_BROWSER_HISTORY_SCORED_HISTORY_MATCH_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/history/scored_history_match.cc » ('j') | chrome/browser/history/scored_history_match.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698