OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_HISTORY_QUERY_PARSER_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_QUERY_PARSER_H_ |
6 #define CHROME_BROWSER_HISTORY_QUERY_PARSER_H_ | 6 #define CHROME_BROWSER_HISTORY_QUERY_PARSER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 // Returns true if this node matches |word|. If |exact| is true, the string | 39 // Returns true if this node matches |word|. If |exact| is true, the string |
40 // must exactly match. Otherwise, this uses a starts with comparison. | 40 // must exactly match. Otherwise, this uses a starts with comparison. |
41 virtual bool Matches(const string16& word, bool exact) const = 0; | 41 virtual bool Matches(const string16& word, bool exact) const = 0; |
42 | 42 |
43 // Returns true if this node matches at least one of the words in |words|. An | 43 // Returns true if this node matches at least one of the words in |words|. An |
44 // entry is added to |match_positions| for all matching words giving the | 44 // entry is added to |match_positions| for all matching words giving the |
45 // matching regions. | 45 // matching regions. |
46 virtual bool HasMatchIn(const std::vector<QueryWord>& words, | 46 virtual bool HasMatchIn(const std::vector<QueryWord>& words, |
47 Snippet::MatchPositions* match_positions) const = 0; | 47 Snippet::MatchPositions* match_positions) const = 0; |
48 | 48 |
| 49 // Returns true if this node matches at least one of the words in |words|. |
| 50 virtual bool HasMatchIn(const std::vector<QueryWord>& words) const = 0; |
| 51 |
49 // Appends the words that make up this node in |words|. | 52 // Appends the words that make up this node in |words|. |
50 virtual void AppendWords(std::vector<string16>* words) const = 0; | 53 virtual void AppendWords(std::vector<string16>* words) const = 0; |
51 }; | 54 }; |
52 | 55 |
53 // This class is used to parse queries entered into the history search into more | 56 // This class is used to parse queries entered into the history search into more |
54 // normalized queries that can be passed to the SQLite backend. | 57 // normalized queries that can be passed to the SQLite backend. |
55 class QueryParser { | 58 class QueryParser { |
56 public: | 59 public: |
57 QueryParser(); | 60 QueryParser(); |
58 | 61 |
(...skipping 21 matching lines...) Expand all Loading... |
80 // the nodes passes to the caller. | 83 // the nodes passes to the caller. |
81 void ParseQueryNodes(const string16& query, std::vector<QueryNode*>* nodes); | 84 void ParseQueryNodes(const string16& query, std::vector<QueryNode*>* nodes); |
82 | 85 |
83 // Returns true if the string text matches the query nodes created by a call | 86 // Returns true if the string text matches the query nodes created by a call |
84 // to ParseQuery. If the query does match, each of the matching positions in | 87 // to ParseQuery. If the query does match, each of the matching positions in |
85 // the text is added to |match_positions|. | 88 // the text is added to |match_positions|. |
86 bool DoesQueryMatch(const string16& text, | 89 bool DoesQueryMatch(const string16& text, |
87 const std::vector<QueryNode*>& nodes, | 90 const std::vector<QueryNode*>& nodes, |
88 Snippet::MatchPositions* match_positions); | 91 Snippet::MatchPositions* match_positions); |
89 | 92 |
| 93 // Returns true if all of the |words| match the query |nodes| created by a |
| 94 // call to ParseQuery. |
| 95 bool DoesQueryMatch(const std::vector<QueryWord>& words, |
| 96 const std::vector<QueryNode*>& nodes); |
| 97 |
| 98 // Extracts the words from |text|, placing each word into |words|. |
| 99 void ExtractQueryWords(const string16& text, std::vector<QueryWord>* words); |
| 100 |
90 private: | 101 private: |
91 // Does the work of parsing |query|; creates nodes in |root| as appropriate. | 102 // Does the work of parsing |query|; creates nodes in |root| as appropriate. |
92 // This is invoked from both of the ParseQuery methods. | 103 // This is invoked from both of the ParseQuery methods. |
93 bool ParseQueryImpl(const string16& query, QueryNodeList* root); | 104 bool ParseQueryImpl(const string16& query, QueryNodeList* root); |
94 | 105 |
95 // Extracts the words from |text|, placing each word into |words|. | |
96 void ExtractQueryWords(const string16& text, std::vector<QueryWord>* words); | |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(QueryParser); | 106 DISALLOW_COPY_AND_ASSIGN(QueryParser); |
99 }; | 107 }; |
100 | 108 |
101 #endif // CHROME_BROWSER_HISTORY_QUERY_PARSER_H_ | 109 #endif // CHROME_BROWSER_HISTORY_QUERY_PARSER_H_ |
OLD | NEW |