安装好coreseek之后接下来的操作非不复杂,唯一一个麻烦一点的就是配置文件,我这里使用的是mysql数据源。表结构如下:本文地址:http://www.04007.cn/article/266.html,未经许可,不得转载.
CREATE TABLE `webinfo` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `url` varchar(255) DEFAULT NULL, `title` varchar(255) DEFAULT NULL, `keywords` varchar(255) DEFAULT NULL, `description` varchar(255) DEFAULT NULL, `status` tinyint(4) DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `url` (`url`) ) ENGINE=MyISAM AUTO_INCREMENT=2011121 DEFAULT CHARSET=utf8里面是抓取的200万条网站数据(来源于这里:http://www.04007.cn/article/200.html 通过网站之间的链接抓取全网域名的php程序)。coreseek里的csft_mysql.conf配置文件内容如下:
#源定义 source webinfo_source { type = mysql sql_host = localhost sql_user = test** sql_pass = ******** sql_db = webdata sql_port = 3306 sql_query_pre = SET NAMES utf8 sql_query = SELECT id,url,title,keywords,description,status FROM webinfo #要索引的数据字段 #sql_attr_uint = group_id #从SQL读取到的值必须为整数 #sql_attr_timestamp = date_added #从SQL读取到的值必须为整数,作为时间属性 sql_query_info_pre = SET NAMES utf8 #命令行查询时,设置正确的字符集 sql_query_info = SELECT * FROM webinfo WHERE id=$id #从数据库读取原始数据信息 } #index定义 index webinfo_index { source = webinfo_source path = /opt/modules/coreseek4.1/var/data/webinfo docinfo = extern mlock = 0 morphology = none min_word_len = 1 #设置最小分词单位,1表示1个中文汉字 html_strip = 0 #中文分词配置 charset_dictpath = /opt/modules/mmseg3.2/etc 中文分词库的位置,取决于你安装的mmseg位置 charset_type = zh_cn.utf-8 } #全局index定义 indexer { mem_limit = 128M } #searchd服务定义 searchd { listen = 9312 read_timeout = 5 max_children = 30 max_matches = 1000 seamless_rotate = 0 preopen_indexes = 0 unlink_old = 1 pid_file = /opt/modules/coreseek4.1/var/searchd_mysql.pid log = /opt/modules/coreseek4.1/var/log/searchd_mysql.log query_log= /opt/modules/coreseek4.1/var/log/query_mysql.log #binlog_path = #关闭binlog日志 }配置文件填写好之后进行索引:执行如下:
[root@kermit etc]# /opt/modules/coreseek4.1/bin/indexer -c /opt/modules/coreseek4.1/etc/csft_mysql.conf webinfo_index Coreseek Fulltext 4.1 [ Sphinx 2.0.2-dev (r2922)] Copyright (c) 2007-2011, Beijing Choice Software Technologies Inc (http://www.coreseek.com) using config file '/opt/modules/coreseek4.1/etc/csft_mysql.conf'... indexing index 'webinfo_index'... WARNING: Attribute count is 0: switching to none docinfo collected 2009613 docs, 277.6 MB sorted 51.6 Mhits, 100.0% done total 2009613 docs, 277618944 bytes total 99.075 sec, 2802097 bytes/sec, 20283.67 docs/sec total 11 reads, 5.549 sec, 20597.2 kb/call avg, 504.5 msec/call avg total 482 writes, 1.045 sec, 948.3 kb/call avg, 2.1 msec/call avg [root@kermit etc]#我的数据表相对简单,字段也不多,表中共有200万条记录,用时100秒,速度还好,毕竟这是全量索引。coreseek自带一个测试端,bin目录下的search脚本。使用测试端测试搜索结果如下:
[root@kermit bin]# ./search -c /opt/modules/coreseek4.1/etc/csft_mysql.conf '中国铁路客户服务中心火车票' Coreseek Fulltext 4.1 [ Sphinx 2.0.2-dev (r2922)] Copyright (c) 2007-2011, Beijing Choice Software Technologies Inc (http://www.coreseek.com) using config file '/opt/modules/coreseek4.1/etc/csft_mysql.conf'... index 'webinfo_index': query '中国铁路客户服务中心火车票 ': returned 2 matches of 2 total in 0.002 sec displaying matches: 1. document=145981, weight=14655 id=145981 url=http://www.web2mi.com title=买火车票_12306铁路客户服务中心_中国铁路客户服务中心_12306铁路服务中心-网上订票官网、手机抢票客户端、票务信息|高铁、动车、余票、站点查询 绿行火车票 keywords=12306火车票网上订票官网,买火车票,12306网上订火车票官网,12306手机客户端,12306铁路客户服务中心,抢票软件,12360火车票预订 description=买火车票是一款通过直接连接中国铁路客户服务中心网站(12306.cn)来购买火车票的移动设备客户端工具软件。 status=1 2. document=336341, weight=14655 id=336341 url=http://web2mi.com title=买火车票_12306铁路客户服务中心_中国铁路客户服务中心_12306铁路服务中心-网上订票官网、手机抢票客户端、票务信息|高铁、动车、余票、站点查询 绿行火车票 keywords=12306火车票网上订票官网,买火车票,12306网上订火车票官网,12306手机客户端,12306铁路客户服务中心,抢票软件,12360火车票预订 description=买火车票是一款通过直接连接中国铁路客户服务中心网站(12306.cn)来购买火车票的移动设备客户端工具软件。 status=1 words: 1. '中国': 39512 documents, 80824 hits 2. '铁路': 1080 documents, 2539 hits 3. '客户': 26255 documents, 37197 hits 4. '服务': 81796 documents, 140654 hits 5. '中心': 18575 documents, 36454 hits 6. '火车票': 108 documents, 389 hits搜索结果中显示了共有多少条记录,本次搜索花费了多少时间。从上面可以看到共计用了0.002秒,而200万条记录,如果通过mysql的模糊查询至少得几秒钟。最后还显示了搜索时进行了中文分词,这个也比较有用,如果我们需要做高亮的话就可以使用这些词去高亮,不过更好的方法是使用客户端的现成的方法直接高亮。search测试程序还有其它的一些参数,我也没有全部使用。如下:
[root@kermit bin]# ./search Coreseek Fulltext 4.1 [ Sphinx 2.0.2-dev (r2922)] Copyright (c) 2007-2011, Beijing Choice Software Technologies Inc (http://www.coreseek.com) Usage: search [OPTIONS] <word1 [word2 [word3 [...]]]> Options are: -c, --config <file> use given config file instead of defaults -i, --index <index> search given index only (default: all indexes) -a, --any match any query word (default: match all words) -b, --boolean match in boolean mode -p, --phrase match exact phrase -e, --extended match in extended mode -f, --filter <attr> <v> only match if attribute attr value is v -s, --sortby <CLAUSE> sort matches by 'CLAUSE' in sort_extended mode -S, --sortexpr <EXPR> sort matches by 'EXPR' DESC in sort_expr mode -o, --offset <offset> print matches starting from this offset (default: 0) -l, --limit <count> print this many matches (default: 20) -q, --noinfo don't print document info from SQL database -g, --group <attr> group by attribute named attr -gs,--groupsort <expr> sort groups by <expr> --sort=date sort by date, descending --rsort=date sort by date, ascending --sort=ts sort by time segments --stdin read query from stdin
本文地址:http://www.04007.cn/article/266.html 未经许可,不得转载. 手机访问本页请扫描右下方二维码.
![]() |
![]() |
手机扫码直接打开本页面 |