Chromium Code Reviews| 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 // |always_prefix_search| is passed to |GetBookmarksMatchingTerm| internally. |
| 47 const base::string16& query, | 47 void GetBookmarksMatching(const base::string16& query, |
| 48 size_t max_count, | 48 size_t max_count, |
| 49 std::vector<BookmarkMatch>* results); | 49 bool always_prefix_search, |
| 50 std::vector<BookmarkMatch>* results); | |
| 50 | 51 |
| 51 private: | 52 private: |
| 52 typedef std::vector<const BookmarkNode*> Nodes; | 53 typedef std::vector<const BookmarkNode*> Nodes; |
| 53 typedef std::set<const BookmarkNode*> NodeSet; | 54 typedef std::set<const BookmarkNode*> NodeSet; |
| 54 typedef std::map<base::string16, NodeSet> Index; | 55 typedef std::map<base::string16, NodeSet> Index; |
| 55 | 56 |
| 56 struct Match; | 57 struct Match; |
| 57 typedef std::vector<Match> Matches; | 58 typedef std::vector<Match> Matches; |
| 58 | 59 |
| 59 // Extracts |matches.nodes| into Nodes, sorts the pairs in decreasing order of | 60 // 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. | 61 // typed count (if supported by the client), and then de-dupes the matches. |
| 61 void SortMatches(const Matches& matches, Nodes* sorted_nodes) const; | 62 void SortMatches(const Matches& matches, Nodes* sorted_nodes) const; |
| 62 | 63 |
| 63 // Add |node| to |results| if the node matches the query. | 64 // Add |node| to |results| if the node matches the query. |
| 64 void AddMatchToResults( | 65 void AddMatchToResults( |
| 65 const BookmarkNode* node, | 66 const BookmarkNode* node, |
| 66 query_parser::QueryParser* parser, | 67 query_parser::QueryParser* parser, |
| 67 const query_parser::QueryNodeStarVector& query_nodes, | 68 const query_parser::QueryNodeStarVector& query_nodes, |
| 68 std::vector<BookmarkMatch>* results); | 69 std::vector<BookmarkMatch>* results); |
| 69 | 70 |
| 70 // Populates |matches| for the specified term. If |first_term| is true, this | 71 // 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 | 72 // is the first term in the query. Returns true if there is at least one node |
| 72 // matching the term. | 73 // matching the term. |
| 74 // When |always_prefix_search| is false, if the term is not long enough in the | |
|
sky
2014/11/03 21:44:05
This description is confusing. I think you want so
Kibeom Kim (inactive)
2014/11/04 01:28:19
Done. (removed since we put enum and it's self-exp
| |
| 75 // sense of |query_parser::QueryParser::IsWordLongEnoughForPrefixSearch|, it | |
| 76 // is not considered for prefix search but only for an exact match. | |
| 77 // When |always_prefix_search| is true, the term is always considered for a | |
| 78 // prefix search, no matter its length. | |
| 73 bool GetBookmarksMatchingTerm(const base::string16& term, | 79 bool GetBookmarksMatchingTerm(const base::string16& term, |
| 74 bool first_term, | 80 bool first_term, |
| 81 bool always_prefix_search, | |
| 75 Matches* matches); | 82 Matches* matches); |
| 76 | 83 |
| 77 // Iterates over |matches| updating each Match's nodes to contain the | 84 // 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|. | 85 // intersection of the Match's current nodes and the nodes at |index_i|. |
| 79 // If the intersection is empty, the Match is removed. | 86 // If the intersection is empty, the Match is removed. |
| 80 // | 87 // |
| 81 // This is invoked from GetBookmarksMatchingTerm. | 88 // This is invoked from GetBookmarksMatchingTerm. |
| 82 void CombineMatchesInPlace(const Index::const_iterator& index_i, | 89 void CombineMatchesInPlace(const Index::const_iterator& index_i, |
| 83 Matches* matches); | 90 Matches* matches); |
| 84 | 91 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 110 | 117 |
| 111 // Languages used to help parse IDNs in URLs for the bookmark index. | 118 // Languages used to help parse IDNs in URLs for the bookmark index. |
| 112 const std::string languages_; | 119 const std::string languages_; |
| 113 | 120 |
| 114 DISALLOW_COPY_AND_ASSIGN(BookmarkIndex); | 121 DISALLOW_COPY_AND_ASSIGN(BookmarkIndex); |
| 115 }; | 122 }; |
| 116 | 123 |
| 117 } // namespace bookmarks | 124 } // namespace bookmarks |
| 118 | 125 |
| 119 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_INDEX_H_ | 126 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_INDEX_H_ |
| OLD | NEW |