OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_INDEX_H_ | 5 #ifndef COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_INDEX_H_ |
6 #define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_INDEX_H_ | 6 #define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_INDEX_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 23 matching lines...) Expand all Loading... |
34 BookmarkIndex(BookmarkClient* client, | 34 BookmarkIndex(BookmarkClient* client, |
35 const std::string& languages); | 35 const std::string& languages); |
36 ~BookmarkIndex(); | 36 ~BookmarkIndex(); |
37 | 37 |
38 // Invoked when a bookmark has been added to the model. | 38 // Invoked when a bookmark has been added to the model. |
39 void Add(const BookmarkNode* node); | 39 void Add(const BookmarkNode* node); |
40 | 40 |
41 // Invoked when a bookmark has been removed from the model. | 41 // Invoked when a bookmark has been removed from the model. |
42 void Remove(const BookmarkNode* node); | 42 void Remove(const BookmarkNode* node); |
43 | 43 |
44 // Returns up to |max_count| of bookmarks containing each term from | 44 // Returns up to |max_count| of bookmarks containing each term from the text |
45 // the text |query| in either the title or the URL. | 45 // |query| in either the title or the URL. |
46 void GetBookmarksMatching( | 46 void GetBookmarksMatching(const base::string16& query, |
47 const base::string16& query, | 47 size_t max_count, |
48 size_t max_count, | 48 query_parser::MatchingAlgorithm matching_algorithm, |
49 std::vector<BookmarkMatch>* results); | 49 std::vector<BookmarkMatch>* results); |
50 | 50 |
51 private: | 51 private: |
52 typedef std::vector<const BookmarkNode*> Nodes; | 52 typedef std::vector<const BookmarkNode*> Nodes; |
53 typedef std::set<const BookmarkNode*> NodeSet; | 53 typedef std::set<const BookmarkNode*> NodeSet; |
54 typedef std::map<base::string16, NodeSet> Index; | 54 typedef std::map<base::string16, NodeSet> Index; |
55 | 55 |
56 struct Match; | 56 struct Match; |
57 typedef std::vector<Match> Matches; | 57 typedef std::vector<Match> Matches; |
58 | 58 |
59 // Extracts |matches.nodes| into Nodes, sorts the pairs in decreasing order of | 59 // Extracts |matches.nodes| into Nodes, sorts the pairs in decreasing order of |
60 // typed count (if supported by the client), and then de-dupes the matches. | 60 // typed count (if supported by the client), and then de-dupes the matches. |
61 void SortMatches(const Matches& matches, Nodes* sorted_nodes) const; | 61 void SortMatches(const Matches& matches, Nodes* sorted_nodes) const; |
62 | 62 |
63 // Add |node| to |results| if the node matches the query. | 63 // Add |node| to |results| if the node matches the query. |
64 void AddMatchToResults( | 64 void AddMatchToResults( |
65 const BookmarkNode* node, | 65 const BookmarkNode* node, |
66 query_parser::QueryParser* parser, | 66 query_parser::QueryParser* parser, |
67 const query_parser::QueryNodeStarVector& query_nodes, | 67 const query_parser::QueryNodeStarVector& query_nodes, |
68 std::vector<BookmarkMatch>* results); | 68 std::vector<BookmarkMatch>* results); |
69 | 69 |
70 // Populates |matches| for the specified term. If |first_term| is true, this | 70 // Populates |matches| for the specified term. If |first_term| is true, this |
71 // is the first term in the query. Returns true if there is at least one node | 71 // is the first term in the query. Returns true if there is at least one node |
72 // matching the term. | 72 // matching the term. |
73 bool GetBookmarksMatchingTerm(const base::string16& term, | 73 bool GetBookmarksMatchingTerm( |
74 bool first_term, | 74 const base::string16& term, |
75 Matches* matches); | 75 bool first_term, |
| 76 query_parser::MatchingAlgorithm matching_algorithm, |
| 77 Matches* matches); |
76 | 78 |
77 // Iterates over |matches| updating each Match's nodes to contain the | 79 // Iterates over |matches| updating each Match's nodes to contain the |
78 // intersection of the Match's current nodes and the nodes at |index_i|. | 80 // intersection of the Match's current nodes and the nodes at |index_i|. |
79 // If the intersection is empty, the Match is removed. | 81 // If the intersection is empty, the Match is removed. |
80 // | 82 // |
81 // This is invoked from GetBookmarksMatchingTerm. | 83 // This is invoked from GetBookmarksMatchingTerm. |
82 void CombineMatchesInPlace(const Index::const_iterator& index_i, | 84 void CombineMatchesInPlace(const Index::const_iterator& index_i, |
83 Matches* matches); | 85 Matches* matches); |
84 | 86 |
85 // Iterates over |current_matches| calculating the intersection between the | 87 // Iterates over |current_matches| calculating the intersection between the |
(...skipping 24 matching lines...) Expand all Loading... |
110 | 112 |
111 // Languages used to help parse IDNs in URLs for the bookmark index. | 113 // Languages used to help parse IDNs in URLs for the bookmark index. |
112 const std::string languages_; | 114 const std::string languages_; |
113 | 115 |
114 DISALLOW_COPY_AND_ASSIGN(BookmarkIndex); | 116 DISALLOW_COPY_AND_ASSIGN(BookmarkIndex); |
115 }; | 117 }; |
116 | 118 |
117 } // namespace bookmarks | 119 } // namespace bookmarks |
118 | 120 |
119 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_INDEX_H_ | 121 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_INDEX_H_ |
OLD | NEW |