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

Side by Side Diff: components/omnibox/browser/scored_history_match.h

Issue 2541143002: Omnibox - Boost Frequency Scores Based on Number of Matching Pages (Closed)
Patch Set: fix leak Created 4 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
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 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 #include "components/omnibox/browser/omnibox_field_trial.h"
19 20
20 class ScoredHistoryMatchTest; 21 class ScoredHistoryMatchTest;
21 22
22 // An HistoryMatch that has a score as well as metrics defining where in the 23 // 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. 24 // history item's URL and/or page title matches have occurred.
24 struct ScoredHistoryMatch : public history::HistoryMatch { 25 struct ScoredHistoryMatch : public history::HistoryMatch {
25 // ScoreMaxRelevance maps from an intermediate-score to the maximum 26 // ScoreMaxRelevance maps from an intermediate-score to the maximum
26 // final-relevance score given to a URL for this intermediate score. 27 // final-relevance score given to a URL for this intermediate score.
27 // This is used to store the score ranges of HQP relevance buckets. 28 // This is used to store the score ranges of HQP relevance buckets.
28 // Please see GetFinalRelevancyScore() for details. 29 // Please see GetFinalRelevancyScore() for details.
29 typedef std::pair<double, int> ScoreMaxRelevance; 30 typedef std::pair<double, int> ScoreMaxRelevance;
30 31
31 // Required for STL, we don't use this directly. 32 // Required for STL, we don't use this directly.
32 ScoredHistoryMatch(); 33 ScoredHistoryMatch();
33 ScoredHistoryMatch(const ScoredHistoryMatch& other); 34 ScoredHistoryMatch(const ScoredHistoryMatch& other);
34 35
35 // Initializes the ScoredHistoryMatch with a raw score calculated for the 36 // Initializes the ScoredHistoryMatch with a raw score calculated for the
36 // history item given in |row| with recent visits as indicated in |visits|. It 37 // 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 38 // 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 39 // |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 40 // score is in part determined by whether the matches occur at word
40 // boundaries, the locations of which are stored in |word_starts|. For some 41 // boundaries, the locations of which are stored in |word_starts|. For some
41 // terms, it's appropriate to look for the word boundary within the term. For 42 // terms, it's appropriate to look for the word boundary within the term. For
42 // instance, the term ".net" should look for a word boundary at the "n". 43 // instance, the term ".net" should look for a word boundary at the "n".
43 // These offsets (".net" should have an offset of 1) come from 44 // These offsets (".net" should have an offset of 1) come from
44 // |terms_to_word_starts_offsets|. |is_url_bookmarked| indicates whether the 45 // |terms_to_word_starts_offsets|. |is_url_bookmarked| indicates whether the
45 // match's URL is referenced by any bookmarks, which can also affect the raw 46 // match's URL is referenced by any bookmarks, which can also affect the raw
46 // score. The raw score allows the matches to be ordered and can be used to 47 // score. |num_matching_pages| indicates how many URLs in the eligible URL
47 // influence the final score calculated by the client of this index. If the 48 // database match the user's input; it can also affect the raw score. The raw
48 // row does not qualify the raw score will be 0. 49 // score allows the matches to be ordered and can be used to influence the
50 // final score calculated by the client of this index. If the row does not
51 // qualify the raw score will be 0.
49 ScoredHistoryMatch(const history::URLRow& row, 52 ScoredHistoryMatch(const history::URLRow& row,
50 const VisitInfoVector& visits, 53 const VisitInfoVector& visits,
51 const base::string16& lower_string, 54 const base::string16& lower_string,
52 const String16Vector& terms_vector, 55 const String16Vector& terms_vector,
53 const WordStarts& terms_to_word_starts_offsets, 56 const WordStarts& terms_to_word_starts_offsets,
54 const RowWordStarts& word_starts, 57 const RowWordStarts& word_starts,
55 bool is_url_bookmarked, 58 bool is_url_bookmarked,
59 size_t num_matching_pages,
56 base::Time now); 60 base::Time now);
57 61
58 ~ScoredHistoryMatch(); 62 ~ScoredHistoryMatch();
59 63
60 // Compares two matches by score. Functor supporting URLIndexPrivateData's 64 // Compares two matches by score. Functor supporting URLIndexPrivateData's
61 // HistoryItemsForTerms function. Looks at particular fields within 65 // HistoryItemsForTerms function. Looks at particular fields within
62 // with url_info to make tie-breaking a bit smarter. 66 // with url_info to make tie-breaking a bit smarter.
63 static bool MatchScoreGreater(const ScoredHistoryMatch& m1, 67 static bool MatchScoreGreater(const ScoredHistoryMatch& m1,
64 const ScoredHistoryMatch& m2); 68 const ScoredHistoryMatch& m2);
65 69
(...skipping 20 matching lines...) Expand all
86 // unimportant matches are eliminated by GetTopicalityScore(), called 90 // unimportant matches are eliminated by GetTopicalityScore(), called
87 // during construction.) 91 // during construction.)
88 92
89 // Term matches within the URL. 93 // Term matches within the URL.
90 TermMatches url_matches; 94 TermMatches url_matches;
91 // Term matches within the page title. 95 // Term matches within the page title.
92 TermMatches title_matches; 96 TermMatches title_matches;
93 97
94 private: 98 private:
95 friend class ScoredHistoryMatchTest; 99 friend class ScoredHistoryMatchTest;
100 FRIEND_TEST_ALL_PREFIXES(ScoredHistoryMatchTest, GetDocumentSpecificityScore);
96 FRIEND_TEST_ALL_PREFIXES(ScoredHistoryMatchTest, GetFinalRelevancyScore); 101 FRIEND_TEST_ALL_PREFIXES(ScoredHistoryMatchTest, GetFinalRelevancyScore);
97 FRIEND_TEST_ALL_PREFIXES(ScoredHistoryMatchTest, GetFrequency); 102 FRIEND_TEST_ALL_PREFIXES(ScoredHistoryMatchTest, GetFrequency);
98 FRIEND_TEST_ALL_PREFIXES(ScoredHistoryMatchTest, GetHQPBucketsFromString); 103 FRIEND_TEST_ALL_PREFIXES(ScoredHistoryMatchTest, GetHQPBucketsFromString);
99 FRIEND_TEST_ALL_PREFIXES(ScoredHistoryMatchTest, ScoringBookmarks); 104 FRIEND_TEST_ALL_PREFIXES(ScoredHistoryMatchTest, ScoringBookmarks);
100 FRIEND_TEST_ALL_PREFIXES(ScoredHistoryMatchTest, ScoringScheme); 105 FRIEND_TEST_ALL_PREFIXES(ScoredHistoryMatchTest, ScoringScheme);
101 FRIEND_TEST_ALL_PREFIXES(ScoredHistoryMatchTest, ScoringTLD); 106 FRIEND_TEST_ALL_PREFIXES(ScoredHistoryMatchTest, ScoringTLD);
102 107
103 // Initialize ScoredHistoryMatch statics. Must be called before any other 108 // Initialize ScoredHistoryMatch statics. Must be called before any other
104 // method of ScoredHistoryMatch and before creating any instances. 109 // method of ScoredHistoryMatch and before creating any instances.
105 static void Init(); 110 static void Init();
(...skipping 15 matching lines...) Expand all
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 // Returns a document specificity score based on how many pages matched the
137 // user's input.
138 float GetDocumentSpecificityScore(size_t num_matching_pages) const;
139
140 // Combines the three component scores into a final score that's
132 // an appropriate value to use as a relevancy score. Scoring buckets are 141 // an appropriate value to use as a relevancy score. Scoring buckets are
133 // specified through |hqp_relevance_buckets|. Please see the function 142 // specified through |hqp_relevance_buckets|. Please see the function
134 // implementation for more details. 143 // implementation for more details.
135 static float GetFinalRelevancyScore( 144 static float GetFinalRelevancyScore(
136 float topicality_score, 145 float topicality_score,
137 float frequency_score, 146 float frequency_score,
147 float specificity_score,
138 const std::vector<ScoreMaxRelevance>& hqp_relevance_buckets); 148 const std::vector<ScoreMaxRelevance>& hqp_relevance_buckets);
139 149
140 // Initializes the HQP experimental params: |hqp_relevance_buckets_| 150 // Initializes the HQP experimental params: |hqp_relevance_buckets_|
141 // to default buckets. If hqp experimental scoring is enabled, it 151 // to default buckets. If hqp experimental scoring is enabled, it
142 // fetches the |hqp_experimental_scoring_enabled_|, |topicality_threshold_| 152 // fetches the |hqp_experimental_scoring_enabled_|, |topicality_threshold_|
143 // and |hqp_relevance_buckets_| from omnibox field trials. 153 // and |hqp_relevance_buckets_| from omnibox field trials.
144 static void InitHQPExperimentalParams(); 154 static void InitHQPExperimentalParams();
145 155
146 // Helper function to parse the string containing the scoring buckets. 156 // Helper function to parse the string containing the scoring buckets.
147 // For example, 157 // For example,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 static float topicality_threshold_; 203 static float topicality_threshold_;
194 204
195 // |hqp_relevance_buckets_str_| is used to control the hqp score ranges. 205 // |hqp_relevance_buckets_str_| is used to control the hqp score ranges.
196 // It is the string representation of |hqp_relevance_buckets_|. 206 // It is the string representation of |hqp_relevance_buckets_|.
197 static char hqp_relevance_buckets_str_[]; 207 static char hqp_relevance_buckets_str_[];
198 208
199 // |hqp_relevance_buckets_| gives mapping from (topicality*frequency) 209 // |hqp_relevance_buckets_| gives mapping from (topicality*frequency)
200 // to the final relevance scoring. Please see GetFinalRelevancyScore() 210 // to the final relevance scoring. Please see GetFinalRelevancyScore()
201 // for more details and scoring method. 211 // for more details and scoring method.
202 static std::vector<ScoreMaxRelevance>* hqp_relevance_buckets_; 212 static std::vector<ScoreMaxRelevance>* hqp_relevance_buckets_;
213
214 // Used for testing. If this point is not null, it overrides the static
Peter Kasting 2016/12/10 02:22:26 Nit: pointer
Mark P 2016/12/11 05:11:37 Done.
215 // local variable |default_num_matches_to_document_specificity_score|
216 // declared in GetDocumentSpecificityScore().
217 static OmniboxFieldTrial::NumMatchesScores*
218 num_matches_to_document_specificity_score_override_;
203 }; 219 };
204 typedef std::vector<ScoredHistoryMatch> ScoredHistoryMatches; 220 typedef std::vector<ScoredHistoryMatch> ScoredHistoryMatches;
205 221
206 #endif // COMPONENTS_OMNIBOX_BROWSER_SCORED_HISTORY_MATCH_H_ 222 #endif // COMPONENTS_OMNIBOX_BROWSER_SCORED_HISTORY_MATCH_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698