Home > php教程 > php手册 > linux 配置 sphinx 全文搜索引擎 - stubbornRookie

linux 配置 sphinx 全文搜索引擎 - stubbornRookie

WBOY
Release: 2016-05-20 11:40:59
Original
2035 people have browsed it

因为公司网站需要,最近在弄sphinx搜索引擎,也是遇到各种问题,最终终于解决了。

服务器系统:centos7 (64位)

详情看安装官网的安装教程进行 coreseek 3.2.14

这里只提一些注意的地方

1:在安装前先安装基础开发库及数据库依赖

<span style="color: #0000ff;">yum</span> <span style="color: #0000ff;">install</span> <span style="color: #0000ff;">make</span> <span style="color: #0000ff;">gcc</span> g++ <span style="color: #0000ff;">gcc</span>-c++ libtool autoconf automake imake mysql-devel libxml2-devel expat-devel:
Copy after login

 2:下载

 <span style="color: #0000ff;">wget</span> http:<span style="color: #008000;">//</span><span style="color: #008000;">www.coreseek.cn/uploads/csft/3.2/coreseek-3.2.14.tar.gz</span>
Copy after login

3:安装mmseg,这里应该是没有什么问题的。

 

$ cd mmseg-<span style="color: #800080;">3.2</span>.<span style="color: #800080;">14</span><span style="color: #000000;">
$ .</span>/<span style="color: #000000;">bootstrap    #输出的warning信息可以忽略,如果出现error则需要解决
$ .</span>/configure --prefix=/usr/local/<span style="color: #000000;">mmseg3
$ </span><span style="color: #0000ff;">make</span> && <span style="color: #0000ff;">make</span> <span style="color: #0000ff;">install</span><span style="color: #000000;">
$ cd ..</span>
Copy after login

4:安装csft

进入到csft目录,先修改src/sphixexpr.cpp这个文件,里面3个地方编译会出错的

<span style="color: #ff0000;">将ExprEval改为this->ExprEval</span>
Copy after login

 再进行下一步安装,这样就可以了。

<span style="color: #0000ff;">sh</span> buildconf.<span style="color: #0000ff;">sh</span><span style="color: #000000;"> 

.</span>/configure --prefix=/usr/local/coreseek  --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg3/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg3/lib/ --with-<span style="color: #000000;">mysql

</span><span style="color: #0000ff;">make</span> && <span style="color: #0000ff;">make</span> <span style="color: #0000ff;">install</span>
Copy after login

5:然后就是配置文件,到安装目录下复制一份

cd /usr/local/coreseek/<span style="color: #000000;">etc
</span><span style="color: #0000ff;">cp</span><span style="color: #000000;"> sphinx.conf.dist sphinx.conf
vim sphinx.conf</span>
Copy after login

主要修改数据库参数 ,其他一些警告问题,注释掉配置文件里面相应内容即可,暂时未发现问题

type                    =<span style="color: #000000;"> mysql

sql_host                </span>=<span style="color: #000000;"> localhost
sql_user                </span>=<span style="color: #000000;"> root
sql_pass                </span>=<span style="color: #000000;"> 
sql_db                    </span>=<span style="color: #000000;"> test
sql_port                </span>= <span style="color: #800080;">3306</span><span style="color: #000000;">
sql_query_pre            </span>= SET NAMES utf8
Copy after login

然后保存,生成索引

cd /usr/local/coreseek/<span style="color: #000000;">bin
.</span>/indexer -c /usr/local/coreseek/etc/sphinx.conf --<span style="color: #000000;">all
.</span>/searchd -c  /usr/local/coreseek/etc/sphinx.conf
Copy after login

导入测试数据,调用测试文件

<span style="color: #0000ff;">require</span> ( "sphinxapi.php"<span style="color: #000000;"> );

</span><span style="color: #800080;">$cl</span> = <span style="color: #0000ff;">new</span><span style="color: #000000;"> SphinxClient ();
</span><span style="color: #800080;">$cl</span>->SetServer ( '127.0.0.1', 9312<span style="color: #000000;">);
</span><span style="color: #800080;">$cl</span>->SetConnectTimeout ( 3<span style="color: #000000;"> );
</span><span style="color: #800080;">$cl</span>->SetArrayResult ( <span style="color: #0000ff;">true</span><span style="color: #000000;"> );
</span><span style="color: #800080;">$cl</span>-><span style="color: #000000;">SetMatchMode ( SPH_MATCH_ANY);
</span><span style="color: #800080;">$res</span> = <span style="color: #800080;">$cl</span>->Query ( '网络搜索', "*"<span style="color: #000000;"> );
</span><span style="color: #008080;">print_r</span>(<span style="color: #800080;">$cl</span><span style="color: #000000;">);
</span><span style="color: #008080;">print_r</span>(<span style="color: #800080;">$res</span>);
Copy after login

应该就没有问题,确保系统中文zh_CN.UTF-8,才能保证中文显示

下面是自己公司的情况,可能也有人会有这样的情况。

搜索引擎在一个服务器,而网站及数据库在另一个服务器,这样的情况下需要考虑的

1:coreseek 安装中如果提示libmysqlclient.so.18共享库找不到

在mysql服务器复制一份libmysqlclient.so.18,路径为/usr/lib64/mysql/libmysqlclient.so.18

2:搜索引擎所在的服务器防火墙端口是否开放

centos7先安装

<span style="color: #0000ff;">yum</span> <span style="color: #0000ff;">install</span> firewalld-config
Copy after login

 然后开启端口

firewall-cmd [--zone=<zone>] --add-port=<port>[-<port>]/<protocol> [--timeout=<seconds>]<br>firewall-cmd --permanent --add-port=10-9900/tc</seconds></protocol></port></port></zone>
Copy after login

查询

firewall-cmd --permanent --query-port=<span style="color: #800080;">80</span>/tcp
Copy after login

3:网站php调用api版本必须与coreseek 版本一致。

测试过程可以在php中直接输出

<span style="color: #008080;">var_dump</span>(<span style="color: #800080;">$cl</span>);<span style="color: #008000;">//</span><span style="color: #008000;">$cl为sphinxClient对象</span>
Copy after login

查看错误信息。

 以上问题解决了应该就可以正常使用了。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template