mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
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''
This commit is contained in:
@@ -284,28 +284,29 @@ static int ftb_parse_query_internal(void *param, byte *query, uint len)
|
||||
static void _ftb_parse_query(FTB *ftb, byte *query, uint len,
|
||||
struct st_mysql_ftparser *parser)
|
||||
{
|
||||
MYSQL_FTPARSER_PARAM param;
|
||||
MYSQL_FTPARSER_PARAM *param;
|
||||
MY_FTB_PARAM ftb_param;
|
||||
DBUG_ENTER("_ftb_parse_query");
|
||||
DBUG_ASSERT(parser);
|
||||
|
||||
if (ftb->state != UNINITIALIZED)
|
||||
return;
|
||||
DBUG_VOID_RETURN;
|
||||
|
||||
ftb_param.ftb= ftb;
|
||||
ftb_param.depth= 0;
|
||||
ftb_param.ftbe= ftb->root;
|
||||
ftb_param.up_quot= 0;
|
||||
|
||||
param.mysql_parse= ftb_parse_query_internal;
|
||||
param.mysql_add_word= ftb_query_add_word;
|
||||
param.ftparser_state= 0;
|
||||
param.mysql_ftparam= (void *)&ftb_param;
|
||||
param.cs= ftb->charset;
|
||||
param.doc= query;
|
||||
param.length= len;
|
||||
param.mode= MYSQL_FTPARSER_FULL_BOOLEAN_INFO;
|
||||
parser->parse(¶m);
|
||||
if (! (param= ftparser_call_initializer(ftb->info, ftb->keynr)))
|
||||
DBUG_VOID_RETURN;
|
||||
param->mysql_parse= ftb_parse_query_internal;
|
||||
param->mysql_add_word= ftb_query_add_word;
|
||||
param->mysql_ftparam= (void *)&ftb_param;
|
||||
param->cs= ftb->charset;
|
||||
param->doc= query;
|
||||
param->length= len;
|
||||
param->mode= MYSQL_FTPARSER_FULL_BOOLEAN_INFO;
|
||||
parser->parse(param);
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
|
||||
@@ -629,30 +630,30 @@ static int ftb_check_phrase_internal(void *param, byte *document, uint len)
|
||||
1 is returned if phrase found, 0 else.
|
||||
*/
|
||||
|
||||
static int _ftb_check_phrase(const byte *document, uint len,
|
||||
FTB_EXPR *ftbe, CHARSET_INFO *cs,
|
||||
struct st_mysql_ftparser *parser)
|
||||
static int _ftb_check_phrase(FTB *ftb, const byte *document, uint len,
|
||||
FTB_EXPR *ftbe, struct st_mysql_ftparser *parser)
|
||||
{
|
||||
MY_FTB_PHRASE_PARAM ftb_param;
|
||||
MYSQL_FTPARSER_PARAM param;
|
||||
MYSQL_FTPARSER_PARAM *param;
|
||||
DBUG_ENTER("_ftb_check_phrase");
|
||||
DBUG_ASSERT(parser);
|
||||
if (! (param= ftparser_call_initializer(ftb->info, ftb->keynr)))
|
||||
DBUG_RETURN(0);
|
||||
ftb_param.phrase= ftbe->phrase;
|
||||
ftb_param.document= ftbe->document;
|
||||
ftb_param.cs= cs;
|
||||
ftb_param.cs= ftb->charset;
|
||||
ftb_param.phrase_length= list_length(ftbe->phrase);
|
||||
ftb_param.document_length= 1;
|
||||
ftb_param.match= 0;
|
||||
|
||||
param.mysql_parse= ftb_check_phrase_internal;
|
||||
param.mysql_add_word= ftb_phrase_add_word;
|
||||
param.ftparser_state= 0;
|
||||
param.mysql_ftparam= (void *)&ftb_param;
|
||||
param.cs= cs;
|
||||
param.doc= (byte *)document;
|
||||
param.length= len;
|
||||
param.mode= MYSQL_FTPARSER_WITH_STOPWORDS;
|
||||
parser->parse(¶m);
|
||||
param->mysql_parse= ftb_check_phrase_internal;
|
||||
param->mysql_add_word= ftb_phrase_add_word;
|
||||
param->mysql_ftparam= (void *)&ftb_param;
|
||||
param->cs= ftb->charset;
|
||||
param->doc= (byte *)document;
|
||||
param->length= len;
|
||||
param->mode= MYSQL_FTPARSER_WITH_STOPWORDS;
|
||||
parser->parse(param);
|
||||
DBUG_RETURN(ftb_param.match ? 1 : 0);
|
||||
}
|
||||
|
||||
@@ -696,8 +697,8 @@ static void _ftb_climb_the_tree(FTB *ftb, FTB_WORD *ftbw, FT_SEG_ITERATOR *ftsi_
|
||||
{
|
||||
if (!ftsi.pos)
|
||||
continue;
|
||||
not_found = ! _ftb_check_phrase(ftsi.pos, ftsi.len,
|
||||
ftbe, ftb->charset, parser);
|
||||
not_found = ! _ftb_check_phrase(ftb, ftsi.pos, ftsi.len,
|
||||
ftbe, parser);
|
||||
}
|
||||
if (not_found) break;
|
||||
} /* ftbe->quot */
|
||||
@@ -861,7 +862,7 @@ float ft_boolean_find_relevance(FT_INFO *ftb, byte *record, uint length)
|
||||
FT_SEG_ITERATOR ftsi, ftsi2;
|
||||
my_off_t docid=ftb->info->lastpos;
|
||||
MY_FTB_FIND_PARAM ftb_param;
|
||||
MYSQL_FTPARSER_PARAM param;
|
||||
MYSQL_FTPARSER_PARAM *param;
|
||||
struct st_mysql_ftparser *parser= ftb->keynr == NO_SUCH_KEY ?
|
||||
&ft_default_parser :
|
||||
ftb->info->s->keyinfo[ftb->keynr].parser;
|
||||
@@ -870,6 +871,8 @@ float ft_boolean_find_relevance(FT_INFO *ftb, byte *record, uint length)
|
||||
return -2.0;
|
||||
if (!ftb->queue.elements)
|
||||
return 0;
|
||||
if (! (param= ftparser_call_initializer(ftb->info, ftb->keynr)))
|
||||
return 0;
|
||||
|
||||
if (ftb->state != INDEX_SEARCH && docid <= ftb->lastpos)
|
||||
{
|
||||
@@ -894,20 +897,20 @@ float ft_boolean_find_relevance(FT_INFO *ftb, byte *record, uint length)
|
||||
|
||||
ftb_param.ftb= ftb;
|
||||
ftb_param.ftsi= &ftsi2;
|
||||
param.mysql_parse= ftb_find_relevance_parse;
|
||||
param.mysql_add_word= ftb_find_relevance_add_word;
|
||||
param.ftparser_state= 0;
|
||||
param.mysql_ftparam= (void *)&ftb_param;
|
||||
param.cs= ftb->charset;
|
||||
param.mode= MYSQL_FTPARSER_SIMPLE_MODE;
|
||||
while (_mi_ft_segiterator(&ftsi))
|
||||
{
|
||||
if (!ftsi.pos)
|
||||
continue;
|
||||
|
||||
param.doc= (byte *)ftsi.pos;
|
||||
param.length= ftsi.len;
|
||||
parser->parse(¶m);
|
||||
/* Since subsequent call to _ftb_check_phrase overwrites param elements,
|
||||
it must be reinitialized at each iteration _inside_ the loop. */
|
||||
param->mysql_parse= ftb_find_relevance_parse;
|
||||
param->mysql_add_word= ftb_find_relevance_add_word;
|
||||
param->mysql_ftparam= (void *)&ftb_param;
|
||||
param->cs= ftb->charset;
|
||||
param->mode= MYSQL_FTPARSER_SIMPLE_MODE;
|
||||
param->doc= (byte *)ftsi.pos;
|
||||
param->length= ftsi.len;
|
||||
parser->parse(param);
|
||||
}
|
||||
ftbe=ftb->root;
|
||||
if (ftbe->docid[1]==docid && ftbe->cur_weight>0 &&
|
||||
|
Reference in New Issue
Block a user