MySQL 8.0.39
Source Code Documentation
plugin_ftparser.h
Go to the documentation of this file.
1/* Copyright (c) 2005, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef _my_plugin_ftparser_h
25#define _my_plugin_ftparser_h
26
27/**
28 @file include/mysql/plugin_ftparser.h
29*/
30
31/*************************************************************************
32 API for Full-text parser plugin. (MYSQL_FTPARSER_PLUGIN)
33*/
34
35#ifndef MYSQL_SERVER
36#include "plugin.h"
37#endif
38
39/* Parsing modes. Set in MYSQL_FTPARSER_PARAM::mode */
41 /*
42 Fast and simple mode. This mode is used for indexing, and natural
43 language queries.
44
45 The parser is expected to return only those words that go into the
46 index. Stopwords or too short/long words should not be returned. The
47 'boolean_info' argument of mysql_add_word() does not have to be set.
48 */
50
51 /*
52 Parse with stopwords mode. This mode is used in boolean searches for
53 "phrase matching."
54
55 The parser is not allowed to ignore words in this mode. Every word
56 should be returned, including stopwords and words that are too short
57 or long. The 'boolean_info' argument of mysql_add_word() does not
58 have to be set.
59 */
61
62 /*
63 Parse in boolean mode. This mode is used to parse a boolean query string.
64
65 The parser should provide a valid MYSQL_FTPARSER_BOOLEAN_INFO
66 structure in the 'boolean_info' argument to mysql_add_word().
67 Usually that means that the parser should recognize boolean operators
68 in the parsing stream and set appropriate fields in
69 MYSQL_FTPARSER_BOOLEAN_INFO structure accordingly. As for
70 MYSQL_FTPARSER_WITH_STOPWORDS mode, no word should be ignored.
71 Instead, use FT_TOKEN_STOPWORD for the token type of such a word.
72 */
74};
75
76/*
77 Token types for boolean mode searching (used for the type member of
78 MYSQL_FTPARSER_BOOLEAN_INFO struct)
79
80 FT_TOKEN_EOF: End of data.
81 FT_TOKEN_WORD: Regular word.
82 FT_TOKEN_LEFT_PAREN: Left parenthesis (start of group/sub-expression).
83 FT_TOKEN_RIGHT_PAREN: Right parenthesis (end of group/sub-expression).
84 FT_TOKEN_STOPWORD: Stopword.
85*/
86
93};
94
95/*
96 This structure is used in boolean search mode only. It conveys
97 boolean-mode metadata to the MySQL search engine for every word in
98 the search query. A valid instance of this structure must be filled
99 in by the plugin parser and passed as an argument in the call to
100 mysql_add_word (the callback function in the MYSQL_FTPARSER_PARAM
101 structure) when a query is parsed in boolean mode.
102
103 type: The token type. Should be one of the enum_ft_token_type values.
104
105 yesno: Whether the word must be present for a match to occur:
106 >0 Must be present
107 <0 Must not be present
108 0 Neither; the word is optional but its presence increases the relevance
109 With the default settings of the ft_boolean_syntax system variable,
110 >0 corresponds to the '+' operator, <0 corresponds to the '-' operator,
111 and 0 means neither operator was used.
112
113 weight_adjust: A weighting factor that determines how much a match
114 for the word counts. Positive values increase, negative - decrease the
115 relative word's importance in the query.
116
117 wasign: The sign of the word's weight in the query. If it's non-negative
118 the match for the word will increase document relevance, if it's
119 negative - decrease (the word becomes a "noise word", the less of it the
120 better).
121
122 trunc: Corresponds to the '*' operator in the default setting of the
123 ft_boolean_syntax system variable.
124
125 position: Start position in bytes of the word in the document, used by InnoDB
126 FTS.
127*/
128
131 int yesno;
133 char wasign;
134 char trunc;
136 /* These are parser state and must be removed. */
137 char prev;
138 char *quot;
139};
140
141/*
142 The following flag means that buffer with a string (document, word)
143 may be overwritten by the caller before the end of the parsing (that is
144 before st_mysql_ftparser::deinit() call). If one needs the string
145 to survive between two successive calls of the parsing function, she
146 needs to save a copy of it. The flag may be set by MySQL before calling
147 st_mysql_ftparser::parse(), or it may be set by a plugin before calling
148 MYSQL_FTPARSER_PARAM::mysql_parse() or
149 MYSQL_FTPARSER_PARAM::mysql_add_word().
150*/
151#define MYSQL_FTFLAGS_NEED_COPY 1
152
153/*
154 An argument of the full-text parser plugin. This structure is
155 filled in by MySQL server and passed to the parsing function of the
156 plugin as an in/out parameter.
157
158 mysql_parse: A pointer to the built-in parser implementation of the
159 server. It's set by the server and can be used by the parser plugin
160 to invoke the MySQL default parser. If plugin's role is to extract
161 textual data from .doc, .pdf or .xml content, it might extract
162 plaintext from the content, and then pass the text to the default
163 MySQL parser to be parsed.
164
165 mysql_add_word: A server callback to add a new word. When parsing
166 a document, the server sets this to point at a function that adds
167 the word to MySQL full-text index. When parsing a search query,
168 this function will add the new word to the list of words to search
169 for. The boolean_info argument can be NULL for all cases except
170 when mode is MYSQL_FTPARSER_FULL_BOOLEAN_INFO.
171
172 ftparser_state: A generic pointer. The plugin can set it to point
173 to information to be used internally for its own purposes.
174
175 mysql_ftparam: This is set by the server. It is used by MySQL functions
176 called via mysql_parse() and mysql_add_word() callback. The plugin
177 should not modify it.
178
179 cs: Information about the character set of the document or query string.
180
181 doc: A pointer to the document or query string to be parsed.
182
183 length: Length of the document or query string, in bytes.
184
185 flags: See MYSQL_FTFLAGS_* constants above.
186
187 mode: The parsing mode. With boolean operators, with stopwords, or
188 nothing. See enum_ftparser_mode above.
189*/
190
192 int (*mysql_parse)(MYSQL_FTPARSER_PARAM *, char *doc, int doc_len);
193 int (*mysql_add_word)(MYSQL_FTPARSER_PARAM *, char *word, int word_len,
194 MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info);
198 char *doc;
200 int flags;
202};
203
204/*
205 Full-text parser descriptor.
206
207 interface_version is, e.g., MYSQL_FTPARSER_INTERFACE_VERSION.
208 The parsing, initialization, and deinitialization functions are
209 invoked per SQL statement for which the parser is used.
210*/
211
217};
218
219#endif
enum_ft_token_type
Definition: plugin_ftparser.h:87
@ FT_TOKEN_RIGHT_PAREN
Definition: plugin_ftparser.h:91
@ FT_TOKEN_LEFT_PAREN
Definition: plugin_ftparser.h:90
@ FT_TOKEN_STOPWORD
Definition: plugin_ftparser.h:92
@ FT_TOKEN_WORD
Definition: plugin_ftparser.h:89
@ FT_TOKEN_EOF
Definition: plugin_ftparser.h:88
enum_ftparser_mode
Definition: plugin_ftparser.h:40
@ MYSQL_FTPARSER_FULL_BOOLEAN_INFO
Definition: plugin_ftparser.h:73
@ MYSQL_FTPARSER_SIMPLE_MODE
Definition: plugin_ftparser.h:49
@ MYSQL_FTPARSER_WITH_STOPWORDS
Definition: plugin_ftparser.h:60
Definition: m_ctype.h:385
Definition: plugin_ftparser.h:129
char * quot
Definition: plugin_ftparser.h:138
char trunc
Definition: plugin_ftparser.h:134
int weight_adjust
Definition: plugin_ftparser.h:132
char prev
Definition: plugin_ftparser.h:137
enum enum_ft_token_type type
Definition: plugin_ftparser.h:130
int yesno
Definition: plugin_ftparser.h:131
int position
Definition: plugin_ftparser.h:135
char wasign
Definition: plugin_ftparser.h:133
Definition: plugin_ftparser.h:191
const CHARSET_INFO * cs
Definition: plugin_ftparser.h:197
char * doc
Definition: plugin_ftparser.h:198
enum enum_ftparser_mode mode
Definition: plugin_ftparser.h:201
int flags
Definition: plugin_ftparser.h:200
void * ftparser_state
Definition: plugin_ftparser.h:195
int(* mysql_add_word)(MYSQL_FTPARSER_PARAM *, char *word, int word_len, MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info)
Definition: plugin_ftparser.h:193
void * mysql_ftparam
Definition: plugin_ftparser.h:196
int length
Definition: plugin_ftparser.h:199
int(* mysql_parse)(MYSQL_FTPARSER_PARAM *, char *doc, int doc_len)
Definition: plugin_ftparser.h:192
Definition: plugin_ftparser.h:212
int(* init)(MYSQL_FTPARSER_PARAM *param)
Definition: plugin_ftparser.h:215
int(* deinit)(MYSQL_FTPARSER_PARAM *param)
Definition: plugin_ftparser.h:216
int(* parse)(MYSQL_FTPARSER_PARAM *param)
Definition: plugin_ftparser.h:214
int interface_version
Definition: plugin_ftparser.h:213