1
/* Copyright (C) 2000-2002, 2004 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
/* Written by Sergei A. Golubchik, who has a shared copyright to this code
17
added support for long options (my_getopt) 22.5.2002 by Jani Tolonen */
21
#include <my_getopt.h>
23
static int key_field=FIELD_VARCHAR,extra_field=FIELD_SKIP_ENDSPACE;
24
static uint key_length=200,extra_length=50;
25
static int key_type=HA_KEYTYPE_TEXT;
26
static int verbose=0,silent=0,skip_update=0,
27
no_keys=0,no_stopwords=0,no_search=0,no_fulltext=0;
28
static int create_flag=0,error=0;
30
#define MAX_REC_LENGTH 300
31
static char record[MAX_REC_LENGTH],read_record[MAX_REC_LENGTH];
33
static int run_test(const char *filename);
34
static void get_options(int argc, char *argv[]);
35
static void create_record(char *, int);
38
static struct my_option my_long_options[] =
40
{"", 'v', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
41
{"", '?', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
42
{"", 'h', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
43
{"", 'V', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
44
{"", 'v', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
45
{"", 's', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
46
{"", 'N', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
47
{"", 'S', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
48
{"", 'K', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
49
{"", 'F', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
50
{"", 'U', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
51
{"", '#', "", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
52
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
55
int main(int argc, char *argv[])
59
get_options(argc,argv);
61
exit(run_test("FT1"));
64
static MI_COLUMNDEF recinfo[3];
65
static MI_KEYDEF keyinfo[2];
66
static HA_KEYSEG keyseg[10];
68
static int run_test(const char *filename)
74
bzero((char*) recinfo,sizeof(recinfo));
76
/* First define 2 columns */
77
recinfo[0].type=extra_field;
78
recinfo[0].length= (extra_field == FIELD_BLOB ? 4 + portable_sizeof_char_ptr :
80
if (extra_field == FIELD_VARCHAR)
81
recinfo[0].length+= HA_VARCHAR_PACKLENGTH(extra_length);
82
recinfo[1].type=key_field;
83
recinfo[1].length= (key_field == FIELD_BLOB ? 4+portable_sizeof_char_ptr :
85
if (key_field == FIELD_VARCHAR)
86
recinfo[1].length+= HA_VARCHAR_PACKLENGTH(key_length);
88
/* Define a key over the first column */
89
keyinfo[0].seg=keyseg;
91
keyinfo[0].block_length= 0; /* Default block length */
92
keyinfo[0].seg[0].type= key_type;
93
keyinfo[0].seg[0].flag= (key_field == FIELD_BLOB) ? HA_BLOB_PART:
94
(key_field == FIELD_VARCHAR) ? HA_VAR_LENGTH_PART:0;
95
keyinfo[0].seg[0].start=recinfo[0].length;
96
keyinfo[0].seg[0].length=key_length;
97
keyinfo[0].seg[0].null_bit= 0;
98
keyinfo[0].seg[0].null_pos=0;
99
keyinfo[0].seg[0].language= default_charset_info->number;
100
keyinfo[0].flag = (no_fulltext?HA_PACK_KEY:HA_FULLTEXT);
103
printf("- Creating isam-file\n");
104
if (mi_create(filename,(no_keys?0:1),keyinfo,2,recinfo,0,NULL,
105
(MI_CREATE_INFO*) 0, create_flag))
107
if (!(file=mi_open(filename,2,0)))
111
printf("- %s stopwords\n",no_stopwords?"Skipping":"Initializing");
112
ft_init_stopwords(no_stopwords?NULL:ft_precompiled_stopwords);
115
printf("- Writing key:s\n");
118
for (i=NUPD ; i<NDATAS; i++ )
120
create_record(record,i);
121
error=mi_write(file,record);
122
if (verbose || error)
123
printf("I= %2d mi_write: %d errno: %d, record: %s\n",
124
i,error,my_errno,data[i].f0);
130
printf("- Updating rows\n");
132
/* Read through all rows and update them */
135
while ((error=mi_rrnd(file,read_record,pos)) == 0)
137
create_record(record,NUPD-i-1);
138
if (mi_update(file,read_record,record))
140
printf("Can't update row: %.*s, error: %d\n",
141
keyinfo[0].seg[0].length,record,my_errno);
143
if(++i == NUPD) break;
147
printf("Found %d of %d rows\n", i,NUPD);
150
if (mi_close(file)) goto err;
151
if(no_search) return 0;
153
printf("- Reopening file\n");
154
if (!(file=mi_open(filename,2,0))) goto err;
156
printf("- Reading rows with key\n");
157
for (i=0 ; i < NQUERIES ; i++)
160
result=ft_nlq_init_search(file,0,(char*) query[i],strlen(query[i]),1);
163
printf("Query %d: `%s' failed with errno %3d\n",i,query[i],my_errno);
166
printf("Query %d: `%s'. Found: %d. Top five documents:\n",
167
i,query[i],result->ndocs);
171
err= ft_nlq_read_next(result, read_record);
172
if (err==HA_ERR_END_OF_FILE)
174
printf("No more matches!\n");
179
printf("ft_read_next %d failed with errno %3d\n",j,my_errno);
182
w=ft_nlq_get_relevance(result);
183
if (key_field == FIELD_VARCHAR)
187
p=recinfo[0].length+read_record;
189
printf("%10.7f: %.*s\n",w,(int) l,p+2);
192
printf("%10.7f: %.*s\n",w,recinfo[1].length,
193
recinfo[0].length+read_record);
195
ft_nlq_close_search(result);
198
if (mi_close(file)) goto err;
199
my_end(MY_CHECK_ERROR);
203
printf("got error: %3d when using myisam-database\n",my_errno);
204
return 1; /* skip warning */
207
static char blob_key[MAX_REC_LENGTH];
208
/* static char blob_record[MAX_REC_LENGTH+20*20]; */
210
void create_record(char *pos, int n)
212
bzero((char*) pos,MAX_REC_LENGTH);
213
if (recinfo[0].type == FIELD_BLOB)
217
strnmov(blob_key,data[n].f0,keyinfo[0].seg[0].length);
218
tmp=strlen(blob_key);
221
memcpy_fixed(pos+4,&ptr,sizeof(char*));
222
pos+=recinfo[0].length;
224
else if (recinfo[0].type == FIELD_VARCHAR)
227
/* -1 is here because pack_length is stored in seg->length */
228
uint pack_length= HA_VARCHAR_PACKLENGTH(keyinfo[0].seg[0].length-1);
229
strnmov(pos+pack_length,data[n].f0,keyinfo[0].seg[0].length);
230
tmp=strlen(pos+pack_length);
231
if (pack_length == 1)
235
pos+=recinfo[0].length;
239
strnmov(pos,data[n].f0,keyinfo[0].seg[0].length);
240
pos+=recinfo[0].length;
242
if (recinfo[1].type == FIELD_BLOB)
246
strnmov(blob_key,data[n].f2,keyinfo[0].seg[0].length);
247
tmp=strlen(blob_key);
250
memcpy_fixed(pos+4,&ptr,sizeof(char*));
251
pos+=recinfo[1].length;
253
else if (recinfo[1].type == FIELD_VARCHAR)
256
/* -1 is here because pack_length is stored in seg->length */
257
uint pack_length= HA_VARCHAR_PACKLENGTH(keyinfo[0].seg[0].length-1);
258
strnmov(pos+pack_length,data[n].f2,keyinfo[0].seg[0].length);
260
if (pack_length == 1)
264
pos+=recinfo[1].length;
268
strnmov(pos,data[n].f2,keyinfo[0].seg[0].length);
269
pos+=recinfo[1].length;
275
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
279
case 'v': verbose=1; break;
280
case 's': silent=1; break;
281
case 'F': no_fulltext=1; no_search=1;
282
case 'U': skip_update=1; break;
283
case 'K': no_keys=no_search=1; break;
284
case 'N': no_search=1; break;
285
case 'S': no_stopwords=1; break;
287
DBUG_PUSH (argument);
300
static void get_options(int argc,char *argv[])
304
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
312
printf("%s [options]\n", my_progname);
313
my_print_help(my_long_options);
314
my_print_variables(my_long_options);