sphinx的安装

sphinx

本文介绍centos下的linux安装,亲测成功。

安装关联软件包

yum install gcc make gcc-c++ libtool autoconf automake imake mysql-devel libxml2-devel

下载 sphinx-0.9.9.tar.gz压缩包,并解压

sphinx-0.9.9.zip

cd sphinx-0.9.9
./configure --prefix=/usr/local/sphinx
make && make install

下载coreseek-3.2.14.tar.gz压缩包,并解压

coreseek-3.2.14.zip

cd mmseg-3.2.14/
./configure --prefix=/usr/local/mmseg
make && make install


期间如果出现如下错误

config.status: error: cannot find input file:
src/Makefile.in

执行:

aclocal
libtoolize --force
automake --add-missing
autoconf
autoheader
make clean
然后在执行
./configure --prefix=/usr/local/mmseg
则可以安装成功

然后安装csft安装包

cd cstf-3.2.14/
./configure --prefix=/usr/local/coreseek  --with-mmseg=/usr/local/mmseg --with-mmseg-includes=/usr/local/mmseg/include/mmseg --with-mmseg-libs=/usr/local/mmseg/lib/
make && make install


如果使用中文拆词,要保证其编辑完全一致

[client]
#password    = your_password
port        = 3306
socket        = /var/lib/mysql/mysql.sock
default-character-set=utf8 
 
 
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
 
character_set_server = utf8
character_set_client = utf8
init_connect='SET NAMES utf8'

测试

cd /usr/local/coreseek/bin
./indexer --all
./search '生活'

至此,中文分词安装完毕


下面开始打php模块


下载sphinx-1.1.0.tar.gz

sphinx-1.1.0.zip

解压并进入相当的文件夹

tar -xvf sphinx-1.1.0.tar.gz
cd sphinx-1.1.0
找一下phpize的路径
which phpize
执行
/usr/bin/phpize
 
找一下php-config的路径
which php-config
 
然后编译./configure --with-php-config=/usr/bin/php-config

提示出错

checking for libsphinxclient headers in default path..not found

configure:error:Cannot find libsphinxclient headers


解决

cd libsphinxclietg/
./configure
make && make install

安装完libsphinxclient,继续安装sphinx扩展

cd sphinx-1.1.0
./configure --with-php-config=/usr/bin/php-config --enable-sphinx
make
make install

由于php版本bug期间可能出现错误,解决方法


下面是其回复内容:

If you change line 105 of sphinx.c from:    

retval = std_hnd->read_property(object, member, type TSRMLS_CC);    

to     

retval = std_hnd->read_property(object, member, type TSRMLS_CC, NULL);    

it compiles and seems to work.    

编辑安装方式简单描述:



然后得到一个类似于

Installing shared extensions:     /usr/lib64/php/modules/

这样的结果

cd  /usr/lib64/php/modules/

在php.ini加入 :extension=sphinx.so

重启apache  echo phpinfo();看到sphinx模块正常加载了进来


测试一下

<?php
$page=empty($_GET['page']) ? 1 : (int)$_GET['page'];//当前第几页
$prepage=5;
$keyword="漂亮";
$sphinx= new SphinxClient();
$sphinx->SetServer("127.0.0.1",9312);
$sphinx->SetMatchMode(SPH_MATCH_ANY);
$sphinx->SetLimits(($page-1)*$prepage,$prepage);//传递当前页面所需的数据条数的参数
$result=$sphinx->query("$keyword","*");
if($result['total']==0){
echo '没有结果,请重新搜索';
exit;
}
echo"<pre>";
print_r($result);
echo"</pre>";


2014-09-29 10:44:36

php
php

这是介绍的地方

本文相关标签

推荐应用

友情链接


皖ICP备14007051号-2 关于穆子龙