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 15 matching lines...) Expand all Loading... |
26 // query. While QueryNode is exposed by way of ParseQuery, it really isn't meant | 26 // query. While QueryNode is exposed by way of ParseQuery, it really isn't meant |
27 // for external usage. | 27 // for external usage. |
28 class QueryNode { | 28 class QueryNode { |
29 public: | 29 public: |
30 virtual ~QueryNode() {} | 30 virtual ~QueryNode() {} |
31 | 31 |
32 // Serialize ourselves out to a string that can be passed to SQLite. Returns | 32 // Serialize ourselves out to a string that can be passed to SQLite. Returns |
33 // the number of words in this node. | 33 // the number of words in this node. |
34 virtual int AppendToSQLiteQuery(string16* query) const = 0; | 34 virtual int AppendToSQLiteQuery(string16* query) const = 0; |
35 | 35 |
| 36 // Serialize ourselves out to a series of strings which can be passed to |
| 37 // SQLite as REGEXP queries. |
| 38 virtual void AppendSQLiteRegexpQueries( |
| 39 std::vector<string16>* queries) const = 0; |
| 40 |
36 // Return true if this is a QueryNodeWord, false if it's a QueryNodeList. | 41 // Return true if this is a QueryNodeWord, false if it's a QueryNodeList. |
37 virtual bool IsWord() const = 0; | 42 virtual bool IsWord() const = 0; |
38 | 43 |
39 // Returns true if this node matches |word|. If |exact| is true, the string | 44 // Returns true if this node matches |word|. If |exact| is true, the string |
40 // must exactly match. Otherwise, this uses a starts with comparison. | 45 // must exactly match. Otherwise, this uses a starts with comparison. |
41 virtual bool Matches(const string16& word, bool exact) const = 0; | 46 virtual bool Matches(const string16& word, bool exact) const = 0; |
42 | 47 |
43 // Returns true if this node matches at least one of the words in |words|. An | 48 // 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 | 49 // entry is added to |match_positions| for all matching words giving the |
45 // matching regions. | 50 // matching regions. |
(...skipping 16 matching lines...) Expand all Loading... |
62 // back every single Chinese character as a word so that there's no | 67 // back every single Chinese character as a word so that there's no |
63 // point doing anything for them and we only adjust the minimum length | 68 // point doing anything for them and we only adjust the minimum length |
64 // to 2 for Korean Hangul while using 3 for others. This is a temporary | 69 // to 2 for Korean Hangul while using 3 for others. This is a temporary |
65 // hack until we have a segmentation support. | 70 // hack until we have a segmentation support. |
66 static bool IsWordLongEnoughForPrefixSearch(const string16& word); | 71 static bool IsWordLongEnoughForPrefixSearch(const string16& word); |
67 | 72 |
68 // Parse a query into a SQLite query. The resulting query is placed in | 73 // Parse a query into a SQLite query. The resulting query is placed in |
69 // |sqlite_query| and the number of words is returned. | 74 // |sqlite_query| and the number of words is returned. |
70 int ParseQuery(const string16& query, string16* sqlite_query); | 75 int ParseQuery(const string16& query, string16* sqlite_query); |
71 | 76 |
| 77 // Parse a query into a series of SQLite REGEXP queries. The resulting queries |
| 78 // are placed in |sqlite_queries|. |
| 79 void ParseQueryAsRegexps(const string16& query, |
| 80 std::vector<string16>* sqlite_queries); |
| 81 |
72 // Parses |query|, returning the words that make up it. Any words in quotes | 82 // Parses |query|, returning the words that make up it. Any words in quotes |
73 // are put in |words| without the quotes. For example, the query text | 83 // are put in |words| without the quotes. For example, the query text |
74 // "foo bar" results in two entries being added to words, one for foo and one | 84 // "foo bar" results in two entries being added to words, one for foo and one |
75 // for bar. | 85 // for bar. |
76 void ParseQueryWords(const string16& query, std::vector<string16>* words); | 86 void ParseQueryWords(const string16& query, std::vector<string16>* words); |
77 | 87 |
78 // Parses |query|, returning the nodes that constitute the valid words in the | 88 // Parses |query|, returning the nodes that constitute the valid words in the |
79 // query. This is intended for later usage with DoesQueryMatch. Ownership of | 89 // query. This is intended for later usage with DoesQueryMatch. Ownership of |
80 // the nodes passes to the caller. | 90 // the nodes passes to the caller. |
81 void ParseQueryNodes(const string16& query, std::vector<QueryNode*>* nodes); | 91 void ParseQueryNodes(const string16& query, std::vector<QueryNode*>* nodes); |
(...skipping 10 matching lines...) Expand all Loading... |
92 // This is invoked from both of the ParseQuery methods. | 102 // This is invoked from both of the ParseQuery methods. |
93 bool ParseQueryImpl(const string16& query, QueryNodeList* root); | 103 bool ParseQueryImpl(const string16& query, QueryNodeList* root); |
94 | 104 |
95 // Extracts the words from |text|, placing each word into |words|. | 105 // Extracts the words from |text|, placing each word into |words|. |
96 void ExtractQueryWords(const string16& text, std::vector<QueryWord>* words); | 106 void ExtractQueryWords(const string16& text, std::vector<QueryWord>* words); |
97 | 107 |
98 DISALLOW_COPY_AND_ASSIGN(QueryParser); | 108 DISALLOW_COPY_AND_ASSIGN(QueryParser); |
99 }; | 109 }; |
100 | 110 |
101 #endif // CHROME_BROWSER_HISTORY_QUERY_PARSER_H_ | 111 #endif // CHROME_BROWSER_HISTORY_QUERY_PARSER_H_ |
OLD | NEW |