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_AUTOCOMPLETE_SCORED_HISTORY_MATCH_H_ | 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_SCORED_HISTORY_MATCH_H_ |
6 #define CHROME_BROWSER_AUTOCOMPLETE_SCORED_HISTORY_MATCH_H_ | 6 #define CHROME_BROWSER_AUTOCOMPLETE_SCORED_HISTORY_MATCH_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "chrome/browser/autocomplete/in_memory_url_index_types.h" | 13 #include "chrome/browser/autocomplete/in_memory_url_index_types.h" |
14 #include "components/history/core/browser/history_match.h" | 14 #include "components/history/core/browser/history_match.h" |
15 #include "components/history/core/browser/history_types.h" | 15 #include "components/history/core/browser/history_types.h" |
16 | 16 |
17 namespace history { | |
18 | |
19 // An HistoryMatch that has a score as well as metrics defining where in the | 17 // 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. | 18 // history item's URL and/or page title matches have occurred. |
21 struct ScoredHistoryMatch : public HistoryMatch { | 19 struct ScoredHistoryMatch : public history::HistoryMatch { |
22 // The Builder inner class allows the embedder to control how matches are | 20 // The Builder inner class allows the embedder to control how matches are |
23 // scored (we cannot use a base::Callback<> as base::Bind() is limited to 6 | 21 // scored (we cannot use a base::Callback<> as base::Bind() is limited to 6 |
24 // parameters). | 22 // parameters). |
25 // TODO(sdefresne): remove this since ScoredHistoryMatch can now depends on | 23 // TODO(sdefresne): remove this since ScoredHistoryMatch can now depends on |
26 // chrome/browser/autocomplete and components/bookmarks | 24 // chrome/browser/autocomplete and components/bookmarks |
27 // http://crbug.com/462645 | 25 // http://crbug.com/462645 |
28 class Builder { | 26 class Builder { |
29 public: | 27 public: |
30 Builder() {} | 28 Builder() {} |
31 virtual ~Builder() {} | 29 virtual ~Builder() {} |
32 | 30 |
33 // Creates a new match with a raw score calculated for the history item | 31 // Creates a new match with a raw score calculated for the history item |
34 // given in |row| with recent visits as indicated in |visits|. First | 32 // given in |row| with recent visits as indicated in |visits|. First |
35 // determines if the row qualifies by seeing if all of the terms in | 33 // determines if the row qualifies by seeing if all of the terms in |
36 // |terms_vector| occur in |row|. If so, calculates a raw score. This raw | 34 // |terms_vector| occur in |row|. If so, calculates a raw score. This raw |
37 // score is in part determined by whether the matches occur at word | 35 // score is in part determined by whether the matches occur at word |
38 // boundaries, the locations of which are stored in |word_starts|. For some | 36 // boundaries, the locations of which are stored in |word_starts|. For some |
39 // terms, it's appropriate to look for the word boundary within the term. | 37 // terms, it's appropriate to look for the word boundary within the term. |
40 // For instance, the term ".net" should look for a word boundary at the "n". | 38 // For instance, the term ".net" should look for a word boundary at the "n". |
41 // These offsets (".net" should have an offset of 1) come from | 39 // These offsets (".net" should have an offset of 1) come from |
42 // |terms_to_word_starts_offsets|. |history_client| is used to determine | 40 // |terms_to_word_starts_offsets|. |history_client| is used to determine |
43 // if the match's URL is referenced by any bookmarks, which can also affect | 41 // if the match's URL is referenced by any bookmarks, which can also affect |
44 // the raw score. The raw score allows the matches to be ordered and can be | 42 // the raw score. The raw score allows the matches to be ordered and can be |
45 // used to influence the final score calculated by the client of this index. | 43 // used to influence the final score calculated by the client of this index. |
46 // If the row does not qualify the raw score will be 0. |languages| is used | 44 // If the row does not qualify the raw score will be 0. |languages| is used |
47 // to help parse/format the URL before looking for the terms. | 45 // to help parse/format the URL before looking for the terms. |
48 virtual ScoredHistoryMatch Build( | 46 virtual ScoredHistoryMatch Build( |
49 const URLRow& row, | 47 const history::URLRow& row, |
50 const VisitInfoVector& visits, | 48 const VisitInfoVector& visits, |
51 const std::string& languages, | 49 const std::string& languages, |
52 const base::string16& lower_string, | 50 const base::string16& lower_string, |
53 const String16Vector& terms_vector, | 51 const String16Vector& terms_vector, |
54 const WordStarts& terms_to_word_starts_offsets, | 52 const WordStarts& terms_to_word_starts_offsets, |
55 const RowWordStarts& word_starts, | 53 const RowWordStarts& word_starts, |
56 const base::Time now) const = 0; | 54 const base::Time now) const = 0; |
57 }; | 55 }; |
58 | 56 |
59 // Required for STL, we don't use this directly. | 57 // Required for STL, we don't use this directly. |
60 ScoredHistoryMatch(); | 58 ScoredHistoryMatch(); |
61 | 59 |
62 // Initialize the ScoredHistoryMatch, passing |url_info|, |input_location|, | 60 // Initialize the ScoredHistoryMatch, passing |url_info|, |input_location|, |
63 // |match_in_scheme| and |innermost_match| to HistoryMatch constructor, and | 61 // |match_in_scheme| and |innermost_match| to HistoryMatch constructor, and |
64 // using |raw_score|, |url_matches|, |title_matches| and |can_inline| to | 62 // using |raw_score|, |url_matches|, |title_matches| and |can_inline| to |
65 // initialize the corresponding properties of this class. | 63 // initialize the corresponding properties of this class. |
66 ScoredHistoryMatch(const URLRow& url_info, | 64 ScoredHistoryMatch(const history::URLRow& url_info, |
67 size_t input_location, | 65 size_t input_location, |
68 bool match_in_scheme, | 66 bool match_in_scheme, |
69 bool innermost_match, | 67 bool innermost_match, |
70 int raw_score, | 68 int raw_score, |
71 const TermMatches& url_matches, | 69 const TermMatches& url_matches, |
72 const TermMatches& title_matches, | 70 const TermMatches& title_matches, |
73 bool can_inline); | 71 bool can_inline); |
74 | 72 |
75 ~ScoredHistoryMatch(); | 73 ~ScoredHistoryMatch(); |
76 | 74 |
(...skipping 22 matching lines...) Expand all Loading... |
99 // Term matches within the URL. | 97 // Term matches within the URL. |
100 TermMatches url_matches; | 98 TermMatches url_matches; |
101 // Term matches within the page title. | 99 // Term matches within the page title. |
102 TermMatches title_matches; | 100 TermMatches title_matches; |
103 | 101 |
104 // True if this is a candidate for in-line autocompletion. | 102 // True if this is a candidate for in-line autocompletion. |
105 bool can_inline; | 103 bool can_inline; |
106 }; | 104 }; |
107 typedef std::vector<ScoredHistoryMatch> ScoredHistoryMatches; | 105 typedef std::vector<ScoredHistoryMatch> ScoredHistoryMatches; |
108 | 106 |
109 } // namespace history | |
110 | |
111 #endif // CHROME_BROWSER_AUTOCOMPLETE_SCORED_HISTORY_MATCH_H_ | 107 #endif // CHROME_BROWSER_AUTOCOMPLETE_SCORED_HISTORY_MATCH_H_ |
OLD | NEW |