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

Side by Side Diff: components/query_parser/query_parser.h

Issue 701553002: Allow systematic prefix search in bookmarks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
OLDNEW
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_QUERY_PARSER_QUERY_PARSER_H_ 5 #ifndef COMPONENTS_QUERY_PARSER_QUERY_PARSER_H_
6 #define COMPONENTS_QUERY_PARSER_QUERY_PARSER_H_ 6 #define COMPONENTS_QUERY_PARSER_QUERY_PARSER_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 // can be useful in prefix matching, but that may give us too many 69 // can be useful in prefix matching, but that may give us too many
70 // false positives. Moreover, the current ICU word breaker gives us 70 // false positives. Moreover, the current ICU word breaker gives us
71 // back every single Chinese character as a word so that there's no 71 // back every single Chinese character as a word so that there's no
72 // point doing anything for them and we only adjust the minimum length 72 // point doing anything for them and we only adjust the minimum length
73 // to 2 for Korean Hangul while using 3 for others. This is a temporary 73 // to 2 for Korean Hangul while using 3 for others. This is a temporary
74 // hack until we have a segmentation support. 74 // hack until we have a segmentation support.
75 static bool IsWordLongEnoughForPrefixSearch(const base::string16& word); 75 static bool IsWordLongEnoughForPrefixSearch(const base::string16& word);
76 76
77 // Parse a query into a SQLite query. The resulting query is placed in 77 // Parse a query into a SQLite query. The resulting query is placed in
78 // |sqlite_query| and the number of words is returned. 78 // |sqlite_query| and the number of words is returned.
79 int ParseQuery(const base::string16& query, base::string16* sqlite_query); 79 int ParseQuery(const base::string16& query,
80 bool always_prefix_search,
81 base::string16* sqlite_query);
80 82
81 // Parses |query|, returning the words that make up it. Any words in quotes 83 // Parses |query|, returning the words that make up it. Any words in quotes
82 // are put in |words| without the quotes. For example, the query text 84 // are put in |words| without the quotes. For example, the query text
83 // "foo bar" results in two entries being added to words, one for foo and one 85 // "foo bar" results in two entries being added to words, one for foo and one
84 // for bar. 86 // for bar.
85 void ParseQueryWords(const base::string16& query, 87 void ParseQueryWords(const base::string16& query,
88 bool always_prefix_search,
86 std::vector<base::string16>* words); 89 std::vector<base::string16>* words);
87 90
88 // Parses |query|, returning the nodes that constitute the valid words in the 91 // Parses |query|, returning the nodes that constitute the valid words in the
89 // query. This is intended for later usage with DoesQueryMatch. Ownership of 92 // query. This is intended for later usage with DoesQueryMatch. Ownership of
90 // the nodes passes to the caller. 93 // the nodes passes to the caller.
91 void ParseQueryNodes(const base::string16& query, 94 void ParseQueryNodes(const base::string16& query,
95 bool always_prefix_search,
92 QueryNodeStarVector* nodes); 96 QueryNodeStarVector* nodes);
93 97
94 // Returns true if the string text matches the query nodes created by a call 98 // Returns true if the string text matches the query nodes created by a call
95 // to ParseQuery. If the query does match, each of the matching positions in 99 // to ParseQuery. If the query does match, each of the matching positions in
96 // the text is added to |match_positions|. 100 // the text is added to |match_positions|.
97 bool DoesQueryMatch(const base::string16& text, 101 bool DoesQueryMatch(const base::string16& text,
98 const QueryNodeStarVector& nodes, 102 const QueryNodeStarVector& nodes,
99 Snippet::MatchPositions* match_positions); 103 Snippet::MatchPositions* match_positions);
100 104
101 // Returns true if all of the |words| match the query |nodes| created by a 105 // Returns true if all of the |words| match the query |nodes| created by a
102 // call to ParseQuery. 106 // call to ParseQuery.
103 bool DoesQueryMatch(const QueryWordVector& words, 107 bool DoesQueryMatch(const QueryWordVector& words,
104 const QueryNodeStarVector& nodes); 108 const QueryNodeStarVector& nodes);
105 109
106 // Extracts the words from |text|, placing each word into |words|. 110 // Extracts the words from |text|, placing each word into |words|.
107 void ExtractQueryWords(const base::string16& text, 111 void ExtractQueryWords(const base::string16& text,
108 QueryWordVector* words); 112 QueryWordVector* words);
109 113
110 // Sorts the match positions in |matches| by their first index, then 114 // Sorts the match positions in |matches| by their first index, then
111 // coalesces any match positions that intersect each other. 115 // coalesces any match positions that intersect each other.
112 static void SortAndCoalesceMatchPositions(Snippet::MatchPositions* matches); 116 static void SortAndCoalesceMatchPositions(Snippet::MatchPositions* matches);
113 117
114 private: 118 private:
115 // Does the work of parsing |query|; creates nodes in |root| as appropriate. 119 // Does the work of parsing |query|; creates nodes in |root| as appropriate.
116 // This is invoked from both of the ParseQuery methods. 120 // This is invoked from both of the ParseQuery methods.
117 bool ParseQueryImpl(const base::string16& query, QueryNodeList* root); 121 // When |always_search_prefix| is true, no words are short enough for being
122 // considered for a prefix search.
123 // When |always_search_prefix| is false, only words long enough in terms of
124 // |IsWordLongEnoughForPrefixSearch| are considered for prefix search. The
125 // shorter words are then only considered for exact matches.
126 bool ParseQueryImpl(const base::string16& query,
127 bool always_search_prefix,
128 QueryNodeList* root);
118 129
119 DISALLOW_COPY_AND_ASSIGN(QueryParser); 130 DISALLOW_COPY_AND_ASSIGN(QueryParser);
120 }; 131 };
121 132
122 } // namespace query_parser 133 } // namespace query_parser
123 134
124 #endif // COMPONENTS_QUERY_PARSER_QUERY_PARSER_H_ 135 #endif // COMPONENTS_QUERY_PARSER_QUERY_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698