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 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> |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 // If the row does not qualify the raw score will be 0. |bookmark_service| is | 31 // If the row does not qualify the raw score will be 0. |bookmark_service| is |
| 32 // used to determine if the match's URL is referenced by any bookmarks. | 32 // used to determine if the match's URL is referenced by any bookmarks. |
| 33 ScoredHistoryMatch(const URLRow& row, | 33 ScoredHistoryMatch(const URLRow& row, |
| 34 const string16& lower_string, | 34 const string16& lower_string, |
| 35 const String16Vector& terms_vector, | 35 const String16Vector& terms_vector, |
| 36 const RowWordStarts& word_starts, | 36 const RowWordStarts& word_starts, |
| 37 const base::Time now, | 37 const base::Time now, |
| 38 BookmarkService* bookmark_service); | 38 BookmarkService* bookmark_service); |
| 39 ~ScoredHistoryMatch(); | 39 ~ScoredHistoryMatch(); |
| 40 | 40 |
| 41 // Calculates a component score based on position, ordering and total | 41 // Calculates a component score based on position, ordering, word |
| 42 // substring match size using metrics recorded in |matches|. |max_length| | 42 // boundaries, and total substring match size using metrics recorded |
| 43 // is the length of the string against which the terms are being searched. | 43 // in |matches| and |word_starts|. |max_length| is the length of |
| 44 // the string against which the terms are being searched. | |
| 44 static int ScoreComponentForMatches(const TermMatches& matches, | 45 static int ScoreComponentForMatches(const TermMatches& matches, |
|
Bart N.
2012/11/29 17:32:26
matches -> provided_matches to make it consistent
Mark P
2012/11/29 19:36:48
Done.
| |
| 46 const WordStarts& word_starts, | |
| 45 size_t max_length); | 47 size_t max_length); |
| 46 | 48 |
| 49 // Given a set of term matches |matches| and word boundaries |word_starts|, | |
| 50 // fills in |matches_at_word_boundaries| with only the matches in |matches| | |
| 51 // that are at word boundaries. | |
| 52 static void MakeTermMatchesOnlyAtWordBoundaries( | |
| 53 const TermMatches& matches, | |
| 54 const WordStarts& word_starts, | |
| 55 TermMatches* matches_at_word_boundaries); | |
| 56 | |
| 47 // Converts a raw value for some particular scoring factor into a score | 57 // Converts a raw value for some particular scoring factor into a score |
| 48 // component for that factor. The conversion function is piecewise linear, | 58 // component for that factor. The conversion function is piecewise linear, |
| 49 // with input values provided in |value_ranks| and resulting output scores | 59 // with input values provided in |value_ranks| and resulting output scores |
| 50 // from |kScoreRank| (mathematically, f(value_rank[i]) = kScoreRank[i]). A | 60 // from |kScoreRank| (mathematically, f(value_rank[i]) = kScoreRank[i]). A |
| 51 // score cannot be higher than kScoreRank[0], and drops directly to 0 if | 61 // score cannot be higher than kScoreRank[0], and drops directly to 0 if |
| 52 // lower than kScoreRank[3]. | 62 // lower than kScoreRank[3]. |
| 53 // | 63 // |
| 54 // For example, take |value| == 70 and |value_ranks| == { 100, 50, 30, 10 }. | 64 // For example, take |value| == 70 and |value_ranks| == { 100, 50, 30, 10 }. |
| 55 // Because 70 falls between ranks 0 (100) and 1 (50), the score is given by | 65 // Because 70 falls between ranks 0 (100) and 1 (50), the score is given by |
| 56 // the linear function: | 66 // the linear function: |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 | 105 |
| 96 // Returns a popularity score based on |typed_count| and | 106 // Returns a popularity score based on |typed_count| and |
| 97 // |visit_count|. | 107 // |visit_count|. |
| 98 static float GetPopularityScore(int typed_count, | 108 static float GetPopularityScore(int typed_count, |
| 99 int visit_count); | 109 int visit_count); |
| 100 | 110 |
| 101 // Sets use_new_scoring based on command line flags and/or | 111 // Sets use_new_scoring based on command line flags and/or |
| 102 // field trial state. | 112 // field trial state. |
| 103 static void InitializeNewScoringField(); | 113 static void InitializeNewScoringField(); |
| 104 | 114 |
| 115 // Sets only_count_matches_at_word_boundaries based on the field trial state. | |
| 116 static void InitializeOnlyCountMatchesAtWordBoundariesField(); | |
| 117 | |
| 105 // Sets also_do_hup_like_scoring based on the field trial state. | 118 // Sets also_do_hup_like_scoring based on the field trial state. |
| 106 static void InitializeAlsoDoHUPLikeScoringField(); | 119 static void InitializeAlsoDoHUPLikeScoringField(); |
| 107 | 120 |
| 108 // End of functions used only in "new" scoring -------------------------- | 121 // End of functions used only in "new" scoring -------------------------- |
| 109 | 122 |
| 110 // An interim score taking into consideration location and completeness | 123 // An interim score taking into consideration location and completeness |
| 111 // of the match. | 124 // of the match. |
| 112 int raw_score; | 125 int raw_score; |
| 113 TermMatches url_matches; // Term matches within the URL. | 126 TermMatches url_matches; // Term matches within the URL. |
| 114 TermMatches title_matches; // Term matches within the page title. | 127 TermMatches title_matches; // Term matches within the page title. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 127 // scores. |raw_term_score_to_topicality_score| is a simple array | 140 // scores. |raw_term_score_to_topicality_score| is a simple array |
| 128 // mapping how raw terms scores (a weighted sum of the number of | 141 // mapping how raw terms scores (a weighted sum of the number of |
| 129 // hits for the term, weighted by how important the hit is: | 142 // hits for the term, weighted by how important the hit is: |
| 130 // hostname, path, etc.) to the topicality score we should assign | 143 // hostname, path, etc.) to the topicality score we should assign |
| 131 // it. This allows easy lookups of scores without requiring math. | 144 // it. This allows easy lookups of scores without requiring math. |
| 132 // This is initialized upon first use of GetTopicalityScore(), | 145 // This is initialized upon first use of GetTopicalityScore(), |
| 133 // which calls FillInTermScoreToTopicalityScoreArray(). | 146 // which calls FillInTermScoreToTopicalityScoreArray(). |
| 134 static const int kMaxRawTermScore = 30; | 147 static const int kMaxRawTermScore = 30; |
| 135 static float* raw_term_score_to_topicality_score; | 148 static float* raw_term_score_to_topicality_score; |
| 136 | 149 |
| 137 // Allows us to determing setting for use_new_scoring_ only once. | 150 // Allows us to determing setting for use_new_scoring_ and other startup |
|
Bart N.
2012/11/29 17:32:26
-> |use_new_scoring| (extra _)?
Mark P
2012/11/29 19:36:48
Rephrased entirely.
| |
| 151 // calculations only once. | |
| 138 static bool initialized_; | 152 static bool initialized_; |
| 139 | 153 |
| 140 // Whether to use new-scoring or old-scoring. Set in the | 154 // Whether to use new-scoring or old-scoring. Set in the |
| 141 // constructor by examining command line flags and field trial | 155 // constructor by examining command line flags and field trial |
| 142 // state. Note that new-scoring has to do with a new version of the | 156 // state. Note that new-scoring has to do with a new version of the |
| 143 // ordinary scoring done here. It has nothing to do with and no | 157 // ordinary scoring done here. It has nothing to do with and no |
| 144 // affect on HistoryURLProvider-like scoring that can happen in this | 158 // affect on HistoryURLProvider-like scoring that can happen in this |
| 145 // class as well (see boolean below). | 159 // class as well (see boolean below). |
| 146 static bool use_new_scoring; | 160 static bool use_new_scoring; |
| 147 | 161 |
| 162 // If true, we ignore all matches that are in the middle of a word. | |
| 163 static bool only_count_matches_at_word_boundaries; | |
| 164 | |
| 148 // If true, assign raw scores to be max(whatever it normally would be, | 165 // If true, assign raw scores to be max(whatever it normally would be, |
| 149 // a score that's similar to the score HistoryURL provider would assign). | 166 // a score that's similar to the score HistoryURL provider would assign). |
| 150 // This variable is set in the constructor by examining the field trial | 167 // This variable is set in the constructor by examining the field trial |
| 151 // state. | 168 // state. |
| 152 static bool also_do_hup_like_scoring; | 169 static bool also_do_hup_like_scoring; |
| 153 }; | 170 }; |
| 154 typedef std::vector<ScoredHistoryMatch> ScoredHistoryMatches; | 171 typedef std::vector<ScoredHistoryMatch> ScoredHistoryMatches; |
| 155 | 172 |
| 156 } // namespace history | 173 } // namespace history |
| 157 | 174 |
| 158 #endif // CHROME_BROWSER_HISTORY_SCORED_HISTORY_MATCH_H_ | 175 #endif // CHROME_BROWSER_HISTORY_SCORED_HISTORY_MATCH_H_ |
| OLD | NEW |