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

linux 配置 sphinx 全文搜索引擎,

WBOY
Release: 2016-06-13 08:41:36
Original
1094 people have browsed it

linux 配置 sphinx 全文搜索引擎,

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

服务器系统:centos7 (64位)

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

这里只提一些注意的地方

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

<span>yum</span> <span>install</span> <span>make</span> <span>gcc</span> g++ <span>gcc</span>-c++ libtool autoconf automake imake mysql-devel libxml2-devel expat-devel:
Copy after login

2:下载

 <span>wget</span> http:<span>//</span><span>www.coreseek.cn/uploads/csft/3.2/coreseek-3.2.14.tar.gz</span>
Copy after login

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

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

4:安装csft

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

<span>将ExprEval改为this->ExprEval</span>
Copy after login

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

<span>sh</span> buildconf.<span>sh</span><span> 

.</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>mysql

</span><span>make</span> && <span>make</span> <span>install</span>
Copy after login

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

cd /usr/local/coreseek/<span>etc
</span><span>cp</span><span> sphinx.conf.dist sphinx.conf
vim sphinx.conf</span>
Copy after login

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

type                    =<span> mysql

sql_host                </span>=<span> localhost
sql_user                </span>=<span> root
sql_pass                </span>=<span> 
sql_db                    </span>=<span> test
sql_port                </span>= <span>3306</span><span>
sql_query_pre            </span>= SET NAMES utf8
Copy after login

然后保存,生成索引

cd /usr/local/coreseek/<span>bin
.</span>/indexer -c /usr/local/coreseek/etc/sphinx.conf --<span>all
.</span>/searchd -c  /usr/local/coreseek/etc/sphinx.conf
Copy after login

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

<span>require</span> ( "sphinxapi.php"<span> );

</span><span>$cl</span> = <span>new</span><span> SphinxClient ();
</span><span>$cl</span>->SetServer ( '127.0.0.1', 9312<span>);
</span><span>$cl</span>->SetConnectTimeout ( 3<span> );
</span><span>$cl</span>->SetArrayResult ( <span>true</span><span> );
</span><span>$cl</span>-><span>SetMatchMode ( SPH_MATCH_ANY);
</span><span>$res</span> = <span>$cl</span>->Query ( '网络搜索', "*"<span> );
</span><span>print_r</span>(<span>$cl</span><span>);
</span><span>print_r</span>(<span>$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>yum</span> <span>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
Copy after login

查询

firewall-cmd --permanent --query-port=<span>80</span>/tcp
Copy after login

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

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

<span>var_dump</span>(<span>$cl</span>);<span>//</span><span>$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