| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 void GetBookmarksMatching(const base::string16& query, | 46 void GetBookmarksMatching(const base::string16& query, |
| 47 size_t max_count, | 47 size_t max_count, |
| 48 query_parser::MatchingAlgorithm matching_algorithm, | 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 // Constructs |sorted_nodes| by taking the matches in |matches| and sorting |
| 57 typedef std::vector<Match> Matches; | 57 // them in decreasing order of typed count (if supported by the client) and |
| 58 | 58 // deduping. |
| 59 // Extracts |matches.nodes| into Nodes, sorts the pairs in decreasing order of | 59 void SortMatches(const NodeSet& matches, Nodes* sorted_nodes) const; |
| 60 // typed count (if supported by the client), and then de-dupes the matches. | |
| 61 void SortMatches(const Matches& matches, Nodes* sorted_nodes) const; | |
| 62 | 60 |
| 63 // Add |node| to |results| if the node matches the query. | 61 // Add |node| to |results| if the node matches the query. |
| 64 void AddMatchToResults( | 62 void AddMatchToResults( |
| 65 const BookmarkNode* node, | 63 const BookmarkNode* node, |
| 66 query_parser::QueryParser* parser, | 64 query_parser::QueryParser* parser, |
| 67 const query_parser::QueryNodeStarVector& query_nodes, | 65 const query_parser::QueryNodeStarVector& query_nodes, |
| 68 std::vector<BookmarkMatch>* results); | 66 std::vector<BookmarkMatch>* results); |
| 69 | 67 |
| 70 // Populates |matches| for the specified term. If |first_term| is true, this | 68 // 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 | 69 // is the first term in the query. Returns true if there is at least one node |
| 72 // matching the term. | 70 // matching the term. |
| 73 bool GetBookmarksMatchingTerm( | 71 bool GetBookmarksMatchingTerm( |
| 74 const base::string16& term, | 72 const base::string16& term, |
| 75 bool first_term, | 73 bool first_term, |
| 76 query_parser::MatchingAlgorithm matching_algorithm, | 74 query_parser::MatchingAlgorithm matching_algorithm, |
| 77 Matches* matches); | 75 NodeSet* matches); |
| 78 | 76 |
| 79 // Iterates over |matches| updating each Match's nodes to contain the | 77 // Replaces |*matches| with the intersection of |*matches| and |
| 80 // intersection of the Match's current nodes and the nodes at |index_i|. | 78 // |matches_to_incorporate|. |
| 81 // If the intersection is empty, the Match is removed. | 79 void CombineMatchesInPlace(const NodeSet& matches_to_incorporate, |
| 82 // | 80 NodeSet* matches); |
| 83 // This is invoked from GetBookmarksMatchingTerm. | |
| 84 void CombineMatchesInPlace(const Index::const_iterator& index_i, | |
| 85 Matches* matches); | |
| 86 | |
| 87 // Iterates over |current_matches| calculating the intersection between the | |
| 88 // Match's nodes and the nodes at |index_i|. If the intersection between the | |
| 89 // two is non-empty, a new match is added to |result|. | |
| 90 // | |
| 91 // This differs from CombineMatchesInPlace in that if the intersection is | |
| 92 // non-empty the result is added to result, not combined in place. This | |
| 93 // variant is used for prefix matching. | |
| 94 // | |
| 95 // This is invoked from GetBookmarksMatchingTerm. | |
| 96 void CombineMatches(const Index::const_iterator& index_i, | |
| 97 const Matches& current_matches, | |
| 98 Matches* result); | |
| 99 | 81 |
| 100 // Returns the set of query words from |query|. | 82 // Returns the set of query words from |query|. |
| 101 std::vector<base::string16> ExtractQueryWords(const base::string16& query); | 83 std::vector<base::string16> ExtractQueryWords(const base::string16& query); |
| 102 | 84 |
| 103 // Adds |node| to |index_|. | 85 // Adds |node| to |index_|. |
| 104 void RegisterNode(const base::string16& term, const BookmarkNode* node); | 86 void RegisterNode(const base::string16& term, const BookmarkNode* node); |
| 105 | 87 |
| 106 // Removes |node| from |index_|. | 88 // Removes |node| from |index_|. |
| 107 void UnregisterNode(const base::string16& term, const BookmarkNode* node); | 89 void UnregisterNode(const base::string16& term, const BookmarkNode* node); |
| 108 | 90 |
| 109 Index index_; | 91 Index index_; |
| 110 | 92 |
| 111 BookmarkClient* const client_; | 93 BookmarkClient* const client_; |
| 112 | 94 |
| 113 // Languages used to help parse IDNs in URLs for the bookmark index. | 95 // Languages used to help parse IDNs in URLs for the bookmark index. |
| 114 const std::string languages_; | 96 const std::string languages_; |
| 115 | 97 |
| 116 DISALLOW_COPY_AND_ASSIGN(BookmarkIndex); | 98 DISALLOW_COPY_AND_ASSIGN(BookmarkIndex); |
| 117 }; | 99 }; |
| 118 | 100 |
| 119 } // namespace bookmarks | 101 } // namespace bookmarks |
| 120 | 102 |
| 121 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_INDEX_H_ | 103 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_INDEX_H_ |
| OLD | NEW |