|
[2009献礼] 发布MySQL-5.1.30的scws-1.x分词插件(090611最新修订)
|
|
2009-01-01, 01:38 AM
(这个帖子最后修改于: 2009-06-11 09:56 AM by hightman.)
帖数: #1
|
|||
|
|||
|
[2009献礼] 发布MySQL-5.1.30的scws-1.x分词插件(090611最新修订)
** MySQL-5.1.30 中文分词插件 **
@Author: hightman <MingL_Mar@msn.com> @Website: http://www.hightman.cn/bbs @download: http://www.hightman.cn/down/myft-5.1.30-090611.tgz 注意: 20090611 最新修订, 修正停止服务器时, 释放停用词列表内存指针错误的bug. [ 基本说明 ] 这是以 mysql-5.1.30 为环境开发制作的 mysql 全文检索分词插件。原则上应该适用整个 5.1.x 系列。 mysql 内置的全文检索仅支持 myisam 类型的表,默认的不支持中文分词。本插件依托 scws-1.0.1 分词系统, scws 是由我开发的免费开源的中文分词系统,纯 C 开发的函数库。安装本插件必须先安装 scws-1.x。 安装本插件后,系统会注册一个名为 scws_parser 的分词器,可以在 mysql 中直接使用它,对于小型全文检索 需求,十分方便。 MyFT 系列之前曾发过布 5.1.11 和 4.0.27 的版本,旧版是简单的分词算法并不理想,建议改为本版。 [ 安装 & 测试] 1. 首先确定您在您的服务器上以源码方式安装了 mysql 5.1.x/ , 假设您的 mysql-5.1.x 安装在 $prefix 目录 (通常为 /usr/local/mysql5) 务必是源码方式,里头一些自定义函数功能还需要对代码打补丁。 2. 接下来您必须先安装 scws-1.0.x 系统,相关的安装说明及下载文件请访问: http://www.ftphp.com/scws 假设安装在 $scws_dir 目录(建议为 /usr/local/scws) 注意要同步下载相应的词典档和规则集并放到 $scws_dir/etc 目录中去。 否则相应的字符集词典/规则集文件不存在的话则会自动采用默认的简易分词法。 3. 下载本插件代码:http://www.hightman.cn/down/myft-5.1.30-081231.tgz 4. 下载后将 tgz 文件复制到您安装的 mysql-5.1 的源代码所在目录里,然后解开: tar xvzf myft-5.1.30-081231.tgz 解开后有一个 scws 目录被放到 plugin/ 目录里 还有一个 myft_scws_udf_5.1.30.patch 补丁文件及本文件 README.myft-hightman 5. 对 mysql 源码打补丁,以支持自定义函数中获取正确的字符集 在 mysql 源码目录执行 patch -p0 < myft_scws_udf_5.1.30.patch 即可 6. 打完补丁后需要重新编译并安装一下 mysql,这不需要重新 configure ,只需在该目录 执行 make ; make install 即可 7. 开始编译 scws 插件,进入到 mysql 源码目录里的 plugin/scws 目录 先配置:./configure --prefix=$prefix --with-scws=$scws_dir 其中 $prefix 为 mysql-5.1.x 的安装目录,$scws_dir 是 scws-1.x 的安装目录 配置完毕执行 make 和 make install 如果没有错误,至此已经安装完成了。 强烈建议您修改 my.cnf 在 [mysqld] 字段里加入 ft_min_word_len = 2 因为默认是 4,太长了点。 8. 这时您需要重启一下 mysql server,运行以下命令: $prefix/share/mysql/mysql.server restart 9. 开始测试该插件,主要是全文索引的分词插件,下面以 utf8 编码进行测试。 您可以用命令行或 phpMyAdmin 之类的工具执行 SQL 命令,测试中是采用命令行。 1) 连接:mysql -u root -pxxxxx -h localhost 2) 设置字符集:SET NAMES 'utf8'; 3) 选用测试库:USE test; 4) 安装插件(只需一次):INSTALL PLUGIN scws_parser SONAME 'libftscws.so'; 5) 建表测试(注意 with parser 指令): CREATE TABLE `test_utf8` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `title` varchar(200) DEFAULT NULL, `body` mediumtext, PRIMARY KEY (`id`), FULLTEXT KEY `ft_utf8` (`title`,`body`) WITH PARSER scws_parser ) ENGINE=MyISAM DEFAULT CHARSET=utf8; INSERT INTO `test_utf8` VALUES (1, 'MySQL Tutorial', 'DBMS stands for DataBase ...'); INSERT INTO `test_utf8` VALUES (2, 'How To Use MySQL Efficiently', 'After you went through a ...'); INSERT INTO `test_utf8` VALUES (3, 'Optimising MySQL', 'In this tutorial we will show ...'); INSERT INTO `test_utf8` VALUES (4, '1001 MySQL Tricks', '1. Never run mysqld as root. 2. ...'); INSERT INTO `test_utf8` VALUES (5, 'MySQL vs. YourSQL', 'In the following database comparison ...'); INSERT INTO `test_utf8` VALUES (6, 'MySQL Security', 'When configured properly, MySQL ...'); INSERT INTO `test_utf8` VALUES (7, '中国测试', '这样可以吗'); INSERT INTO `test_utf8` VALUES (8, '疯狂测中国测试', '这样总应该可以吗'); INSERT INTO `test_utf8` VALUES (9, '中国语言测试', '这样又是行不行呢'); INSERT INTO `test_utf8` VALUES (10, '我爱china', 'china是我的祖国'); 6) 测试查询: -- 第一句因为 mysql 出现的次数太多(默认超过1半)被忽略了 SELECT * FROM test_utf8 WHERE MATCH(title, body) AGAINST ('mysql'); SELECT * FROM test_utf8 WHERE MATCH(title, body) AGAINST ('mysql' IN BOOLEAN MODE); SELECT * FROM test_utf8 WHERE MATCH(title, body) AGAINST ('中国'); SELECT * FROM test_utf8 WHERE MATCH(title, body) AGAINST ('+中国 -疯狂' IN BOOLEAN MODE); 10. 自定义函数 SCWS_SEGMENT(),将输入的字符串分词并返回以空格相连的字符串; 1) 创建函数(只需一次):CREATE FUNCTION scws_segment RETURNS STRING SONAME 'libftscws.so'; 2) 该函数接受至少一个参数,最多四个参数,依次表示: <要分词的字符串,可为表达式> <复合分词参数 1~15(整型)> <自动将散字二字分词,1或0> <忽略标点符号,1或0> 3) 在返回结果太长(特别是开启 multi的情况下)会被裁断,以 ... 结尾(不必担心!) 4) 测试: mysql> SELECT SCWS_SEGMENT('我是中国人'); +---------------------------------+ | SCWS_SEGMENT('我是中国人') | +---------------------------------+ | 我 是 中国人 | +---------------------------------+ 1 row in set (0.00 sec) mysql> SELECT SCWS_SEGMENT(title) FROM test_utf8; +-------------------------------+ | SCWS_SEGMENT(title) | +-------------------------------+ | MySQL Tutorial | | How To Use MySQL Efficiently | | Optimising MySQL | | 1001 MySQL Tricks | | MySQL vs . YourSQL | | MySQL Security | | 中国 测试 | | 疯狂 测 中国 测试 | | 中国 语言 测试 | | 我爱 china | +-------------------------------+ 10 rows in set (0.00 sec) 11. 自定义函数 SCWS_TOPWORDS(),该函数返回字符串中的核心关键词列表; 1) 创建函数(只需一次):CREATE FUNCTION scws_topwords RETURNS STRING SONAME 'libftscws.so'; 2) 接受 1~3 个参数,分别为:<字符串> <词数(整数)> <词性包含或排除(字符串)> 词性多个之间用,分隔,以~开头则表示除这些词性以外。。。和 scws 用法一样。 3) 返回结果是由符合条件的关键词及其词性和次数组成,各词之间用空格连接 <词>/<词性>/<词数> 4) 测试: mysql> SELECT SCWS_TOPWORDS('我是中国人,中国人很有志气'); +----------------------------------------------------------+ | SCWS_TOPWORDS('我是中国人,中国人很有志气') | +----------------------------------------------------------+ | 中国人/n/2 志气/n/1 | +----------------------------------------------------------+ 1 row in set (0.00 sec) mysql> SELECT SCWS_TOPWORDS(CONCAT(title, ' ', body)) FROM test_utf8; +--------------------------------------------------------------------------------------------------+ | SCWS_TOPWORDS(CONCAT(title, ' ', body)) | +--------------------------------------------------------------------------------------------------+ | DataBase/en/1 Tutorial/en/1 stands/en/1 MySQL/en/1 DBMS/en/1 for/en/1 | | Efficiently/en/1 through/en/1 After/en/1 MySQL/en/1 went/en/1 How/en/1 Use/en/1 you/en/1 To/en/1 | | Optimising/en/1 tutorial/en/1 MySQL/en/1 this/en/1 show/en/1 will/en/1 In/en/1 we/en/1 | | Tricks/en/1 mysqld/en/1 MySQL/en/1 Never/en/1 1001/en/1 root/en/1 run/en/1 as/en/1 | | comparison/en/1 following/en/1 database/en/1 YourSQL/en/1 MySQL/en/1 the/en/1 In/en/1 vs/en/1 | | MySQL/en/2 configured/en/1 Security/en/1 properly/en/1 When/en/1 | | 中国/ns/1 这样/r/1 测试/vn/1 可以/v/1 | | 中国/ns/1 应该/v/1 疯狂/an/1 这样/r/1 测试/vn/1 可以/v/1 | | 中国/ns/1 不行/a/1 语言/n/1 这样/r/1 测试/vn/1 又是/n/1 | | china/en/2 祖国/n/1 我爱/n/1 | +--------------------------------------------------------------------------------------------------+ 10 rows in set (0.00 sec) 12. 全文检索中的停用词表,类似词典和规则集一样放在 $scws_dir/etc 中 分别为:stops.[$charset.]txt rules.[$charset.]ini dict.[$charset.]xdb 如果 $charset 没有指定,则默认即为 gbk rules dict 采用 scws-1.x 的格式, stops.txt 用的是每行一个词即可,自行建立。 hightman,更多需要请访问 http://www.hightman.cn/bbs 2009 大家新年快乐! |
|||
|
2009-01-31, 08:43 AM
帖数: #2
|
|||
|
|||
|
RE: [2009献礼] 发布MySQL-5.1.30的scws-1.x分词插件
感谢大版的无私奉献。新年好@!
|
|||
|
2009-02-17, 02:14 PM
帖数: #3
|
|||
|
|||
|
RE: [2009献礼] 发布MySQL-5.1.30的scws-1.x分词插件
支持footman(hightman)
|
|||
|
2009-03-06, 11:59 AM
帖数: #4
|
|||
|
|||
|
RE: [2009献礼] 发布MySQL-5.1.30的scws-1.x分词插件
有一个问题,安装插件后,每次重启mysql都需要 Repair by sorting 全文索引表,由于数据量很大,会持续30分钟以上,导致表无法访问,请问有没有解决办法?
|
|||
|
2009-06-22, 05:35 PM
帖数: #5
|
|||
|
|||
|
RE: [2009献礼] 发布MySQL-5.1.30的scws-1.x分词插件(090611最新修订)
按照文章方法编译完整出错信息如下: 请指引
mysql-5.1.30.tar.gz scws-1.0.3.tar.bz2 myft-5.1.30-081231.tgz Red Hat Enterprise Linux AS release 3 (Taroon Update 6) gcc version 3.2.3 20030502 C -DPIC -o .libs/libftscws_la-plugin_scws.o In file included from ../../include/my_global.h:85, from plugin_scws.c:20: ../../include/my_config.h:1065:1: warning: "PACKAGE" redefined plugin_scws.c:1:1: warning: this is the location of the previous definition ../../include/my_config.h:1071:1: warning: "PACKAGE_NAME" redefined plugin_scws.c:1:1: warning: this is the location of the previous definition ../../include/my_config.h:1074:1: warning: "PACKAGE_STRING" redefined plugin_scws.c:1:1: warning: this is the location of the previous definition ../../include/my_config.h:1077:1: warning: "PACKAGE_TARNAME" redefined plugin_scws.c:1:1: warning: this is the location of the previous definition ../../include/my_config.h:1080:1: warning: "PACKAGE_VERSION" redefined plugin_scws.c:1:1: warning: this is the location of the previous definition ../../include/my_config.h:1202:1: warning: "VERSION" redefined plugin_scws.c:1:1: warning: this is the location of the previous definition In file included from ../../storage/myisam/fulltext.h:20, from ../../storage/myisam/ftdefs.h:20, from plugin_scws.c:25: ../../storage/myisam/myisamdef.h:216: syntax error before "pthread_rwlock_t" ../../storage/myisam/myisamdef.h:216: warning: no semicolon at end of struct or union ../../storage/myisam/myisamdef.h:221: syntax error before "mmap_lock" ../../storage/myisam/myisamdef.h:221: warning: data definition has no type or storage class ../../storage/myisam/myisamdef.h:222: warning: data definition has no type or storage class ../../storage/myisam/myisamdef.h:235: syntax error before "MYISAM_SHARE" ../../storage/myisam/myisamdef.h:235: warning: no semicolon at end of struct or union ../../storage/myisam/myisamdef.h:304: syntax error before '}' token ../../storage/myisam/myisamdef.h:570: syntax error before '*' token ../../storage/myisam/myisamdef.h:759: syntax error before "MYISAM_SHARE" ../../storage/myisam/myisamdef.h:762: syntax error before '*' token ../../storage/myisam/myisamdef.h:763: syntax error before '*' token make: *** [libftscws_la-plugin_scws.lo] Error 1 |
|||
|
|
| 可能相关的主题... | |||||
| 主题: | 作者 | 回复数: | 人气: | 最近发表 | |
| It crashes for MySQL 5.1.35, and solution | 新用户 | 3 | 6,165 |
2009-06-12 08:42 AM 最近发表: hightman |
|
| MySQL-5.1.11~12 全文检索分词插件支持mysql5.0.41吗? | ykjsw | 1 | 11,283 |
2009-01-01 12:41 PM 最近发表: hightman |
|
| (安装手记) MySQL-5.1.11~12 全文检索分词插件 | derekchen | 1 | 11,292 |
2008-06-05 10:26 PM 最近发表: derekchen |
|
| MySQL-5.1.11~12 全文检索分词插件 | hightman | 21 | 69,377 |
2008-06-04 11:13 PM 最近发表: derekchen |
|
| MySQL-4.0.x(fulltext) 源码修订 patch 文件包 | hightman | 1 | 15,112 |
2007-06-13 01:28 PM 最近发表: Mistruster |
|
| MySQL Fulltext 总结与目录 | hightman | 0 | 14,729 |
2007-06-06 02:26 AM 最近发表: hightman |
|
| MySQL-4.0.x FT 使用与演示 | hightman | 0 | 12,609 |
2007-06-06 01:57 AM 最近发表: hightman |
|
| MySQL-4.0.27-hi4 完整安装包发布及安装说明(推荐) | hightman | 0 | 13,364 |
2007-06-06 01:28 AM 最近发表: hightman |
|
| MySQL ft 补丁的授权声明 | hightman | 0 | 12,541 |
2007-06-06 01:09 AM 最近发表: hightman |
|

搜索
会员列表
日历
帮助


