OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_BOOKMARKS_BROWSER_TITLED_URL_INDEX_H_ | |
6 #define COMPONENTS_BOOKMARKS_BROWSER_TITLED_URL_INDEX_H_ | |
7 | |
8 #include <stddef.h> | |
9 | |
10 #include <map> | |
11 #include <set> | |
12 #include <string> | |
13 #include <vector> | |
14 | |
15 #include "base/macros.h" | |
16 #include "base/strings/string16.h" | |
17 #include "components/bookmarks/browser/titled_url_node.h" | |
18 #include "components/query_parser/query_parser.h" | |
19 | |
20 namespace bookmarks { | |
21 | |
22 struct TitledUrlMatch; | |
23 | |
24 // TitledUrlIndex maintains an index of paired titles and URLs for quick lookup. | |
25 // | |
26 // TitledUrlIndex stores the index (index_) as a map of sets. The map (type | |
27 // Index) maps from a lower case string to the set (type NodeSet) of | |
28 // TitledUrlNodes that contain that string in their title or URL. | |
29 class TitledUrlIndex { | |
sky
2016/12/01 20:24:51
Can you convert BookmarkIndex in place and then re
mattreynolds
2016/12/01 23:33:18
Done.
| |
30 public: | |
31 TitledUrlIndex(); | |
32 ~TitledUrlIndex(); | |
33 | |
34 // Invoked when a title/URL pair has been added to the model. | |
35 void Add(const TitledUrlNode* node); | |
36 | |
37 // Invoked when a title/URL pair has been removed from the model. | |
38 void Remove(const TitledUrlNode* node); | |
39 | |
40 // Returns up to |max_count| of matches containing each term from the text | |
41 // |query| in either the title or the URL. | |
42 void GetResultsMatching(const base::string16& query, | |
43 size_t max_count, | |
44 query_parser::MatchingAlgorithm matching_algorithm, | |
45 std::vector<TitledUrlMatch>* results); | |
46 | |
47 protected: | |
48 typedef std::vector<const TitledUrlNode*> Nodes; | |
49 typedef std::set<const TitledUrlNode*> NodeSet; | |
50 typedef std::map<base::string16, NodeSet> Index; | |
51 | |
52 private: | |
53 // Constructs |sorted_nodes| by copying the matches in |matches|. If the order | |
54 // of matches is relevant, override this method to specify the sorting and | |
55 // deduplication behavior. The default implementation performs no sorting. | |
56 virtual void SortMatches(const NodeSet& matches, Nodes* sorted_nodes) const; | |
57 | |
58 // Add |node| to |results| if the node matches the query. | |
59 void AddMatchToResults(const TitledUrlNode* node, | |
60 query_parser::QueryParser* parser, | |
61 const query_parser::QueryNodeVector& query_nodes, | |
62 std::vector<TitledUrlMatch>* results); | |
63 | |
64 // Populates |matches| for the specified term. If |first_term| is true, this | |
65 // is the first term in the query. Returns true if there is at least one node | |
66 // matching the term. | |
67 bool GetResultsMatchingTerm( | |
68 const base::string16& term, | |
69 bool first_term, | |
70 query_parser::MatchingAlgorithm matching_algorithm, | |
71 NodeSet* matches); | |
72 | |
73 // Returns the set of query words from |query|. | |
74 std::vector<base::string16> ExtractQueryWords(const base::string16& query); | |
75 | |
76 // Adds |node| to |index_|. | |
77 void RegisterNode(const base::string16& term, const TitledUrlNode* node); | |
78 | |
79 // Removes |node| from |index_|. | |
80 void UnregisterNode(const base::string16& term, const TitledUrlNode* node); | |
81 | |
82 Index index_; | |
83 | |
84 DISALLOW_COPY_AND_ASSIGN(TitledUrlIndex); | |
85 }; | |
86 | |
87 } // namespace bookmarks | |
88 | |
89 #endif // COMPONENTS_BOOKMARKS_BROWSER_TITLED_URL_INDEX_H_ | |
OLD | NEW |