2006-12-31 01:02:27 +01:00
|
|
|
/* Copyright (C) 2001-2005 MySQL AB
|
2001-04-11 13:04:03 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2001-04-11 13:04:03 +02:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
|
|
|
/* Written by Sergei A. Golubchik, who has a shared copyright to this code */
|
|
|
|
|
2001-10-09 14:53:54 +02:00
|
|
|
#define FT_CORE
|
2001-04-11 13:04:03 +02:00
|
|
|
#include "ftdefs.h"
|
|
|
|
|
|
|
|
/* search with natural language queries */
|
|
|
|
|
2002-06-11 10:20:31 +02:00
|
|
|
typedef struct ft_doc_rec
|
|
|
|
{
|
2001-10-09 14:53:54 +02:00
|
|
|
my_off_t dpos;
|
|
|
|
double weight;
|
|
|
|
} FT_DOC;
|
|
|
|
|
2002-06-11 10:20:31 +02:00
|
|
|
struct st_ft_info
|
|
|
|
{
|
2001-10-09 14:53:54 +02:00
|
|
|
struct _ft_vft *please;
|
|
|
|
MI_INFO *info;
|
|
|
|
int ndocs;
|
|
|
|
int curdoc;
|
|
|
|
FT_DOC doc[1];
|
|
|
|
};
|
|
|
|
|
2002-06-11 10:20:31 +02:00
|
|
|
typedef struct st_all_in_one
|
|
|
|
{
|
2001-04-11 13:04:03 +02:00
|
|
|
MI_INFO *info;
|
|
|
|
uint keynr;
|
2002-04-15 22:32:40 +02:00
|
|
|
CHARSET_INFO *charset;
|
2001-04-11 13:04:03 +02:00
|
|
|
uchar *keybuff;
|
|
|
|
TREE dtree;
|
|
|
|
} ALL_IN_ONE;
|
|
|
|
|
2002-06-11 10:20:31 +02:00
|
|
|
typedef struct st_ft_superdoc
|
|
|
|
{
|
2001-04-11 13:04:03 +02:00
|
|
|
FT_DOC doc;
|
|
|
|
FT_WORD *word_ptr;
|
|
|
|
double tmp_weight;
|
|
|
|
} FT_SUPERDOC;
|
|
|
|
|
2001-05-11 02:14:15 +02:00
|
|
|
static int FT_SUPERDOC_cmp(void* cmp_arg __attribute__((unused)),
|
|
|
|
FT_SUPERDOC *p1, FT_SUPERDOC *p2)
|
2001-04-11 13:04:03 +02:00
|
|
|
{
|
|
|
|
if (p1->doc.dpos < p2->doc.dpos)
|
|
|
|
return -1;
|
|
|
|
if (p1->doc.dpos == p2->doc.dpos)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio)
|
|
|
|
{
|
2004-02-29 22:58:45 +01:00
|
|
|
int subkeys, r;
|
|
|
|
uint keylen, doc_cnt;
|
2001-04-11 13:04:03 +02:00
|
|
|
FT_SUPERDOC sdoc, *sptr;
|
|
|
|
TREE_ELEMENT *selem;
|
2003-08-29 12:44:35 +02:00
|
|
|
double gweight=1;
|
2003-01-21 19:24:34 +01:00
|
|
|
MI_INFO *info=aio->info;
|
|
|
|
uchar *keybuff=aio->keybuff;
|
|
|
|
MI_KEYDEF *keyinfo=info->s->keyinfo+aio->keynr;
|
|
|
|
my_off_t key_root=info->s->state.key_root[aio->keynr];
|
2004-02-29 22:58:45 +01:00
|
|
|
uint extra=HA_FT_WLEN+info->s->base.rec_reflength;
|
2001-04-11 13:04:03 +02:00
|
|
|
#if HA_FT_WTYPE == HA_KEYTYPE_FLOAT
|
|
|
|
float tmp_weight;
|
|
|
|
#else
|
|
|
|
#error
|
|
|
|
#endif
|
|
|
|
|
2002-10-18 16:53:46 +02:00
|
|
|
DBUG_ENTER("walk_and_match");
|
|
|
|
|
2001-04-11 13:04:03 +02:00
|
|
|
word->weight=LWS_FOR_QUERY;
|
|
|
|
|
2003-01-21 19:24:34 +01:00
|
|
|
keylen=_ft_make_key(info,aio->keynr,(char*) keybuff,word,0);
|
2001-04-11 13:04:03 +02:00
|
|
|
keylen-=HA_FT_WLEN;
|
|
|
|
doc_cnt=0;
|
|
|
|
|
2004-04-26 14:53:31 +02:00
|
|
|
/* Skip rows inserted by current inserted */
|
2004-04-27 14:33:40 +02:00
|
|
|
for (r=_mi_search(info, keyinfo, keybuff, keylen, SEARCH_FIND, key_root) ;
|
2004-05-19 04:09:10 +02:00
|
|
|
!r &&
|
|
|
|
(subkeys=ft_sintXkorr(info->lastkey+info->lastkey_length-extra)) > 0 &&
|
|
|
|
info->lastpos >= info->state->data_file_length ;
|
2004-04-26 14:53:31 +02:00
|
|
|
r= _mi_search_next(info, keyinfo, info->lastkey,
|
|
|
|
info->lastkey_length, SEARCH_BIGGER, key_root))
|
|
|
|
;
|
|
|
|
|
2003-01-21 19:24:34 +01:00
|
|
|
info->update|= HA_STATE_AKTIV; /* for _mi_test_if_changed() */
|
2001-04-11 13:04:03 +02:00
|
|
|
|
2004-10-22 17:44:51 +02:00
|
|
|
/* The following should be safe, even if we compare doubles */
|
2003-08-19 20:53:45 +02:00
|
|
|
while (!r && gweight)
|
2001-04-11 13:04:03 +02:00
|
|
|
{
|
2003-01-21 19:24:34 +01:00
|
|
|
|
|
|
|
if (keylen &&
|
2003-11-08 15:41:24 +01:00
|
|
|
mi_compare_text(aio->charset,info->lastkey+1,
|
2004-03-25 14:05:01 +01:00
|
|
|
info->lastkey_length-extra-1, keybuff+1,keylen-1,0,0))
|
2002-06-03 11:59:31 +02:00
|
|
|
break;
|
2001-04-11 13:04:03 +02:00
|
|
|
|
2003-01-21 19:24:34 +01:00
|
|
|
if (subkeys<0)
|
|
|
|
{
|
|
|
|
if (doc_cnt)
|
|
|
|
DBUG_RETURN(1); /* index is corrupted */
|
|
|
|
/*
|
|
|
|
TODO here: unsafe optimization, should this word
|
|
|
|
be skipped (based on subkeys) ?
|
|
|
|
*/
|
|
|
|
keybuff+=keylen;
|
|
|
|
keyinfo=& info->s->ft2_keyinfo;
|
|
|
|
key_root=info->lastpos;
|
|
|
|
keylen=0;
|
|
|
|
r=_mi_search_first(info, keyinfo, key_root);
|
2004-04-27 21:17:10 +02:00
|
|
|
goto do_skip;
|
2003-01-21 19:24:34 +01:00
|
|
|
}
|
2001-04-11 13:04:03 +02:00
|
|
|
#if HA_FT_WTYPE == HA_KEYTYPE_FLOAT
|
2003-01-21 19:24:34 +01:00
|
|
|
tmp_weight=*(float*)&subkeys;
|
2001-04-11 13:04:03 +02:00
|
|
|
#else
|
|
|
|
#error
|
|
|
|
#endif
|
2004-10-22 17:44:51 +02:00
|
|
|
/* The following should be safe, even if we compare doubles */
|
2003-01-21 19:24:34 +01:00
|
|
|
if (tmp_weight==0)
|
|
|
|
DBUG_RETURN(doc_cnt); /* stopword, doc_cnt should be 0 */
|
2001-04-11 13:04:03 +02:00
|
|
|
|
2003-01-21 19:24:34 +01:00
|
|
|
sdoc.doc.dpos=info->lastpos;
|
2001-04-11 13:04:03 +02:00
|
|
|
|
|
|
|
/* saving document matched into dtree */
|
2002-08-30 11:40:40 +02:00
|
|
|
if (!(selem=tree_insert(&aio->dtree, &sdoc, 0, aio->dtree.custom_arg)))
|
2002-10-18 16:53:46 +02:00
|
|
|
DBUG_RETURN(1);
|
2001-04-11 13:04:03 +02:00
|
|
|
|
|
|
|
sptr=(FT_SUPERDOC *)ELEMENT_KEY((&aio->dtree), selem);
|
|
|
|
|
2002-06-11 10:20:31 +02:00
|
|
|
if (selem->count==1) /* document's first match */
|
2001-04-11 13:04:03 +02:00
|
|
|
sptr->doc.weight=0;
|
|
|
|
else
|
|
|
|
sptr->doc.weight+=sptr->tmp_weight*sptr->word_ptr->weight;
|
|
|
|
|
|
|
|
sptr->word_ptr=word;
|
|
|
|
sptr->tmp_weight=tmp_weight;
|
|
|
|
|
|
|
|
doc_cnt++;
|
2003-01-21 19:24:34 +01:00
|
|
|
|
2003-08-19 20:53:45 +02:00
|
|
|
gweight=word->weight*GWS_IN_USE;
|
|
|
|
if (gweight < 0 || doc_cnt > 2000000)
|
|
|
|
gweight=0;
|
2001-04-11 13:04:03 +02:00
|
|
|
|
2003-01-21 19:24:34 +01:00
|
|
|
if (_mi_test_if_changed(info) == 0)
|
|
|
|
r=_mi_search_next(info, keyinfo, info->lastkey, info->lastkey_length,
|
|
|
|
SEARCH_BIGGER, key_root);
|
2001-04-11 13:04:03 +02:00
|
|
|
else
|
2003-01-21 19:24:34 +01:00
|
|
|
r=_mi_search(info, keyinfo, info->lastkey, info->lastkey_length,
|
|
|
|
SEARCH_BIGGER, key_root);
|
2004-04-27 21:17:10 +02:00
|
|
|
do_skip:
|
|
|
|
while ((subkeys=ft_sintXkorr(info->lastkey+info->lastkey_length-extra)) > 0 &&
|
|
|
|
!r && info->lastpos >= info->state->data_file_length)
|
2004-04-27 14:33:40 +02:00
|
|
|
r= _mi_search_next(info, keyinfo, info->lastkey, info->lastkey_length,
|
|
|
|
SEARCH_BIGGER, key_root);
|
2004-04-26 14:53:31 +02:00
|
|
|
|
2001-04-11 13:04:03 +02:00
|
|
|
}
|
2003-08-19 20:53:45 +02:00
|
|
|
word->weight=gweight;
|
2002-10-18 16:53:46 +02:00
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
2001-04-11 13:04:03 +02:00
|
|
|
}
|
|
|
|
|
2002-06-11 10:20:31 +02:00
|
|
|
|
2001-04-11 13:04:03 +02:00
|
|
|
static int walk_and_copy(FT_SUPERDOC *from,
|
|
|
|
uint32 count __attribute__((unused)), FT_DOC **to)
|
|
|
|
{
|
2002-10-18 16:53:46 +02:00
|
|
|
DBUG_ENTER("walk_and_copy");
|
2002-06-11 10:20:31 +02:00
|
|
|
from->doc.weight+=from->tmp_weight*from->word_ptr->weight;
|
|
|
|
(*to)->dpos=from->doc.dpos;
|
|
|
|
(*to)->weight=from->doc.weight;
|
|
|
|
(*to)++;
|
2002-10-18 16:53:46 +02:00
|
|
|
DBUG_RETURN(0);
|
2001-04-11 13:04:03 +02:00
|
|
|
}
|
|
|
|
|
2003-10-23 15:21:06 +02:00
|
|
|
static int walk_and_push(FT_SUPERDOC *from,
|
|
|
|
uint32 count __attribute__((unused)), QUEUE *best)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("walk_and_copy");
|
|
|
|
from->doc.weight+=from->tmp_weight*from->word_ptr->weight;
|
2004-02-17 21:12:24 +01:00
|
|
|
set_if_smaller(best->elements, ft_query_expansion_limit-1);
|
2003-10-23 15:21:06 +02:00
|
|
|
queue_insert(best, (byte *)& from->doc);
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
2002-06-11 10:20:31 +02:00
|
|
|
|
2003-10-23 15:21:06 +02:00
|
|
|
|
|
|
|
static int FT_DOC_cmp(void *unused __attribute__((unused)),
|
|
|
|
FT_DOC *a, FT_DOC *b)
|
2001-09-25 20:31:02 +02:00
|
|
|
{
|
2002-06-11 10:20:31 +02:00
|
|
|
return sgn(b->weight - a->weight);
|
2001-09-25 20:31:02 +02:00
|
|
|
}
|
|
|
|
|
2002-06-11 10:20:31 +02:00
|
|
|
|
2001-10-09 14:53:54 +02:00
|
|
|
FT_INFO *ft_init_nlq_search(MI_INFO *info, uint keynr, byte *query,
|
2003-10-23 15:21:06 +02:00
|
|
|
uint query_len, uint flags, byte *record)
|
2001-04-11 13:04:03 +02:00
|
|
|
{
|
2003-10-23 15:21:06 +02:00
|
|
|
TREE wtree;
|
2001-09-25 20:31:02 +02:00
|
|
|
ALL_IN_ONE aio;
|
2001-04-11 13:04:03 +02:00
|
|
|
FT_DOC *dptr;
|
2001-10-09 14:53:54 +02:00
|
|
|
FT_INFO *dlist=NULL;
|
|
|
|
my_off_t saved_lastpos=info->lastpos;
|
WL#2575 - Fulltext: Parser plugin for FTS
Manual merge.
Makefile.am:
Added new 'plugin' subdir.
configure.in:
Added plugin related makefiles.
include/my_base.h:
Added HA_OPEN_FROM_SQL_LAYER flag - indicates that a table was openned from the sql layer.
Added HA_OPTION_RELIES_ON_SQL_LAYER flag - indicates that a table relies on the sql layer.
Added HA_CREATE_RELIES_ON_SQL_LAYER flag - indicates that a table must be created with
HA_OPTION_RELIES_ON_SQL_LAYER flag.
include/myisam.h:
Distinct fulltext parser number added.
include/plugin.h:
Revise comment.
sql/ha_myisam.cc:
Pass HA_OPEN_FROM_SQL_LAYER flag to mi_open().
Pass HA_CREATE_RELIES_ON_SQL_LAYER flag to mi_create().
sql/sql_plugin.cc:
Reuse "unused" dynamic array elements.
A check for plugin info interface version.
sql/sql_plugin.h:
Added plugin_type_names[] - string plugin type names.
sql/sql_show.cc:
Use plugin_type_names array instead of switch to find literal parser name representation.
sql/sql_table.cc:
Fixed that ALTER TABLE ... ADD INDEX loses WITH PARSER info.
storage/myisam/ft_boolean_search.c:
Call fulltext parser init() function, pass MYSQL_FTPARSER_PARAM, returned by
ftparser_call_initializer(), to parser->parse().
storage/myisam/ft_nlq_search.c:
Call fulltext parser init() function, pass MYSQL_FTPARSER_PARAM, returned by
ftparser_call_initializer(), to parser->parse().
storage/myisam/ft_parser.c:
Added two functions:
ftparser_call_initializer() - calls parser->init() function if specified and parser is not yet
initialized. Returns MYSQL_FTPARSER_PARAM *.
ftparser_call_deinitializer() - calls parser->deinit() function if specified and parser was
initialized. Deinitializes all parsers.
ft_parse() accepts additional param now - MYSQL_FTPARSER_PARM and passes it to parser->parse().
storage/myisam/ft_update.c:
Call fulltext parser init() function, pass MYSQL_FTPARSER_PARAM, returned by
ftparser_call_initializer(), to _mi_ft_parse().
_mi_ft_parse() accepts additional param now - MYSQL_FTPARSER_PARAM and passes
it to parser->parse().
storage/myisam/ftdefs.h:
Prototypes for new functions were added. MYSQL_FTPARSER_PARAM was added
to ft_parse and _mi_ft_parse().
storage/myisam/mi_close.c:
Free ftparser_param allocated by ftparser_call_initializer().
storage/myisam/mi_create.c:
If a table relies on the sql layer, set HA_OPTION_RELIES_ON_SQL_LAYER.
storage/myisam/mi_locking.c:
Call deinitializer for each initialized parser.
storage/myisam/mi_open.c:
Set default values for share->ftparser and keydef->ftparser_nr.
If a table is openned from the non-sql layer and HA_OPTION_RELIES_ON_SQL_LAYER is set, raise
HA_ERR_UNSUPPORTED error.
storage/myisam/myisamdef.h:
Added number of distinct parsers to MYISAM_SHARE.
Added ftparser_param to MI_INFO.
plugin/Makefile.am:
New BitKeeper file ``plugin/Makefile.am''
plugin/fulltext/Makefile.am:
New BitKeeper file ``plugin/fulltext/Makefile.am''
plugin/fulltext/plugin_example.c:
New BitKeeper file ``plugin/fulltext/plugin_example.c''
2005-12-28 13:05:30 +01:00
|
|
|
struct st_mysql_ftparser *parser;
|
|
|
|
MYSQL_FTPARSER_PARAM *ftparser_param;
|
2002-10-18 16:53:46 +02:00
|
|
|
DBUG_ENTER("ft_init_nlq_search");
|
2001-04-11 13:04:03 +02:00
|
|
|
|
2001-09-25 20:31:02 +02:00
|
|
|
/* black magic ON */
|
2001-10-09 14:53:54 +02:00
|
|
|
if ((int) (keynr = _mi_check_index(info,keynr)) < 0)
|
2002-10-18 16:53:46 +02:00
|
|
|
DBUG_RETURN(NULL);
|
2001-10-09 14:53:54 +02:00
|
|
|
if (_mi_readinfo(info,F_RDLCK,1))
|
2002-10-18 16:53:46 +02:00
|
|
|
DBUG_RETURN(NULL);
|
2001-09-25 20:31:02 +02:00
|
|
|
/* black magic OFF */
|
|
|
|
|
2001-10-09 14:53:54 +02:00
|
|
|
aio.info=info;
|
2001-04-11 13:04:03 +02:00
|
|
|
aio.keynr=keynr;
|
2003-01-21 19:24:34 +01:00
|
|
|
aio.charset=info->s->keyinfo[keynr].seg->charset;
|
2002-04-15 22:32:40 +02:00
|
|
|
aio.keybuff=info->lastkey+info->s->base.max_key_length;
|
WL#2575 - Fulltext: Parser plugin for FTS
Manual merge.
Makefile.am:
Added new 'plugin' subdir.
configure.in:
Added plugin related makefiles.
include/my_base.h:
Added HA_OPEN_FROM_SQL_LAYER flag - indicates that a table was openned from the sql layer.
Added HA_OPTION_RELIES_ON_SQL_LAYER flag - indicates that a table relies on the sql layer.
Added HA_CREATE_RELIES_ON_SQL_LAYER flag - indicates that a table must be created with
HA_OPTION_RELIES_ON_SQL_LAYER flag.
include/myisam.h:
Distinct fulltext parser number added.
include/plugin.h:
Revise comment.
sql/ha_myisam.cc:
Pass HA_OPEN_FROM_SQL_LAYER flag to mi_open().
Pass HA_CREATE_RELIES_ON_SQL_LAYER flag to mi_create().
sql/sql_plugin.cc:
Reuse "unused" dynamic array elements.
A check for plugin info interface version.
sql/sql_plugin.h:
Added plugin_type_names[] - string plugin type names.
sql/sql_show.cc:
Use plugin_type_names array instead of switch to find literal parser name representation.
sql/sql_table.cc:
Fixed that ALTER TABLE ... ADD INDEX loses WITH PARSER info.
storage/myisam/ft_boolean_search.c:
Call fulltext parser init() function, pass MYSQL_FTPARSER_PARAM, returned by
ftparser_call_initializer(), to parser->parse().
storage/myisam/ft_nlq_search.c:
Call fulltext parser init() function, pass MYSQL_FTPARSER_PARAM, returned by
ftparser_call_initializer(), to parser->parse().
storage/myisam/ft_parser.c:
Added two functions:
ftparser_call_initializer() - calls parser->init() function if specified and parser is not yet
initialized. Returns MYSQL_FTPARSER_PARAM *.
ftparser_call_deinitializer() - calls parser->deinit() function if specified and parser was
initialized. Deinitializes all parsers.
ft_parse() accepts additional param now - MYSQL_FTPARSER_PARM and passes it to parser->parse().
storage/myisam/ft_update.c:
Call fulltext parser init() function, pass MYSQL_FTPARSER_PARAM, returned by
ftparser_call_initializer(), to _mi_ft_parse().
_mi_ft_parse() accepts additional param now - MYSQL_FTPARSER_PARAM and passes
it to parser->parse().
storage/myisam/ftdefs.h:
Prototypes for new functions were added. MYSQL_FTPARSER_PARAM was added
to ft_parse and _mi_ft_parse().
storage/myisam/mi_close.c:
Free ftparser_param allocated by ftparser_call_initializer().
storage/myisam/mi_create.c:
If a table relies on the sql layer, set HA_OPTION_RELIES_ON_SQL_LAYER.
storage/myisam/mi_locking.c:
Call deinitializer for each initialized parser.
storage/myisam/mi_open.c:
Set default values for share->ftparser and keydef->ftparser_nr.
If a table is openned from the non-sql layer and HA_OPTION_RELIES_ON_SQL_LAYER is set, raise
HA_ERR_UNSUPPORTED error.
storage/myisam/myisamdef.h:
Added number of distinct parsers to MYISAM_SHARE.
Added ftparser_param to MI_INFO.
plugin/Makefile.am:
New BitKeeper file ``plugin/Makefile.am''
plugin/fulltext/Makefile.am:
New BitKeeper file ``plugin/fulltext/Makefile.am''
plugin/fulltext/plugin_example.c:
New BitKeeper file ``plugin/fulltext/plugin_example.c''
2005-12-28 13:05:30 +01:00
|
|
|
parser= info->s->keyinfo[keynr].parser;
|
2006-04-06 16:03:04 +02:00
|
|
|
if (! (ftparser_param= ftparser_call_initializer(info, keynr, 0)))
|
WL#2575 - Fulltext: Parser plugin for FTS
Manual merge.
Makefile.am:
Added new 'plugin' subdir.
configure.in:
Added plugin related makefiles.
include/my_base.h:
Added HA_OPEN_FROM_SQL_LAYER flag - indicates that a table was openned from the sql layer.
Added HA_OPTION_RELIES_ON_SQL_LAYER flag - indicates that a table relies on the sql layer.
Added HA_CREATE_RELIES_ON_SQL_LAYER flag - indicates that a table must be created with
HA_OPTION_RELIES_ON_SQL_LAYER flag.
include/myisam.h:
Distinct fulltext parser number added.
include/plugin.h:
Revise comment.
sql/ha_myisam.cc:
Pass HA_OPEN_FROM_SQL_LAYER flag to mi_open().
Pass HA_CREATE_RELIES_ON_SQL_LAYER flag to mi_create().
sql/sql_plugin.cc:
Reuse "unused" dynamic array elements.
A check for plugin info interface version.
sql/sql_plugin.h:
Added plugin_type_names[] - string plugin type names.
sql/sql_show.cc:
Use plugin_type_names array instead of switch to find literal parser name representation.
sql/sql_table.cc:
Fixed that ALTER TABLE ... ADD INDEX loses WITH PARSER info.
storage/myisam/ft_boolean_search.c:
Call fulltext parser init() function, pass MYSQL_FTPARSER_PARAM, returned by
ftparser_call_initializer(), to parser->parse().
storage/myisam/ft_nlq_search.c:
Call fulltext parser init() function, pass MYSQL_FTPARSER_PARAM, returned by
ftparser_call_initializer(), to parser->parse().
storage/myisam/ft_parser.c:
Added two functions:
ftparser_call_initializer() - calls parser->init() function if specified and parser is not yet
initialized. Returns MYSQL_FTPARSER_PARAM *.
ftparser_call_deinitializer() - calls parser->deinit() function if specified and parser was
initialized. Deinitializes all parsers.
ft_parse() accepts additional param now - MYSQL_FTPARSER_PARM and passes it to parser->parse().
storage/myisam/ft_update.c:
Call fulltext parser init() function, pass MYSQL_FTPARSER_PARAM, returned by
ftparser_call_initializer(), to _mi_ft_parse().
_mi_ft_parse() accepts additional param now - MYSQL_FTPARSER_PARAM and passes
it to parser->parse().
storage/myisam/ftdefs.h:
Prototypes for new functions were added. MYSQL_FTPARSER_PARAM was added
to ft_parse and _mi_ft_parse().
storage/myisam/mi_close.c:
Free ftparser_param allocated by ftparser_call_initializer().
storage/myisam/mi_create.c:
If a table relies on the sql layer, set HA_OPTION_RELIES_ON_SQL_LAYER.
storage/myisam/mi_locking.c:
Call deinitializer for each initialized parser.
storage/myisam/mi_open.c:
Set default values for share->ftparser and keydef->ftparser_nr.
If a table is openned from the non-sql layer and HA_OPTION_RELIES_ON_SQL_LAYER is set, raise
HA_ERR_UNSUPPORTED error.
storage/myisam/myisamdef.h:
Added number of distinct parsers to MYISAM_SHARE.
Added ftparser_param to MI_INFO.
plugin/Makefile.am:
New BitKeeper file ``plugin/Makefile.am''
plugin/fulltext/Makefile.am:
New BitKeeper file ``plugin/fulltext/Makefile.am''
plugin/fulltext/plugin_example.c:
New BitKeeper file ``plugin/fulltext/plugin_example.c''
2005-12-28 13:05:30 +01:00
|
|
|
goto err;
|
2001-04-11 13:04:03 +02:00
|
|
|
|
2003-10-23 15:21:06 +02:00
|
|
|
bzero(&wtree,sizeof(wtree));
|
2001-04-11 13:04:03 +02:00
|
|
|
|
2001-07-02 21:18:57 +02:00
|
|
|
init_tree(&aio.dtree,0,0,sizeof(FT_SUPERDOC),(qsort_cmp2)&FT_SUPERDOC_cmp,0,
|
|
|
|
NULL, NULL);
|
2001-04-11 13:04:03 +02:00
|
|
|
|
2003-10-23 15:21:06 +02:00
|
|
|
ft_parse_init(&wtree, aio.charset);
|
2006-05-30 18:15:18 +02:00
|
|
|
ftparser_param->flags= 0;
|
|
|
|
if (ft_parse(&wtree, query, query_len, parser, ftparser_param,
|
|
|
|
&wtree.mem_root))
|
2001-09-25 20:31:02 +02:00
|
|
|
goto err;
|
2001-04-11 13:04:03 +02:00
|
|
|
|
2003-10-23 15:21:06 +02:00
|
|
|
if (tree_walk(&wtree, (tree_walk_action)&walk_and_match, &aio,
|
2002-06-11 10:20:31 +02:00
|
|
|
left_root_right))
|
2003-10-23 15:21:06 +02:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (flags & FT_EXPAND && ft_query_expansion_limit)
|
|
|
|
{
|
|
|
|
QUEUE best;
|
2003-11-18 12:47:27 +01:00
|
|
|
init_queue(&best,ft_query_expansion_limit,0,0, (queue_compare) &FT_DOC_cmp,
|
|
|
|
0);
|
2003-10-23 15:21:06 +02:00
|
|
|
tree_walk(&aio.dtree, (tree_walk_action) &walk_and_push,
|
|
|
|
&best, left_root_right);
|
|
|
|
while (best.elements)
|
|
|
|
{
|
|
|
|
my_off_t docid=((FT_DOC *)queue_remove(& best, 0))->dpos;
|
|
|
|
if (!(*info->read_record)(info,docid,record))
|
|
|
|
{
|
|
|
|
info->update|= HA_STATE_AKTIV;
|
2006-05-30 18:15:18 +02:00
|
|
|
ftparser_param->flags= MYSQL_FTFLAGS_NEED_COPY;
|
|
|
|
_mi_ft_parse(&wtree, info, keynr, record, ftparser_param,
|
|
|
|
&wtree.mem_root);
|
2003-10-23 15:21:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
delete_queue(&best);
|
|
|
|
reset_tree(&aio.dtree);
|
|
|
|
if (tree_walk(&wtree, (tree_walk_action)&walk_and_match, &aio,
|
|
|
|
left_root_right))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
}
|
2001-04-11 13:04:03 +02:00
|
|
|
|
2005-02-16 00:27:23 +01:00
|
|
|
/*
|
|
|
|
If ndocs == 0, this will not allocate RAM for FT_INFO.doc[],
|
|
|
|
so if ndocs == 0, FT_INFO.doc[] must not be accessed.
|
|
|
|
*/
|
2001-10-09 14:53:54 +02:00
|
|
|
dlist=(FT_INFO *)my_malloc(sizeof(FT_INFO)+
|
2005-09-29 02:03:35 +02:00
|
|
|
sizeof(FT_DOC)*
|
|
|
|
(int)(aio.dtree.elements_in_tree-1),
|
2002-06-11 10:20:31 +02:00
|
|
|
MYF(0));
|
2003-10-23 15:21:06 +02:00
|
|
|
if (!dlist)
|
|
|
|
goto err;
|
2001-04-11 13:04:03 +02:00
|
|
|
|
2001-11-05 00:04:08 +01:00
|
|
|
dlist->please= (struct _ft_vft *) & _ft_vft_nlq;
|
2001-04-11 13:04:03 +02:00
|
|
|
dlist->ndocs=aio.dtree.elements_in_tree;
|
|
|
|
dlist->curdoc=-1;
|
|
|
|
dlist->info=aio.info;
|
|
|
|
dptr=dlist->doc;
|
|
|
|
|
2002-06-11 10:20:31 +02:00
|
|
|
tree_walk(&aio.dtree, (tree_walk_action) &walk_and_copy,
|
|
|
|
&dptr, left_root_right);
|
2001-04-11 13:04:03 +02:00
|
|
|
|
2003-10-22 17:57:09 +02:00
|
|
|
if (flags & FT_SORTED)
|
2003-10-23 15:21:06 +02:00
|
|
|
qsort2(dlist->doc, dlist->ndocs, sizeof(FT_DOC), (qsort2_cmp)&FT_DOC_cmp, 0);
|
2001-09-25 20:31:02 +02:00
|
|
|
|
|
|
|
err:
|
2003-10-23 15:21:06 +02:00
|
|
|
delete_tree(&aio.dtree);
|
|
|
|
delete_tree(&wtree);
|
2001-10-09 14:53:54 +02:00
|
|
|
info->lastpos=saved_lastpos;
|
2002-10-18 16:53:46 +02:00
|
|
|
DBUG_RETURN(dlist);
|
2001-04-11 13:04:03 +02:00
|
|
|
}
|
|
|
|
|
2002-06-11 10:20:31 +02:00
|
|
|
|
2001-10-09 14:53:54 +02:00
|
|
|
int ft_nlq_read_next(FT_INFO *handler, char *record)
|
2001-09-25 20:31:02 +02:00
|
|
|
{
|
|
|
|
MI_INFO *info= (MI_INFO *) handler->info;
|
|
|
|
|
|
|
|
if (++handler->curdoc >= handler->ndocs)
|
|
|
|
{
|
|
|
|
--handler->curdoc;
|
|
|
|
return HA_ERR_END_OF_FILE;
|
|
|
|
}
|
|
|
|
|
|
|
|
info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
|
|
|
|
|
|
|
|
info->lastpos=handler->doc[handler->curdoc].dpos;
|
|
|
|
if (!(*info->read_record)(info,info->lastpos,record))
|
|
|
|
{
|
|
|
|
info->update|= HA_STATE_AKTIV; /* Record is read */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return my_errno;
|
|
|
|
}
|
|
|
|
|
2002-06-11 10:20:31 +02:00
|
|
|
|
2001-11-28 17:55:45 +01:00
|
|
|
float ft_nlq_find_relevance(FT_INFO *handler,
|
2001-12-09 23:08:24 +01:00
|
|
|
byte *record __attribute__((unused)),
|
|
|
|
uint length __attribute__((unused)))
|
2001-10-09 14:53:54 +02:00
|
|
|
{
|
|
|
|
int a,b,c;
|
|
|
|
FT_DOC *docs=handler->doc;
|
2001-11-28 17:55:45 +01:00
|
|
|
my_off_t docid=handler->info->lastpos;
|
|
|
|
|
|
|
|
if (docid == HA_POS_ERROR)
|
|
|
|
return -5.0;
|
2001-10-09 14:53:54 +02:00
|
|
|
|
2001-11-22 19:35:35 +01:00
|
|
|
/* Assuming docs[] is sorted by dpos... */
|
2001-10-09 14:53:54 +02:00
|
|
|
|
|
|
|
for (a=0, b=handler->ndocs, c=(a+b)/2; b-a>1; c=(a+b)/2)
|
|
|
|
{
|
|
|
|
if (docs[c].dpos > docid)
|
|
|
|
b=c;
|
|
|
|
else
|
|
|
|
a=c;
|
|
|
|
}
|
2005-02-16 00:27:23 +01:00
|
|
|
/* bounds check to avoid accessing unallocated handler->doc */
|
|
|
|
if (a < handler->ndocs && docs[a].dpos == docid)
|
2001-12-09 23:08:24 +01:00
|
|
|
return (float) docs[a].weight;
|
2001-10-09 14:53:54 +02:00
|
|
|
else
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
2002-06-11 10:20:31 +02:00
|
|
|
|
2001-10-09 14:53:54 +02:00
|
|
|
void ft_nlq_close_search(FT_INFO *handler)
|
|
|
|
{
|
|
|
|
my_free((gptr)handler,MYF(0));
|
|
|
|
}
|
|
|
|
|
2002-06-11 10:20:31 +02:00
|
|
|
|
2001-10-09 14:53:54 +02:00
|
|
|
float ft_nlq_get_relevance(FT_INFO *handler)
|
|
|
|
{
|
2001-12-09 23:08:24 +01:00
|
|
|
return (float) handler->doc[handler->curdoc].weight;
|
2001-10-09 14:53:54 +02:00
|
|
|
}
|
|
|
|
|
2002-06-11 10:20:31 +02:00
|
|
|
|
2001-10-09 14:53:54 +02:00
|
|
|
void ft_nlq_reinit_search(FT_INFO *handler)
|
|
|
|
{
|
|
|
|
handler->curdoc=-1;
|
|
|
|
}
|
|
|
|
|