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

Side by Side Diff: chrome/browser/history/url_index_private_data.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
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 CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_ 5 #ifndef CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_
6 #define CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_ 6 #define CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_
7 #pragma once 7 #pragma once
8 8
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 11
12 #include "base/file_path.h" 12 #include "base/file_path.h"
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "chrome/browser/history/in_memory_url_index_types.h" 15 #include "chrome/browser/history/in_memory_url_index_types.h"
16 #include "chrome/browser/history/in_memory_url_index_cache.pb.h" 16 #include "chrome/browser/history/in_memory_url_index_cache.pb.h"
17 #include "chrome/browser/history/scored_history_match.h"
17 #include "content/public/browser/notification_details.h" 18 #include "content/public/browser/notification_details.h"
18 19
19 class HistoryQuickProviderTest; 20 class HistoryQuickProviderTest;
20 21
21 namespace in_memory_url_index { 22 namespace in_memory_url_index {
22 class InMemoryURLIndexCacheItem; 23 class InMemoryURLIndexCacheItem;
23 } 24 }
24 25
25 namespace history { 26 namespace history {
26 27
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 82
82 ~SearchTermCacheItem(); 83 ~SearchTermCacheItem();
83 84
84 WordIDSet word_id_set_; 85 WordIDSet word_id_set_;
85 HistoryIDSet history_id_set_; 86 HistoryIDSet history_id_set_;
86 bool used_; // True if this item has been used for the current term search. 87 bool used_; // True if this item has been used for the current term search.
87 }; 88 };
88 typedef std::map<string16, SearchTermCacheItem> SearchTermCacheMap; 89 typedef std::map<string16, SearchTermCacheItem> SearchTermCacheMap;
89 90
90 // A helper class which performs the final filter on each candidate 91 // A helper class which performs the final filter on each candidate
91 // history URL match, inserting accepted matches into |scored_matches_| 92 // history URL match, inserting accepted matches into |scored_matches_|.
92 // and trimming the maximum number of matches to 10.
93 class AddHistoryMatch : public std::unary_function<HistoryID, void> { 93 class AddHistoryMatch : public std::unary_function<HistoryID, void> {
94 public: 94 public:
95 AddHistoryMatch(const URLIndexPrivateData& private_data, 95 AddHistoryMatch(const URLIndexPrivateData& private_data,
96 const string16& lower_string, 96 const string16& lower_string,
97 const String16Vector& lower_terms, 97 const String16Vector& lower_terms,
98 const base::Time now); 98 const base::Time now);
99 ~AddHistoryMatch(); 99 ~AddHistoryMatch();
100 100
101 void operator()(const HistoryID history_id); 101 void operator()(const HistoryID history_id);
102 102
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // exist and it meets the minimum 'quick' criteria. If the row already exists 209 // exist and it meets the minimum 'quick' criteria. If the row already exists
210 // in the index then the index will be updated if the row still meets the 210 // in the index then the index will be updated if the row still meets the
211 // criteria, otherwise the row will be removed from the index. Returns true 211 // criteria, otherwise the row will be removed from the index. Returns true
212 // if the index was actually updated. |languages| gives a list of language 212 // if the index was actually updated. |languages| gives a list of language
213 // encodings by which the URLs and page titles are broken down into words and 213 // encodings by which the URLs and page titles are broken down into words and
214 // characters. |scheme_whitelist| is used to filter non-qualifying schemes. 214 // characters. |scheme_whitelist| is used to filter non-qualifying schemes.
215 bool UpdateURL(const URLRow& row, 215 bool UpdateURL(const URLRow& row,
216 const std::string& languages, 216 const std::string& languages,
217 const std::set<std::string>& scheme_whitelist); 217 const std::set<std::string>& scheme_whitelist);
218 218
219 // Deletes indexing data for the history item with the URL given in |url|. 219 // Deletes index data for the history item with the given |url|.
220 // The item may not have actually been indexed, which is the case if it did 220 // The item may not have actually been indexed, which is the case if it did
221 // not previously meet minimum 'quick' criteria. Returns true if the index 221 // not previously meet minimum 'quick' criteria. Returns true if the index
222 // was actually updated. 222 // was actually updated.
223 bool DeleteURL(const GURL& url); 223 bool DeleteURL(const GURL& url);
224 224
225 // Parses and indexes the words in the URL and page title of |row| and 225 // Parses and indexes the words in the URL and page title of |row| and
226 // calculate the word starts in each, saving the starts in |word_starts|. 226 // calculate the word starts in each, saving the starts in |word_starts|.
227 // |languages| gives a list of language encodings by which the URLs and page 227 // |languages| gives a list of language encodings by which the URLs and page
228 // titles are broken down into words and characters. 228 // titles are broken down into words and characters.
229 void AddRowWordsToIndex(const URLRow& row, 229 void AddRowWordsToIndex(const URLRow& row,
(...skipping 22 matching lines...) Expand all
252 void ResetSearchTermCache(); 252 void ResetSearchTermCache();
253 253
254 // Composes a set of history item IDs by intersecting the set for each word 254 // Composes a set of history item IDs by intersecting the set for each word
255 // in |unsorted_words|. 255 // in |unsorted_words|.
256 HistoryIDSet HistoryIDSetFromWords(const String16Vector& unsorted_words); 256 HistoryIDSet HistoryIDSetFromWords(const String16Vector& unsorted_words);
257 257
258 // Helper function to HistoryIDSetFromWords which composes a set of history 258 // Helper function to HistoryIDSetFromWords which composes a set of history
259 // ids for the given term given in |term|. 259 // ids for the given term given in |term|.
260 HistoryIDSet HistoryIDsForTerm(const string16& term); 260 HistoryIDSet HistoryIDsForTerm(const string16& term);
261 261
262 // Calculates a raw score for this history item by first determining
263 // if all of the terms in |terms_vector| occur in |row| and, if so,
264 // calculating a raw score based on 1) starting position of each term
265 // in the user input, 2) completeness of each term's match, 3) ordering
266 // of the occurrence of each term (i.e. they appear in order), 4) last
267 // visit time (compared to |now|), and 5) number of visits.
268 // This raw score allows the results to be ordered and can be used
269 // to influence the final score calculated by the client of this
270 // index. Returns a ScoredHistoryMatch structure with the raw score and
271 // substring matching metrics.
272 ScoredHistoryMatch ScoredMatchForURL(
273 const URLRow& row,
274 const string16& lower_string,
275 const String16Vector& terms_vector,
276 const RowWordStarts& word_starts,
277 const base::Time now) const;
278
279 // Calculates a component score based on position, ordering and total
280 // substring match size using metrics recorded in |matches|. |max_length|
281 // is the length of the string against which the terms are being searched.
282 // Only used in "old" scoring.
283 static int ScoreComponentForMatches(const TermMatches& matches,
284 size_t max_length);
285
286 // Start of functions used only in "new" scoring ------------------------
287
288 // Return a topicality score based on how many matches appear in the
289 // |url| and the page's title and where they are (e.g., at word
290 // boundaries). |url_matches| and |title_matches| provide details
291 // about where the matches in the URL and title are and what terms
292 // (identified by a term number < |num_terms|) match where.
293 // |word_starts| explains where word boundaries are.
294 static float GetTopicalityScore(const int num_terms,
295 const string16& url,
296 const TermMatches& url_matches,
297 const TermMatches& title_matches,
298 const RowWordStarts& word_starts);
299
300 // Precalculates raw_term_score_to_topicality_score_, used in
301 // GetTopicalityScore().
302 static void FillInTermScoreToTopicalityScoreArray();
303
304 // Returns a recency score based on |last_visit_days_ago|, which is
305 // how many days ago the page was last visited.
306 static float GetRecencyScore(int last_visit_days_ago);
307
308 // Pre-calculates days_ago_to_recency_numerator_, used in
309 // GetRecencyScore().
310 static void FillInDaysAgoToRecencyScoreArray();
311
312 // Returns a popularity score based on |typed_count| and
313 // |visit_count|.
314 static float GetPopularityScore(int typed_count,
315 int visit_count);
316
317 // End of functions used only in "new" scoring --------------------------
318
319 // Encode a data structure into the protobuf |cache|. 262 // Encode a data structure into the protobuf |cache|.
320 void SavePrivateData(imui::InMemoryURLIndexCacheItem* cache) const; 263 void SavePrivateData(imui::InMemoryURLIndexCacheItem* cache) const;
321 void SaveWordList(imui::InMemoryURLIndexCacheItem* cache) const; 264 void SaveWordList(imui::InMemoryURLIndexCacheItem* cache) const;
322 void SaveWordMap(imui::InMemoryURLIndexCacheItem* cache) const; 265 void SaveWordMap(imui::InMemoryURLIndexCacheItem* cache) const;
323 void SaveCharWordMap(imui::InMemoryURLIndexCacheItem* cache) const; 266 void SaveCharWordMap(imui::InMemoryURLIndexCacheItem* cache) const;
324 void SaveWordIDHistoryMap(imui::InMemoryURLIndexCacheItem* cache) const; 267 void SaveWordIDHistoryMap(imui::InMemoryURLIndexCacheItem* cache) const;
325 void SaveHistoryInfoMap(imui::InMemoryURLIndexCacheItem* cache) const; 268 void SaveHistoryInfoMap(imui::InMemoryURLIndexCacheItem* cache) const;
326 void SaveWordStartsMap(imui::InMemoryURLIndexCacheItem* cache) const; 269 void SaveWordStartsMap(imui::InMemoryURLIndexCacheItem* cache) const;
327 270
328 // Decode a data structure from the protobuf |cache|. Return false if there 271 // Decode a data structure from the protobuf |cache|. Return false if there
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 // A one-to-one mapping from HistoryID to the history item data governing 330 // A one-to-one mapping from HistoryID to the history item data governing
388 // index inclusion and relevance scoring. 331 // index inclusion and relevance scoring.
389 HistoryInfoMap history_info_map_; 332 HistoryInfoMap history_info_map_;
390 333
391 // A one-to-one mapping from HistoryID to the word starts detected in each 334 // A one-to-one mapping from HistoryID to the word starts detected in each
392 // item's URL and page title. 335 // item's URL and page title.
393 WordStartsMap word_starts_map_; 336 WordStartsMap word_starts_map_;
394 337
395 // End of data members that are cached --------------------------------------- 338 // End of data members that are cached ---------------------------------------
396 339
397 // Pre-computed information to speed up calculating recency scores.
398 // |days_ago_to_recency_score_| is a simple array mapping how long
399 // ago a page was visited (in days) to the recency score we should
400 // assign it. This allows easy lookups of scores without requiring
401 // math. This is initialized upon first use of GetRecencyScore(),
402 // which calls FillInDaysAgoToRecencyScoreArray(),
403 static const int kDaysToPrecomputeRecencyScoresFor = 366;
404 static float* days_ago_to_recency_score_;
405
406 // Pre-computed information to speed up calculating topicality
407 // scores. |raw_term_score_to_topicality_score_| is a simple array
408 // mapping how raw terms scores (a weighted sum of the number of
409 // hits for the term, weighted by how important the hit is:
410 // hostname, path, etc.) to the topicality score we should assign
411 // it. This allows easy lookups of scores without requiring math.
412 // This is initialized upon first use of GetTopicalityScore(),
413 // which calls FillInTermScoreToTopicalityScoreArray().
414 static const int kMaxRawTermScore = 30;
415 static float* raw_term_score_to_topicality_score_;
416
417 // Whether to use new-score or old-scoring. Set in the constructor
418 // by examining command line flags.
419 bool use_new_scoring_;
420
421 // For unit testing only. Specifies the version of the cache file to be saved. 340 // For unit testing only. Specifies the version of the cache file to be saved.
422 // Used only for testing upgrading of an older version of the cache upon 341 // Used only for testing upgrading of an older version of the cache upon
423 // restore. 342 // restore.
424 int saved_cache_version_; 343 int saved_cache_version_;
425 344
426 // Used for unit testing only. Records the number of candidate history items 345 // Used for unit testing only. Records the number of candidate history items
427 // at three stages in the index searching process. 346 // at three stages in the index searching process.
428 size_t pre_filter_item_count_; // After word index is queried. 347 size_t pre_filter_item_count_; // After word index is queried.
429 size_t post_filter_item_count_; // After trimming large result set. 348 size_t post_filter_item_count_; // After trimming large result set.
430 size_t post_scoring_item_count_; // After performing final filter/scoring. 349 size_t post_scoring_item_count_; // After performing final filter/scoring.
431 }; 350 };
432 351
433 } // namespace history 352 } // namespace history
434 353
435 #endif // CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_ 354 #endif // CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_
OLDNEW
« no previous file with comments | « chrome/browser/history/scored_history_match_unittest.cc ('k') | chrome/browser/history/url_index_private_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698