-
Notifications
You must be signed in to change notification settings - Fork 2
/
mysql-ko-ftparser.cc
110 lines (83 loc) · 2.98 KB
/
mysql-ko-ftparser.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <iostream>
#include <cstdlib>
#include <cctype>
#include "mysql/plugin.h"
#include "mecab_lib.h"
#if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__) || __GNUC__ == 2 && __GNUC_MINOR__ < 8)
#define __attribute__(A)
#endif
/*
한국어를 위한 MySQL FullText Parser입니다.
형태소 분석기로 은전한닢 프로젝트(http://eunjeon.blogspot.kr/)를 이용합니다.
*/
static int mysql_ko_ftparser_plugin_init(void* arg __attribute__((unused)))
{
return(0);
}
static int mysql_ko_ftparser_plugin_deinit(void* arg __attribute__((unused)))
{
return(0);
}
static int mysql_ko_ftparser_init(
MYSQL_FTPARSER_PARAM* param __attribute__((unused)))
{
param->ftparser_state = (void*) MeCab::initialize_parser();
return(0);
}
static int mysql_ko_ftparser_deinit(
MYSQL_FTPARSER_PARAM* param __attribute__((unused)))
{
MeCab::deinitialize_parser((MeCab::Parser*&) param->ftparser_state);
return(0);
}
static void add_word(MYSQL_FTPARSER_PARAM* param, char* word, size_t len)
{
MYSQL_FTPARSER_BOOLEAN_INFO bool_info =
{ FT_TOKEN_WORD, 0, 0, 0, 0, ' ', 0 };
param->mysql_add_word(param, word, len, &bool_info);
}
static int mysql_ko_ftparser_parse(MYSQL_FTPARSER_PARAM* param)
{
MeCab::Parser* parser = (MeCab::Parser*) param->ftparser_state;
for (const MeCab::Node* node = parser->parseToNode(param->doc,param->length)
; node != NULL
; node = node->next)
{
if (node == NULL)
{
throw std::runtime_error(parser->what());
}
if (MeCab::is_indexable_node(node))
{
add_word(param, (char*) node->surface, node->length);
}
}
return(0);
}
static struct st_mysql_ftparser mysql_ko_ftparser_descriptor =
{
MYSQL_FTPARSER_INTERFACE_VERSION, /* interface version */
mysql_ko_ftparser_parse, /* parsing function */
mysql_ko_ftparser_init, /* parser init functio */
mysql_ko_ftparser_deinit /* parser deinit function */
};
/*
Plugin library descriptor
*/
mysql_declare_plugin(ftexample)
{
MYSQL_FTPARSER_PLUGIN, /* type */
&mysql_ko_ftparser_descriptor, /* descriptor */
"mysql_ko_ftparser", /* name */
"mysql Heo", /* author */
"Korean Full-Text Parser", /* description */
PLUGIN_LICENSE_GPL,
mysql_ko_ftparser_plugin_init, /* init function (when loaded) */
mysql_ko_ftparser_plugin_deinit, /* deinit function (when unloaded) */
0x0001, /* version */
NULL, /* status variables */
NULL, /* system variables */
NULL,
0,
}
mysql_declare_plugin_end;