Index: components/history/core/browser/scored_history_match.h |
diff --git a/chrome/browser/history/scored_history_match.h b/components/history/core/browser/scored_history_match.h |
similarity index 61% |
rename from chrome/browser/history/scored_history_match.h |
rename to components/history/core/browser/scored_history_match.h |
index 15a37e7bd73673dc4efe2ca93a5e29a06d3e8d59..42ce3c95b91be468d1a5d0eac4bb67219d8a853d 100644 |
--- a/chrome/browser/history/scored_history_match.h |
+++ b/components/history/core/browser/scored_history_match.h |
@@ -2,14 +2,14 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#ifndef CHROME_BROWSER_HISTORY_SCORED_HISTORY_MATCH_H_ |
-#define CHROME_BROWSER_HISTORY_SCORED_HISTORY_MATCH_H_ |
+#ifndef COMPONENTS_HISTORY_CORE_BROWSER_SCORED_HISTORY_MATCH_H_ |
+#define COMPONENTS_HISTORY_CORE_BROWSER_SCORED_HISTORY_MATCH_H_ |
-#include <map> |
-#include <set> |
+#include <string> |
#include <vector> |
#include "base/strings/string16.h" |
+#include "base/time/time.h" |
#include "components/history/core/browser/history_match.h" |
#include "components/history/core/browser/history_types.h" |
#include "components/history/core/browser/in_memory_url_index_types.h" |
@@ -17,8 +17,8 @@ |
namespace history { |
-class HistoryClient; |
class ScoredHistoryMatchTest; |
+class ScoredHistoryMatchClient; |
// An HistoryMatch that has a score as well as metrics defining where in the |
// history item's URL and/or page title matches have occurred. |
@@ -54,9 +54,17 @@ class ScoredHistoryMatch : public history::HistoryMatch { |
const WordStarts& terms_to_word_starts_offsets, |
const RowWordStarts& word_starts, |
const base::Time now, |
- HistoryClient* history_client); |
+ const ScoredHistoryMatchClient* client); |
~ScoredHistoryMatch(); |
+ // Initialize static state, must be called before any other method. |
+ static void Init(); |
+ |
+ // Configure static state depending on field trials. |
+ static void SetFieldTrials(int bookmark_value, |
+ bool allow_tld_matches, |
+ bool allow_scheme_matches); |
+ |
// Compares two matches by score. Functor supporting URLIndexPrivateData's |
// HistoryItemsForTerms function. Looks at particular fields within |
// with url_info to make tie-breaking a bit smarter. |
@@ -88,13 +96,6 @@ class ScoredHistoryMatch : public history::HistoryMatch { |
FRIEND_TEST_ALL_PREFIXES(ScoredHistoryMatchTest, ScoringScheme); |
FRIEND_TEST_ALL_PREFIXES(ScoredHistoryMatchTest, ScoringTLD); |
- // The number of days of recency scores to precompute. |
- static const int kDaysToPrecomputeRecencyScoresFor; |
- |
- // The number of raw term score buckets use; raw term scores |
- // greater this are capped at the score of the largest bucket. |
- static const int kMaxRawTermScore; |
- |
// Return a topicality score based on how many matches appear in the |
// url and the page's title and where they are (e.g., at word |
// boundaries). Revises |url_matches_| and |title_matches_| in the |
@@ -103,19 +104,8 @@ class ScoredHistoryMatch : public history::HistoryMatch { |
float GetTopicalityScore(const int num_terms, |
const base::string16& cleaned_up_url, |
const WordStarts& terms_to_word_starts_offsets, |
- const RowWordStarts& word_starts); |
- |
- // Precalculates raw_term_score_to_topicality_score_, used in |
- // GetTopicalityScore(). |
- static void FillInTermScoreToTopicalityScoreArray(); |
- |
- // Returns a recency score based on |last_visit_days_ago|, which is |
- // how many days ago the page was last visited. |
- static float GetRecencyScore(int last_visit_days_ago); |
- |
- // Pre-calculates days_ago_to_recency_numerator_, used in |
- // GetRecencyScore(). |
- static void FillInDaysAgoToRecencyScoreArray(); |
+ const RowWordStarts& word_starts, |
+ const ScoredHistoryMatchClient* client); |
// Examines the first kMaxVisitsToScore and return a score (higher is |
// better) based the rate of visits, whether the page is bookmarked, and |
@@ -124,19 +114,13 @@ class ScoredHistoryMatch : public history::HistoryMatch { |
// recomputing it frequently. |
static float GetFrequency(const base::Time& now, |
const bool bookmarked, |
- const VisitInfoVector& visits); |
+ const VisitInfoVector& visits, |
+ const ScoredHistoryMatchClient* client); |
// Combines the two component scores into a final score that's |
// an appropriate value to use as a relevancy score. |
- static float GetFinalRelevancyScore( |
- float topicality_score, |
- float frequency_score); |
- |
- // Sets |also_do_hup_like_scoring_|, |
- // |max_assigned_score_for_non_inlineable_matches_|, |bookmark_value_|, |
- // |allow_tld_matches_|, and |allow_scheme_matches_| based on the field |
- // trial state. |
- static void Init(); |
+ static float GetFinalRelevancyScore(float topicality_score, |
+ float frequency_score); |
// An interim score taking into consideration location and completeness |
// of the match. |
@@ -155,54 +139,10 @@ class ScoredHistoryMatch : public history::HistoryMatch { |
// True if this is a candidate for in-line autocompletion. |
bool can_inline_; |
- |
- // Pre-computed information to speed up calculating recency scores. |
- // |days_ago_to_recency_score_| is a simple array mapping how long |
- // ago a page was visited (in days) to the recency score we should |
- // assign it. This allows easy lookups of scores without requiring |
- // math. This is initialized upon first use of GetRecencyScore(), |
- // which calls FillInDaysAgoToRecencyScoreArray(), |
- static float* days_ago_to_recency_score_; |
- |
- // Pre-computed information to speed up calculating topicality |
- // scores. |raw_term_score_to_topicality_score_| is a simple array |
- // mapping how raw terms scores (a weighted sum of the number of |
- // hits for the term, weighted by how important the hit is: |
- // hostname, path, etc.) to the topicality score we should assign |
- // it. This allows easy lookups of scores without requiring math. |
- // This is initialized upon first use of GetTopicalityScore(), |
- // which calls FillInTermScoreToTopicalityScoreArray(). |
- static float* raw_term_score_to_topicality_score_; |
- |
- // Used so we initialize static variables only once (on first use). |
- static bool initialized_; |
- |
- // Untyped visits to bookmarked pages score this, compared to 1 for |
- // untyped visits to non-bookmarked pages and 20 for typed visits. |
- static int bookmark_value_; |
- |
- // If true, we allow input terms to match in the TLD (e.g., .com). |
- static bool allow_tld_matches_; |
- |
- // If true, we allow input terms to match in the scheme (e.g., http://). |
- static bool allow_scheme_matches_; |
- |
- // If true, assign raw scores to be max(whatever it normally would be, |
- // a score that's similar to the score HistoryURL provider would assign). |
- // This variable is set in the constructor by examining the field trial |
- // state. |
- static bool also_do_hup_like_scoring_; |
- |
- // The maximum score that can be assigned to non-inlineable matches. |
- // This is useful because often we want inlineable matches to come |
- // first (even if they don't sometimes score as well as non-inlineable |
- // matches) because if a non-inlineable match comes first than all matches |
- // will get demoted later in HistoryQuickProvider to non-inlineable scores. |
- // Set to -1 to indicate no maximum score. |
- static int max_assigned_score_for_non_inlineable_matches_; |
}; |
+ |
typedef std::vector<ScoredHistoryMatch> ScoredHistoryMatches; |
} // namespace history |
-#endif // CHROME_BROWSER_HISTORY_SCORED_HISTORY_MATCH_H_ |
+#endif // COMPONENTS_HISTORY_CORE_BROWSER_SCORED_HISTORY_MATCH_H_ |