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

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

Issue 10541045: Move ScoredHistoryMatch into Its Own Set of Files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 months 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_HISTORY_SCORED_HISTORY_MATCH_H_
6 #define CHROME_BROWSER_HISTORY_SCORED_HISTORY_MATCH_H_
7 #pragma once
8
9 #include <map>
10 #include <set>
11 #include <vector>
12
13 #include "base/string16.h"
14 #include "chrome/browser/history/history_types.h"
15 #include "chrome/browser/autocomplete/history_provider_util.h"
16 #include "chrome/browser/history/in_memory_url_index_types.h"
17
18 namespace history {
19
20 // An HistoryMatch that has a score as well as metrics defining where in the
21 // history item's URL and/or page title matches have occurred.
22 struct ScoredHistoryMatch : public history::HistoryMatch {
23 ScoredHistoryMatch(); // Required by STL.
24
25 // Creates a new match with a raw score calculated for the history item given
26 // in |row| by first determining if all of the terms in |terms_vector| occur
27 // in |row| and, if so, calculating a raw score based on 1) starting position
28 // of each term in the user input, 2) completeness of each term's match,
29 // 3) ordering of the occurrence of each term (i.e. they appear in order),
30 // 4) last visit time (compared to |now|), and 5) number of visits.
31 // This raw score allows the results to be ordered and can be used
32 // to influence the final score calculated by the client of this
33 // index.
34 ScoredHistoryMatch(const URLRow& row,
35 const string16& lower_string,
36 const String16Vector& terms_vector,
37 const RowWordStarts& word_starts,
38 const base::Time now);
39 ~ScoredHistoryMatch();
40
41 // Calculates a component score based on position, ordering and total
42 // substring match size using metrics recorded in |matches|. |max_length|
43 // is the length of the string against which the terms are being searched.
44 static int ScoreComponentForMatches(const TermMatches& matches,
45 size_t max_length);
46
47 // Converts a raw value for some particular scoring factor into a score
48 // component for that factor. The conversion function is piecewise linear,
49 // with input values provided in |value_ranks| and resulting output scores
50 // from |kScoreRank| (mathematically, f(value_rank[i]) = kScoreRank[i]). A
51 // score cannot be higher than kScoreRank[0], and drops directly to 0 if
52 // lower than kScoreRank[3].
53 //
54 // 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
56 // the linear function:
57 // score = m * value + b, where
58 // m = (kScoreRank[0] - kScoreRank[1]) / (value_ranks[0] - value_ranks[1])
59 // b = value_ranks[1]
60 // Any value higher than 100 would be scored as if it were 100, and any value
61 // lower than 10 scored 0.
62 static int ScoreForValue(int value, const int* value_ranks);
63
64 // Compares two matches by score. Functor supporting URLIndexPrivateData's
65 // HistoryItemsForTerms function.
66 static bool MatchScoreGreater(const ScoredHistoryMatch& m1,
67 const ScoredHistoryMatch& m2);
68
69 // Start of functions used only in "new" scoring ------------------------
70
71 // Return a topicality score based on how many matches appear in the
72 // |url| and the page's title and where they are (e.g., at word
73 // boundaries). |url_matches| and |title_matches| provide details
74 // about where the matches in the URL and title are and what terms
75 // (identified by a term number < |num_terms|) match where.
76 // |word_starts| explains where word boundaries are.
77 static float GetTopicalityScore(const int num_terms,
78 const string16& url,
79 const TermMatches& url_matches,
80 const TermMatches& title_matches,
81 const RowWordStarts& word_starts);
82
83 // Precalculates raw_term_score_to_topicality_score, used in
84 // GetTopicalityScore().
85 static void FillInTermScoreToTopicalityScoreArray();
86
87 // Returns a recency score based on |last_visit_days_ago|, which is
88 // how many days ago the page was last visited.
89 static float GetRecencyScore(int last_visit_days_ago);
90
91 // Pre-calculates days_ago_to_recency_numerator_, used in
92 // GetRecencyScore().
93 static void FillInDaysAgoToRecencyScoreArray();
94
95 // Returns a popularity score based on |typed_count| and
96 // |visit_count|.
97 static float GetPopularityScore(int typed_count,
98 int visit_count);
99
100 // End of functions used only in "new" scoring --------------------------
101
102 // An interim score taking into consideration location and completeness
103 // of the match.
104 int raw_score;
105 TermMatches url_matches; // Term matches within the URL.
106 TermMatches title_matches; // Term matches within the page title.
107 bool can_inline; // True if this is a candidate for in-line autocompletion.
108
109 // Pre-computed information to speed up calculating recency scores.
110 // |days_ago_to_recency_score| is a simple array mapping how long
111 // ago a page was visited (in days) to the recency score we should
112 // assign it. This allows easy lookups of scores without requiring
113 // math. This is initialized upon first use of GetRecencyScore(),
114 // which calls FillInDaysAgoToRecencyScoreArray(),
115 static const int kDaysToPrecomputeRecencyScoresFor = 366;
116 static float* days_ago_to_recency_score;
117
118 // Pre-computed information to speed up calculating topicality
119 // scores. |raw_term_score_to_topicality_score| is a simple array
120 // mapping how raw terms scores (a weighted sum of the number of
121 // hits for the term, weighted by how important the hit is:
122 // hostname, path, etc.) to the topicality score we should assign
123 // it. This allows easy lookups of scores without requiring math.
124 // This is initialized upon first use of GetTopicalityScore(),
125 // which calls FillInTermScoreToTopicalityScoreArray().
126 static const int kMaxRawTermScore = 30;
127 static float* raw_term_score_to_topicality_score;
128
129 // Allows us to determing setting for use_new_scoring_ only once.
130 static bool initialized;
131
132 // Whether to use new-score or old-scoring. Set in the constructor
133 // by examining command line flags.
134 static bool use_new_scoring;
135 };
136 typedef std::vector<ScoredHistoryMatch> ScoredHistoryMatches;
137
138 } // namespace history
139
140 #endif // CHROME_BROWSER_HISTORY_SCORED_HISTORY_MATCH_H_
OLDNEW
« no previous file with comments | « chrome/browser/history/in_memory_url_index_unittest.cc ('k') | chrome/browser/history/scored_history_match.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698