在上一片文章php之sphinx/coreseek全文搜索,分词(一)中我们介绍了使用sphinx进行全文搜索,然后我们许晴郑爽了解到sphinx对中文分词不是太智能,所以接下来我将带着大家一起来安装使用sphinx(coreseek)进行全文搜索中文分词
以下内容请在新环境进行配置测试
二丶coreseek简介
coreseek是一款基于sphinx开源的搜索引擎,专门为用户提供免费的中文全文检索系统,coreseek被称为带有中文分词的sphinx,与sphinx不同的是coreseek增加了一个带有中文分司的词库,目前coreseek的官网已经不能访问,且该开源项目已不再维护,但这并不妨碍我们使用coreseek进行全文搜索,中文分词
三丶安装1.系统环境
centos7.2 +lnmp环境
2.下载coreseek并上传到服务器
下载链接:pan.baidu/s/1g74zH9tCE3lQH9UyQUnyyw 密码:o9gj
3.安装mmseg 分词
tar -zxvf coreseek-4.1-beta.tar.gz cd coreseek-4.1-beta/mmseg-3.2.14/ ./bootstrap echo $? ./configure --prefix=/usr/local/mmseg make make install4.安装coreseek
cd ../csft-4.1/ sh buildconf.sh ##警告可以忽略 ./configure --prefix=/usr/local/coreseek --without-python --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg/include/mmseg/ --with-mmseg-libs=/usr/loc遮瑕al/mmseg/lib/ --with-mysql ma整理术ke ##警告可忽略 make install###可能会报的错1. sh b穿衣镜尺寸uildconf.sh 报错 automake: warnings are treated as errors#解决办法 将configure.ac文件的AM_INIT_AUTOMAKE([-Wall -Werror foreign]) 修改为AM_INIT_AUTOMAKE([-Wall foreign])subdir-objects2.make报错1make[2]: *** [sphinxexpr.o] Error 1make[2]: Leaving directory `/root/coreseek-4.1-beta/csft-4.1/src'make[1]: *** [all] Error 2make[1]: Leaving directory `/root/coreseek-4.1-beta/csft-4.1/src'make: *** [all-recursive] Error 1##解决办法将src目录下sphinxexpr.cpp 文件的所有的T val = ExprEval ( this-m_pArg, tMatch );修改为T val = this->ExprEval ( this-m_pArg, tMatch );然后执行 make clean 在执行make3.make 报错2collect2: error: ld returned 1 exit statu中秋活动策划方案smake[2]: *** [indexer] Error 1make[2]: Leaving diip地址rectory `/root/coreseek-4.1-beta/csft-4.1/src'make[1]: *** [all] Error 2make[1]: Leaving directory `/root/coreseek-4.1-beta/csft-4.1/src'##解决办法编辑configure 文件 修改 #define USE_LIBICONV 1 的 1 修改为0四丶配置coreseek 以及demo测试
1 coreseek配置
cd /usr/local/coreseek/etc vim sphinx.conf.dist ##配置基本与sphinx相同 不同的是coreseek需要在索引attr_node 里添加 charset_type = zh_cn.utf-8 charset_dictpath = /usr/local/mmseg/etc/ 添加这两行,意思是把中文分词加入到配置文件中修改保存完执行 egrep -v '#|^$' sphinx.conf.dist >sphinx.conf## sphinx.conf 的内容如下:source node{ type = mysql sql_host = localhost sql_user = root sql_pass = 123456 sql_db = test sql_sock = /tmp/mysql.sock sql_query_pre = SET NAMES utf8 sql_query_pre = SET SESSION query_cache_type=OFF sql_query = 韩剧李算SELECT id,title,content,created FROM node sql_field_string = title sql_field_string = content sql_field_string = created sql_ranged_throttle = 0}index attr_node{ source 第九禁区 = node path = /usr/local/coreseek/var/data/attr_node docinfo = extern mlock = 0 morphology = none min_word_len = 1 charset_type = zh_cn.utf-8 charset_dictpath = /usr/local/mmseg/etc/ html_strip = 0}indexer{ mem_limit = 128M}searchd{ listen = 9312 listen = 9306:mysql41 log = /usr/local/coreseek/var/log/searchd.log query_log = /usr/local/coreseek/var/log/query.log 美女动作电影 read_timeout = 5 client_timeout = 300 max_children = 30 pid_file = /usr/local/coreseek/var/log/searchd.pid m骑在羊背上的国家ax_matche彩色烟雾弹s = 1000 seamless_rotate = 1 preopen_indexes = 1 unlink_old = 1 mva_updates_pool = 1M max_packet_si免费博客网站ze = 8M max_filters = 256 max_filter_values = 4096 max_batch_queries = 32}2.创建启动索引
cd ../bin ./indexer --config /usr/local/coreseek/etc/sphinx.conf -all ./searchd --config /usr/local/coreseek/etc/sphinx.conf3.测试demo编写
cd /home/wwwroot/default/ mkdir coreseek cd cd coreseek-4.1-bata/csft-4.1/api/ cp sphinxapi.php /home/wwwroot/default/coreseek/ c唐聚五d /home/wwwroot/default/coreseek/##创建并编伊朗美国辑 index.htmlvim in商鞅徙木立信论dex.html##写入以下代码<!DOCTYPE html><html><head><title>欢迎使用sphinx!</title><meta charset="utf-8"></head><body><h1>欢迎使用sphinx搜索</h1><form method="post" action="sphinxtest.php" ><input type="text" name="centent"/><input type="submit" vlaue="搜索"></form></body></html>##然后保存退出然后我们 新建并编辑一个 sphinxtest.phpvim sphinxtest.php ##写入以下代码<?phprequire('sphinxapi.php');$cl = new SphinxClient ();$q = $_POST['centent'];$host = "localhost";$port = 9312;$index = "attr_node";$cl->SetServer ( $host, $port );$cl->SetConnectT江湖菜imeout ( 1 );$cl->SetArrayRe徐辉祖sult ( true );//匹配查询词中的任意一个$cl->SetMatchMode(SPH_MATCH_ANY);$res = $cl->Query ( $q, 打沙袋$index );echo '<pre>';var_dump($res);echo '</pre>';?>##保存并退出4.测试
我们在搜索框输入 “阳光明媚”
显示如下:
array(10) { ["error"]=> string(0) "" ["warning"]=> string(0) "" ["status"]=> int(0) ["fields"]=> array(3) { [0]=> string(5) "title" [1]=> string(7) "content" [2]=> string(7) "created" } ["attrs"]=> array(3) { ["title"]=> int(7) ["content"]=> int(7) ["created"]=> int(7) } ["matches"]=> array(3) { [0]=> array(3) { ["id"]=> int(6) ["weight"]=> string(1) "8" [韩国牛肉4;attrs"]=> array(3) { ["title"]=> string(33) "笔墨流芬芳,醉爱文字情" ["content"]=> string(366) "文字,是一米阳光,温暖着我的心。阳光明媚,我在阳光里享受着它的融融暖意。文字,发着光,发着热,让我的灵魂不再四处漂游。文字,好暖,让我结冰的心湖慢慢融化。阳光,让早已心如死灰的心感受到从未有过的温暖。只要抓住那一米阳光,就等于抓住了一颗救命稻草" ["created"]=> string(19) "2018-07-17 11:12:00" } } [1]=> array(3) { ["id"]=> int(10) ["weight"]=> string(1) "8" ["attrs"]=> array(3) { ["title"]=> string(24) "走在迷途的拾荒人" ["content"]=> string(423) "时光就像一个美少女,在低眉浅笑中,就将有些人一些事隔到了光阴的对面。其实光阴从不曾厚过谁也不曾薄过谁,生活就是一种积累,你若储存的温暖多,你的生活就会阳光明媚,你若储存太多寒凉,你的生活就会阴云密布。放下烦恼与忧愁,带着最美的微笑出发,脚下路在,前方希望在,回眸处爱与温暖一直都在。" ["created"]=> string(19) "2018-07-17 11:12:00" } } [2]=> array(3) { ["id"]=> int(9) ["weight"]=> string(1) "1" ["attrs"]=> array(3) { ["title"]=> string(15) "阳光的滋味" ["content"]=> string(336) "明眸善睐,云袖轻舒,花影婆娑,夜鸟伏声。望月,终团圆。融化一季相思苦楚,泪凝妙目。开襟解怀,邀月畅饮。一季愁情尽遣。蘸墨狂书,满腹恩爱无度。羞愧了月里仙子,忧郁了河汉星辰。明月缱惓,夜色飘香。尝遍了相思苦涩,领略这相聚欢欣。" ["created"]=> string(19) "2018-07-17 11:12:00" } } } ["total"]=> string(1) "3" ["total_found"]=> string(1) "3" ["time"]=> string(5) "0.003" 怎样去头屑 ["words"]=> array(2) { ["阳光"]=> array(2) { ["docs"]=> string(1) "3" ["hits"]=> string(1) "7" } ["明媚"]=> array(2) { ["docs"]=> string(1) "2" ["hits"]=> string(1) "2" } }在words里我们可以发现 阳光明媚被拆分成了两个词组 而不是像sphinx 切割成一个一个的字符 相比sphinx 又智能了许多!
到此sphinx以及coreseek的安装 配置以及基本使用就介绍到这里了 sphinx和coreseek 还有更多其他功能等例如分页 排序 指定查询等 功能十分强大
小编也是一个编程新手,不到之处还望大家多多包含 ,如在安装中遇到什么问题请在下方留言,小编看到一定会帮大家解决问题的。
本文发布于:2023-06-04 07:59:01,感谢您对本站的认可!
本文链接:http://www.ranqi119.com/ge/85/214702.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |