| 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> |
| 11 | 11 |
| 12 #include "base/string16.h" | 12 #include "base/string16.h" |
| 13 #include "chrome/browser/history/history_types.h" | 13 #include "chrome/browser/history/history_types.h" |
| 14 #include "chrome/browser/autocomplete/history_provider_util.h" | 14 #include "chrome/browser/autocomplete/history_provider_util.h" |
| 15 #include "chrome/browser/history/in_memory_url_index_types.h" | 15 #include "chrome/browser/history/in_memory_url_index_types.h" |
| 16 | 16 |
| 17 class BookmarkService; |
| 18 |
| 17 namespace history { | 19 namespace history { |
| 18 | 20 |
| 19 // An HistoryMatch that has a score as well as metrics defining where in the | 21 // An HistoryMatch that has a score as well as metrics defining where in the |
| 20 // history item's URL and/or page title matches have occurred. | 22 // history item's URL and/or page title matches have occurred. |
| 21 struct ScoredHistoryMatch : public history::HistoryMatch { | 23 struct ScoredHistoryMatch : public history::HistoryMatch { |
| 22 ScoredHistoryMatch(); // Required by STL. | 24 ScoredHistoryMatch(); // Required by STL. |
| 23 | 25 |
| 24 // Creates a new match with a raw score calculated for the history item given | 26 // Creates a new match with a raw score calculated for the history item given |
| 25 // in |row|. First determines if the row qualifies by seeing if all of the | 27 // in |row|. First determines if the row qualifies by seeing if all of the |
| 26 // terms in |terms_vector| occur in |row|. If so, calculates a raw score. | 28 // terms in |terms_vector| occur in |row|. If so, calculates a raw score. |
| 27 // This raw score allows the results to be ordered and can be used to | 29 // This raw score allows the results to be ordered and can be used to |
| 28 // influence the final score calculated by the client of this index. | 30 // influence the final score calculated by the client of this index. |
| 29 // If the row does not qualify the raw score will be 0. | 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. |
| 30 ScoredHistoryMatch(const URLRow& row, | 33 ScoredHistoryMatch(const URLRow& row, |
| 31 const string16& lower_string, | 34 const string16& lower_string, |
| 32 const String16Vector& terms_vector, | 35 const String16Vector& terms_vector, |
| 33 const RowWordStarts& word_starts, | 36 const RowWordStarts& word_starts, |
| 34 const base::Time now); | 37 const base::Time now, |
| 38 BookmarkService* bookmark_service); |
| 35 ~ScoredHistoryMatch(); | 39 ~ScoredHistoryMatch(); |
| 36 | 40 |
| 37 // Calculates a component score based on position, ordering and total | 41 // Calculates a component score based on position, ordering and total |
| 38 // substring match size using metrics recorded in |matches|. |max_length| | 42 // substring match size using metrics recorded in |matches|. |max_length| |
| 39 // is the length of the string against which the terms are being searched. | 43 // is the length of the string against which the terms are being searched. |
| 40 static int ScoreComponentForMatches(const TermMatches& matches, | 44 static int ScoreComponentForMatches(const TermMatches& matches, |
| 41 size_t max_length); | 45 size_t max_length); |
| 42 | 46 |
| 43 // Converts a raw value for some particular scoring factor into a score | 47 // Converts a raw value for some particular scoring factor into a score |
| 44 // component for that factor. The conversion function is piecewise linear, | 48 // component for that factor. The conversion function is piecewise linear, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 135 |
| 132 // Whether to use new-score or old-scoring. Set in the constructor | 136 // Whether to use new-score or old-scoring. Set in the constructor |
| 133 // by examining command line flags. | 137 // by examining command line flags. |
| 134 static bool use_new_scoring; | 138 static bool use_new_scoring; |
| 135 }; | 139 }; |
| 136 typedef std::vector<ScoredHistoryMatch> ScoredHistoryMatches; | 140 typedef std::vector<ScoredHistoryMatch> ScoredHistoryMatches; |
| 137 | 141 |
| 138 } // namespace history | 142 } // namespace history |
| 139 | 143 |
| 140 #endif // CHROME_BROWSER_HISTORY_SCORED_HISTORY_MATCH_H_ | 144 #endif // CHROME_BROWSER_HISTORY_SCORED_HISTORY_MATCH_H_ |
| OLD | NEW |