Skip to content

Commit 60e3b61

Browse files
Incompatible ftparser plugin API change.
mysql_parse() and mysql_add_word() now take a MYSQL_FTPARSER_PARAM*, not a mysql_ftparam.
1 parent 9874a76 commit 60e3b61

7 files changed

Lines changed: 59 additions & 57 deletions

File tree

client/Makefile.am

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ link_sources:
8383
for f in $(sql_src) ; do \
8484
rm -f $$f; \
8585
@LN_CP_F@ $(top_srcdir)/sql/$$f $$f; \
86-
done; \
87-
for f in $(strings_src) ; do \
88-
rm -f $(srcdir)/$$f; \
89-
@LN_CP_F@ $(top_srcdir)/strings/$$f $$f; \
90-
done; \
91-
rm -f $(srcdir)/my_user.c; \
92-
@LN_CP_F@ $(top_srcdir)/sql-common/my_user.c my_user.c
86+
done;
87+
for f in $(strings_src) ; do \
88+
rm -f $(srcdir)/$$f; \
89+
@LN_CP_F@ $(top_srcdir)/strings/$$f $$f; \
90+
done;
91+
-rm -f $(srcdir)/my_user.c;
92+
@LN_CP_F@ $(top_srcdir)/sql-common/my_user.c my_user.c
9393

9494

9595
# Don't update the files from bitkeeper

include/mysql/plugin.h

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ struct st_mysql_plugin
9898
API for Full-text [pre]parser plugin. (MYSQL_FTPARSER_PLUGIN)
9999
*/
100100

101-
#define MYSQL_FTPARSER_INTERFACE_VERSION 0x0000
101+
#define MYSQL_FTPARSER_INTERFACE_VERSION 0x0100
102102

103103
/* Parsing modes. Set in MYSQL_FTPARSER_PARAM::mode */
104+
enum enum_ftparser_mode
105+
{
104106
/*
105107
Fast and simple mode. This mode is used for indexing, and natural
106108
language queries.
@@ -109,7 +111,7 @@ struct st_mysql_plugin
109111
index. Stopwords or too short/long words should not be returned. The
110112
'boolean_info' argument of mysql_add_word() does not have to be set.
111113
*/
112-
#define MYSQL_FTPARSER_SIMPLE_MODE 0
114+
MYSQL_FTPARSER_SIMPLE_MODE= 0,
113115

114116
/*
115117
Parse with stopwords mode. This mode is used in boolean searches for
@@ -120,7 +122,7 @@ struct st_mysql_plugin
120122
or long. The 'boolean_info' argument of mysql_add_word() does not
121123
have to be set.
122124
*/
123-
#define MYSQL_FTPARSER_WITH_STOPWORDS 1
125+
MYSQL_FTPARSER_WITH_STOPWORDS= 1,
124126

125127
/*
126128
Parse in boolean mode. This mode is used to parse a boolean query string.
@@ -133,7 +135,8 @@ struct st_mysql_plugin
133135
MYSQL_FTPARSER_WITH_STOPWORDS mode, no word should be ignored.
134136
Instead, use FT_TOKEN_STOPWORD for the token type of such a word.
135137
*/
136-
#define MYSQL_FTPARSER_FULL_BOOLEAN_INFO 2
138+
MYSQL_FTPARSER_FULL_BOOLEAN_INFO= 2
139+
};
137140

138141
/*
139142
Token types for boolean mode searching (used for the type member of
@@ -209,22 +212,20 @@ typedef struct st_mysql_ftparser_boolean_info
209212
to invoke the MySQL default parser. If plugin's role is to extract
210213
textual data from .doc, .pdf or .xml content, it might extract
211214
plaintext from the content, and then pass the text to the default
212-
MySQL parser to be parsed. When mysql_parser is called, its param
213-
argument should be given as the mysql_ftparam value.
215+
MySQL parser to be parsed.
214216
215217
mysql_add_word: A server callback to add a new word. When parsing
216218
a document, the server sets this to point at a function that adds
217219
the word to MySQL full-text index. When parsing a search query,
218220
this function will add the new word to the list of words to search
219-
for. When mysql_add_word is called, its param argument should be
220-
given as the mysql_ftparam value. boolean_info can be NULL for all
221-
cases except when mode is MYSQL_FTPARSER_FULL_BOOLEAN_INFO.
221+
for. The boolean_info argument can be NULL for all cases except
222+
when mode is MYSQL_FTPARSER_FULL_BOOLEAN_INFO.
222223
223224
ftparser_state: A generic pointer. The plugin can set it to point
224225
to information to be used internally for its own purposes.
225226
226-
mysql_ftparam: This is set by the server. It is passed as the first
227-
argument to the mysql_parse or mysql_add_word callback. The plugin
227+
mysql_ftparam: This is set by the server. It is used by MySQL functions
228+
called via mysql_parse() and mysql_add_word() callback. The plugin
228229
should not modify it.
229230
230231
cs: Information about the character set of the document or query string.
@@ -239,15 +240,17 @@ typedef struct st_mysql_ftparser_boolean_info
239240

240241
typedef struct st_mysql_ftparser_param
241242
{
242-
int (*mysql_parse)(void *param, char *doc, int doc_len);
243-
int (*mysql_add_word)(void *param, char *word, int word_len,
243+
int (*mysql_parse)(struct st_mysql_ftparser_param *,
244+
char *doc, int doc_len);
245+
int (*mysql_add_word)(struct st_mysql_ftparser_param *,
246+
char *word, int word_len,
244247
MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info);
245248
void *ftparser_state;
246249
void *mysql_ftparam;
247250
struct charset_info_st *cs;
248251
char *doc;
249252
int length;
250-
int mode;
253+
enum enum_ftparser_mode mode;
251254
} MYSQL_FTPARSER_PARAM;
252255

253256
/*

plugin/fulltext/plugin_example.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,7 @@ static void add_word(MYSQL_FTPARSER_PARAM *param, char *word, size_t len)
144144
MYSQL_FTPARSER_BOOLEAN_INFO bool_info=
145145
{ FT_TOKEN_WORD, 0, 0, 0, 0, ' ', 0 };
146146

147-
if (param->mode == MYSQL_FTPARSER_FULL_BOOLEAN_INFO)
148-
param->mysql_add_word(param->mysql_ftparam, word, len, &bool_info);
149-
else
150-
param->mysql_add_word(param->mysql_ftparam, word, len, 0);
147+
param->mysql_add_word(param, word, len, &bool_info);
151148
}
152149

153150
/*

sql/sql_plugin.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ static int min_plugin_interface_version= 0x0000;
4141
static int min_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
4242
{
4343
0x0000,
44-
0x0000,
45-
0x0000
44+
MYSQL_HANDLERTON_INTERFACE_VERSION,
45+
MYSQL_FTPARSER_INTERFACE_VERSION
4646
};
4747
static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
4848
{
4949
0x0000, /* UDF: not implemented */
5050
MYSQL_HANDLERTON_INTERFACE_VERSION,
5151
MYSQL_FTPARSER_INTERFACE_VERSION
5252
};
53+
5354
static DYNAMIC_ARRAY plugin_dl_array;
5455
static DYNAMIC_ARRAY plugin_array;
5556
static HASH plugin_hash[MYSQL_MAX_PLUGIN_TYPE_NUM];

storage/myisam/ft_boolean_search.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,18 @@ static int FTB_WORD_cmp_list(CHARSET_INFO *cs, FTB_WORD **a, FTB_WORD **b)
160160

161161
typedef struct st_my_ftb_param
162162
{
163-
MYSQL_FTPARSER_PARAM *up;
164163
FTB *ftb;
165164
FTB_EXPR *ftbe;
166165
byte *up_quot;
167166
uint depth;
168167
} MY_FTB_PARAM;
169168

170169

171-
static int ftb_query_add_word(void *param, char *word, int word_len,
170+
static int ftb_query_add_word(MYSQL_FTPARSER_PARAM *param,
171+
char *word, int word_len,
172172
MYSQL_FTPARSER_BOOLEAN_INFO *info)
173173
{
174-
MY_FTB_PARAM *ftb_param= (MY_FTB_PARAM *)param;
174+
MY_FTB_PARAM *ftb_param= param->mysql_ftparam;
175175
FTB_WORD *ftbw;
176176
FTB_EXPR *ftbe, *tmp_expr;
177177
FT_WORD *phrase_word;
@@ -269,9 +269,10 @@ static int ftb_query_add_word(void *param, char *word, int word_len,
269269
}
270270

271271

272-
static int ftb_parse_query_internal(void *param, char *query, int len)
272+
static int ftb_parse_query_internal(MYSQL_FTPARSER_PARAM *param,
273+
char *query, int len)
273274
{
274-
MY_FTB_PARAM *ftb_param= (MY_FTB_PARAM *)param;
275+
MY_FTB_PARAM *ftb_param= param->mysql_ftparam;
275276
MYSQL_FTPARSER_BOOLEAN_INFO info;
276277
CHARSET_INFO *cs= ftb_param->ftb->charset;
277278
char **start= &query;
@@ -281,7 +282,7 @@ static int ftb_parse_query_internal(void *param, char *query, int len)
281282
info.prev= ' ';
282283
info.quot= 0;
283284
while (ft_get_word(cs, start, end, &w, &info))
284-
ftb_param->up->mysql_add_word(param, w.pos, w.len, &info);
285+
param->mysql_add_word(param, w.pos, w.len, &info);
285286
return(0);
286287
}
287288

@@ -299,7 +300,6 @@ static void _ftb_parse_query(FTB *ftb, byte *query, uint len,
299300
if (! (param= ftparser_call_initializer(ftb->info, ftb->keynr, 0)))
300301
DBUG_VOID_RETURN;
301302

302-
ftb_param.up= param;
303303
ftb_param.ftb= ftb;
304304
ftb_param.depth= 0;
305305
ftb_param.ftbe= ftb->root;
@@ -571,7 +571,6 @@ FT_INFO * ft_init_boolean_search(MI_INFO *info, uint keynr, byte *query,
571571

572572
typedef struct st_my_ftb_phrase_param
573573
{
574-
MYSQL_FTPARSER_PARAM *up;
575574
LIST *phrase;
576575
LIST *document;
577576
CHARSET_INFO *cs;
@@ -581,10 +580,11 @@ typedef struct st_my_ftb_phrase_param
581580
} MY_FTB_PHRASE_PARAM;
582581

583582

584-
static int ftb_phrase_add_word(void *param, char *word, int word_len,
583+
static int ftb_phrase_add_word(MYSQL_FTPARSER_PARAM *param,
584+
char *word, int word_len,
585585
MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info __attribute__((unused)))
586586
{
587-
MY_FTB_PHRASE_PARAM *phrase_param= (MY_FTB_PHRASE_PARAM *)param;
587+
MY_FTB_PHRASE_PARAM *phrase_param= param->mysql_ftparam;
588588
FT_WORD *w= (FT_WORD *)phrase_param->document->data;
589589
LIST *phrase, *document;
590590
w->pos= word;
@@ -611,14 +611,15 @@ static int ftb_phrase_add_word(void *param, char *word, int word_len,
611611
}
612612

613613

614-
static int ftb_check_phrase_internal(void *param, char *document, int len)
614+
static int ftb_check_phrase_internal(MYSQL_FTPARSER_PARAM *param,
615+
char *document, int len)
615616
{
616617
FT_WORD word;
617-
MY_FTB_PHRASE_PARAM *phrase_param= (MY_FTB_PHRASE_PARAM *)param;
618+
MY_FTB_PHRASE_PARAM *phrase_param= param->mysql_ftparam;
618619
const char *docend= document + len;
619620
while (ft_simple_get_word(phrase_param->cs, &document, docend, &word, FALSE))
620621
{
621-
phrase_param->up->mysql_add_word(param, word.pos, word.len, 0);
622+
param->mysql_add_word(param, word.pos, word.len, 0);
622623
if (phrase_param->match)
623624
return 1;
624625
}
@@ -651,7 +652,6 @@ static int _ftb_check_phrase(FTB *ftb, const byte *document, uint len,
651652
if (! (param= ftparser_call_initializer(ftb->info, ftb->keynr, 1)))
652653
DBUG_RETURN(0);
653654

654-
ftb_param.up= param;
655655
ftb_param.phrase= ftbe->phrase;
656656
ftb_param.document= ftbe->document;
657657
ftb_param.cs= ftb->charset;
@@ -820,16 +820,16 @@ int ft_boolean_read_next(FT_INFO *ftb, char *record)
820820

821821
typedef struct st_my_ftb_find_param
822822
{
823-
MYSQL_FTPARSER_PARAM *up;
824823
FT_INFO *ftb;
825824
FT_SEG_ITERATOR *ftsi;
826825
} MY_FTB_FIND_PARAM;
827826

828827

829-
static int ftb_find_relevance_add_word(void *param, char *word, int len,
828+
static int ftb_find_relevance_add_word(MYSQL_FTPARSER_PARAM *param,
829+
char *word, int len,
830830
MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info __attribute__((unused)))
831831
{
832-
MY_FTB_FIND_PARAM *ftb_param= (MY_FTB_FIND_PARAM *)param;
832+
MY_FTB_FIND_PARAM *ftb_param= param->mysql_ftparam;
833833
FT_INFO *ftb= ftb_param->ftb;
834834
FTB_WORD *ftbw;
835835
int a, b, c;
@@ -859,14 +859,15 @@ static int ftb_find_relevance_add_word(void *param, char *word, int len,
859859
}
860860

861861

862-
static int ftb_find_relevance_parse(void *param, char *doc, int len)
862+
static int ftb_find_relevance_parse(MYSQL_FTPARSER_PARAM *param,
863+
char *doc, int len)
863864
{
864-
MY_FTB_FIND_PARAM *ftb_param=(MY_FTB_FIND_PARAM *)param;
865+
MY_FTB_FIND_PARAM *ftb_param= param->mysql_ftparam;
865866
FT_INFO *ftb= ftb_param->ftb;
866867
char *end= doc + len;
867868
FT_WORD w;
868869
while (ft_simple_get_word(ftb->charset, &doc, end, &w, TRUE))
869-
ftb_param->up->mysql_add_word(param, w.pos, w.len, 0);
870+
param->mysql_add_word(param, w.pos, w.len, 0);
870871
return(0);
871872
}
872873

@@ -910,7 +911,6 @@ float ft_boolean_find_relevance(FT_INFO *ftb, byte *record, uint length)
910911
_mi_ft_segiterator_init(ftb->info, ftb->keynr, record, &ftsi);
911912
memcpy(&ftsi2, &ftsi, sizeof(ftsi));
912913

913-
ftb_param.up= param;
914914
ftb_param.ftb= ftb;
915915
ftb_param.ftsi= &ftsi2;
916916
param->mysql_parse= ftb_find_relevance_parse;

storage/myisam/ft_parser.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ typedef struct st_ft_docstat {
2727

2828
typedef struct st_my_ft_parser_param
2929
{
30-
MYSQL_FTPARSER_PARAM *up;
3130
TREE *wtree;
3231
my_bool with_alloc;
3332
} MY_FT_PARSER_PARAM;
@@ -241,14 +240,16 @@ void ft_parse_init(TREE *wtree, CHARSET_INFO *cs)
241240
}
242241

243242

244-
static int ft_add_word(void *param, byte *word, uint word_len,
243+
static int ft_add_word(MYSQL_FTPARSER_PARAM *param,
244+
char *word, int word_len,
245245
MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info __attribute__((unused)))
246246
{
247247
TREE *wtree;
248248
FT_WORD w;
249+
MY_FT_PARSER_PARAM *ft_param=param->mysql_ftparam;
249250
DBUG_ENTER("ft_add_word");
250-
wtree= ((MY_FT_PARSER_PARAM *)param)->wtree;
251-
if (((MY_FT_PARSER_PARAM *)param)->with_alloc)
251+
wtree= ft_param->wtree;
252+
if (ft_param->with_alloc)
252253
{
253254
byte *ptr;
254255
/* allocating the data in the tree - to avoid mallocs and frees */
@@ -269,16 +270,17 @@ static int ft_add_word(void *param, byte *word, uint word_len,
269270
}
270271

271272

272-
static int ft_parse_internal(void *param, byte *doc, int doc_len)
273+
static int ft_parse_internal(MYSQL_FTPARSER_PARAM *param,
274+
byte *doc, int doc_len)
273275
{
274276
byte *end=doc+doc_len;
275-
MY_FT_PARSER_PARAM *ft_param=(MY_FT_PARSER_PARAM *)param;
277+
MY_FT_PARSER_PARAM *ft_param=param->mysql_ftparam;
276278
TREE *wtree= ft_param->wtree;
277279
FT_WORD w;
278280
DBUG_ENTER("ft_parse_internal");
279281

280282
while (ft_simple_get_word(wtree->custom_arg, &doc, end, &w, TRUE))
281-
if (ft_param->up->mysql_add_word(param, w.pos, w.len, 0))
283+
if (param->mysql_add_word(param, w.pos, w.len, 0))
282284
DBUG_RETURN(1);
283285
DBUG_RETURN(0);
284286
}
@@ -292,7 +294,6 @@ int ft_parse(TREE *wtree, byte *doc, int doclen, my_bool with_alloc,
292294
DBUG_ENTER("ft_parse");
293295
DBUG_ASSERT(parser);
294296

295-
my_param.up= param;
296297
my_param.wtree= wtree;
297298
my_param.with_alloc= with_alloc;
298299

storage/myisam/ft_static.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ const char *ft_precompiled_stopwords[] = {
629629

630630
static int ft_default_parser_parse(MYSQL_FTPARSER_PARAM *param)
631631
{
632-
return param->mysql_parse(param->mysql_ftparam, param->doc, param->length);
632+
return param->mysql_parse(param, param->doc, param->length);
633633
}
634634

635635
struct st_mysql_ftparser ft_default_parser=

0 commit comments

Comments
 (0)