InnoDB Plugin  1.0
fts0ast.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 2007, 2014, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free Software
7 Foundation; version 2 of the License.
8 
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along with
14 this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
16 
17 *****************************************************************************/
18 
19 /******************************************************************/
26 #ifndef INNOBASE_FST0AST_H
27 #define INNOBASE_FST0AST_H
28 
29 #include "mem0mem.h"
30 #include "ha_prototypes.h"
31 
32 /* The type of AST Node */
40 };
41 
42 /* The FTS query operators that we support */
73 };
74 
75 /* Data types used by the FTS parser */
76 struct fts_lexer_t;
77 struct fts_ast_node_t;
78 struct fts_ast_state_t;
79 struct fts_ast_string_t;
80 
81 typedef dberr_t (*fts_ast_callback)(fts_ast_oper_t, fts_ast_node_t*, void*);
82 
83 /********************************************************************
84 Parse the string using the lexer setup within state.*/
85 int
86 fts_parse(
87 /*======*/
88  /* out: 0 on OK, 1 on error */
89  fts_ast_state_t* state);
91 /********************************************************************
92 Create an AST operator node */
93 extern
96 /*=====================*/
97  void* arg,
98  fts_ast_oper_t oper);
99 /********************************************************************
100 Create an AST term node, makes a copy of ptr */
101 extern
104 /*=====================*/
105  void* arg,
106  const fts_ast_string_t* ptr);
107 /********************************************************************
108 Create an AST text node */
109 extern
112 /*=====================*/
113  void* arg,
114  const fts_ast_string_t* ptr);
115 /********************************************************************
116 Create an AST expr list node */
117 extern
120 /*=====================*/
121  void* arg,
122  fts_ast_node_t* expr);
123 /********************************************************************
124 Create a sub-expression list node. This function takes ownership of
125 expr and is responsible for deleting it. */
126 extern
129 /*============================*/
130  /* out: new node */
131  void* arg,
132  fts_ast_node_t* expr);
133 /********************************************************************
134 Set the wildcard attribute of a term.*/
135 extern
136 void
138 /*======================*/
139  fts_ast_node_t* node);
140 /********************************************************************
141 Set the proximity attribute of a text node. */
142 
143 void
145 /*======================*/
146  fts_ast_node_t* node,
147  ulint distance);
149 /********************************************************************/
152 UNIV_INTERN
155 /*==============*/
156  fts_ast_node_t* node);
157 /********************************************************************
158 Add a sub-expression to an AST*/
159 extern
162 /*=============*/
163  fts_ast_node_t* list,
164  fts_ast_node_t* node);
165 /********************************************************************
166 Print the AST node recursively.*/
167 extern
168 void
170 /*===============*/
171  fts_ast_node_t* node);
172 /********************************************************************
173 For tracking node allocations, in case there is an during parsing.*/
174 extern
175 void
177 /*===================*/
178  fts_ast_state_t*state,
179  fts_ast_node_t* node);
180 /********************************************************************
181 Free node and expr allocations.*/
182 extern
183 void
185 /*===============*/
186  fts_ast_state_t*state);
188 /******************************************************************/
191 UNIV_INTERN
192 dberr_t
194 /*==========*/
195  fts_ast_oper_t oper,
196  fts_ast_node_t* node,
197  fts_ast_callback visitor,
198  void* arg,
199  bool* has_ignore)
203  __attribute__((nonnull, warn_unused_result));
204 /*****************************************************************/
209 UNIV_INTERN
210 dberr_t
212 /*==================*/
213  fts_ast_node_t* node,
214  fts_ast_callback visitor,
215  void* arg)
216  __attribute__((nonnull, warn_unused_result));
217 /********************************************************************
218 Create a lex instance.*/
219 UNIV_INTERN
220 fts_lexer_t*
222 /*=============*/
223  ibool boolean_mode,
224  const byte* query,
225  ulint query_len)
226  __attribute__((nonnull, malloc, warn_unused_result));
227 /********************************************************************
228 Free an fts_lexer_t instance.*/
229 UNIV_INTERN
230 void
232 /*===========*/
233  fts_lexer_t* fts_lexer)
235  __attribute__((nonnull));
236 
243 UNIV_INTERN
246  const byte* str,
247  ulint len);
248 
252 UNIV_INTERN
253 void
255  fts_ast_string_t* ast_str);
256 
262 UNIV_INTERN
263 ulint
265  const fts_ast_string_t* ast_str,
266  int base);
267 
271 UNIV_INTERN
272 void
274  const fts_ast_string_t* ast_str);
275 
276 /* String of length len.
277 We always store the string of length len with a terminating '\0',
278 regardless of there is any 0x00 in the string itself */
281  byte* str;
282 
284  ulint len;
285 };
286 
287 /* Query term type */
291 };
292 
293 /* Query text type */
296  ulint distance;
298 };
299 
300 /* The list of nodes in an expr list */
304 };
305 
306 /* FTS AST node to store the term, text, operator and sub-expressions.*/
315  bool visited;
317 };
318 
319 /* To track state during parsing */
327  fts_lexer_t* lexer;
328  CHARSET_INFO* charset;
330 };
331 
332 #ifdef UNIV_DEBUG
333 const char*
334 fts_ast_oper_name_get(fts_ast_oper_t oper);
335 const char*
336 fts_ast_node_type_get(fts_ast_type_t type);
337 #endif /* UNIV_DEBUG */
338 
339 #endif /* INNOBASE_FSTS0AST_H */