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

Side by Side Diff: chrome/browser/bookmarks/bookmark_index.h

Issue 165455: Autocomplete suggestions for bookmark TitleMatch's does not order matching bo... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 3 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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_BOOKMARKS_BOOKMARK_INDEX_H_ 5 #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_INDEX_H_
6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_INDEX_H_ 6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_INDEX_H_
7 7
8 #include <list> 8 #include <list>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 15
16 class BookmarkNode; 16 class BookmarkNode;
17 class Profile;
17 class QueryNode; 18 class QueryNode;
18 class QueryParser; 19 class QueryParser;
19 20
20 namespace bookmark_utils { 21 namespace bookmark_utils {
21 struct TitleMatch; 22 struct TitleMatch;
22 } 23 }
23 24
25 namespace history {
26 class URLDatabase;
27 }
28
24 // BookmarkIndex maintains an index of the titles of bookmarks for quick 29 // BookmarkIndex maintains an index of the titles of bookmarks for quick
25 // look up. BookmarkIndex is owned and maintained by BookmarkModel, you 30 // look up. BookmarkIndex is owned and maintained by BookmarkModel, you
26 // shouldn't need to interact directly with BookmarkIndex. 31 // shouldn't need to interact directly with BookmarkIndex.
27 // 32 //
28 // BookmarkIndex maintains the index (index_) as a map of sets. The map (type 33 // BookmarkIndex maintains the index (index_) as a map of sets. The map (type
29 // Index) maps from a lower case string to the set (type NodeSet) of 34 // Index) maps from a lower case string to the set (type NodeSet) of
30 // BookmarkNodes that contain that string in their title. 35 // BookmarkNodes that contain that string in their title.
31 36
32 class BookmarkIndex { 37 class BookmarkIndex {
33 public: 38 public:
34 BookmarkIndex() {} 39 explicit BookmarkIndex(Profile* profile) : profile_(profile) {}
35 40
36 // Invoked when a bookmark has been added to the model. 41 // Invoked when a bookmark has been added to the model.
37 void Add(const BookmarkNode* node); 42 void Add(const BookmarkNode* node);
38 43
39 // Invoked when a bookmark has been removed from the model. 44 // Invoked when a bookmark has been removed from the model.
40 void Remove(const BookmarkNode* node); 45 void Remove(const BookmarkNode* node);
41 46
42 // Returns up to |max_count| of bookmarks containing the text |query|. 47 // Returns up to |max_count| of bookmarks containing the text |query|.
43 void GetBookmarksWithTitlesMatching( 48 void GetBookmarksWithTitlesMatching(
44 const std::wstring& query, 49 const std::wstring& query,
(...skipping 18 matching lines...) Expand all
63 // 68 //
64 // Use nodes_begin() and nodes_end() to get an iterator over the set as 69 // Use nodes_begin() and nodes_end() to get an iterator over the set as
65 // it handles the necessary switching between nodes and terms.front(). 70 // it handles the necessary switching between nodes and terms.front().
66 NodeSet nodes; 71 NodeSet nodes;
67 72
68 // Returns an iterator to the beginning of the matching nodes. See 73 // Returns an iterator to the beginning of the matching nodes. See
69 // description of nodes for why this should be used over nodes.begin(). 74 // description of nodes for why this should be used over nodes.begin().
70 NodeSet::const_iterator nodes_begin() const; 75 NodeSet::const_iterator nodes_begin() const;
71 76
72 // Returns an iterator to the beginning of the matching nodes. See 77 // Returns an iterator to the beginning of the matching nodes. See
73 // description of nodes for why this should be used over nodes.begin(). 78 // description of nodes for why this should be used over nodes.end().
74 NodeSet::const_iterator nodes_end() const; 79 NodeSet::const_iterator nodes_end() const;
75 }; 80 };
76 81
77 typedef std::vector<Match> Matches; 82 typedef std::vector<Match> Matches;
78 83
79 // Add all the matching nodes in |match.nodes| to |results| until there are 84 // Pairs BookmarkNodes and the number of times the nodes' URLs were typed.
80 // at most |max_count| matches in |results|. 85 // Used to sort Matches in decreasing order of typed count.
81 void AddMatchToResults(const Match& match, 86 typedef std::pair<const BookmarkNode*, int> NodeTypedCountPair;
82 size_t max_count, 87 typedef std::vector<NodeTypedCountPair> NodeTypedCountPairs;
88
89 // Extracts |matches.nodes| into NodeTypedCountPairs and sorts the pairs in
90 // decreasing order of typed count.
91 void SortMatches(const Matches& matches,
92 NodeTypedCountPairs* node_typed_counts) const;
93
94 // Extracts BookmarkNodes from |match| and retrieves typed counts for each
95 // node from the in-memory database. Inserts pairs containing the node and
96 // typed count into the vector |node_typed_counts|. |node_typed_counts| is
97 // sorted in decreasing order of typed count.
98 void ExtractBookmarkNodePairs(history::URLDatabase* url_db,
99 const Match& match,
100 NodeTypedCountPairs* node_typed_counts) const;
101
102 // Sort function for NodeTypedCountPairs. We sort in decreasing order of typed
103 // count so that the best matches will always be added to the results.
104 static bool NodeTypedCountPairSortFunc(const NodeTypedCountPair& a,
105 const NodeTypedCountPair& b) {
106 return a.second > b.second;
107 }
108
109 // Add |node| to |results| if the node matches the query.
110 void AddMatchToResults(const BookmarkNode* node,
83 QueryParser* parser, 111 QueryParser* parser,
84 const std::vector<QueryNode*>& query_nodes, 112 const std::vector<QueryNode*>& query_nodes,
85 std::vector<bookmark_utils::TitleMatch>* results); 113 std::vector<bookmark_utils::TitleMatch>* results);
86 114
87 // Populates |matches| for the specified term. If |first_term| is true, this 115 // Populates |matches| for the specified term. If |first_term| is true, this
88 // is the first term in the query. Returns true if there is at least one node 116 // is the first term in the query. Returns true if there is at least one node
89 // matching the term. 117 // matching the term.
90 bool GetBookmarksWithTitleMatchingTerm(const std::wstring& term, 118 bool GetBookmarksWithTitleMatchingTerm(const std::wstring& term,
91 bool first_term, 119 bool first_term,
92 Matches* matches); 120 Matches* matches);
(...skipping 23 matching lines...) Expand all
116 std::vector<std::wstring> ExtractQueryWords(const std::wstring& query); 144 std::vector<std::wstring> ExtractQueryWords(const std::wstring& query);
117 145
118 // Adds |node| to |index_|. 146 // Adds |node| to |index_|.
119 void RegisterNode(const std::wstring& term, const BookmarkNode* node); 147 void RegisterNode(const std::wstring& term, const BookmarkNode* node);
120 148
121 // Removes |node| from |index_|. 149 // Removes |node| from |index_|.
122 void UnregisterNode(const std::wstring& term, const BookmarkNode* node); 150 void UnregisterNode(const std::wstring& term, const BookmarkNode* node);
123 151
124 Index index_; 152 Index index_;
125 153
154 Profile* profile_;
155
126 DISALLOW_COPY_AND_ASSIGN(BookmarkIndex); 156 DISALLOW_COPY_AND_ASSIGN(BookmarkIndex);
127 }; 157 };
128 158
129 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_INDEX_H_ 159 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_INDEX_H_
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/history_contents_provider_unittest.cc ('k') | chrome/browser/bookmarks/bookmark_index.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698