sphinx安装

来源:互联网 发布:10型军用巧克力淘宝 编辑:程序博客网 时间:2024/05/18 03:24

sphinx

结构图:

安装sphinx软件

如何搜索包含北京的记录?
Select * from news where content like ‘%北京%’
 
这样有什么弊端?
1.不走索引,特别慢
如果是100万条记录?如果是1000万条记录?
2.搜索不准确,只能搜标题
 
Sphinx原理,如果搜索北京
Sphinx临时文件,特别快
id 关键词 权重
1 北京 3
2 北京 2
3 中国 2
 
Sphinx是什么
Sphinx由俄罗斯人Andrew Aksyonoff 开发的高性能全文搜索软件包,在GPL与商业协议双许可协议下发行。
全文检索是指以文档的全部文本信息作为检索对象的一种信息检索技术。检索的对象有可能是文章的标题,也有可能是文章的作者,也有可能是文章摘要或内容。
Sphinx的特性
高速索引 (在新款CPU上,近10 MB/秒);高速搜索 (2-4G的文本量中平均查询速度不到0.1秒);高可用性 (单CPU上最大可支持 100 GB的文本,100M文档); 提供良好的相关性排名;支持分布式搜索;  提供文档摘要生成;  提供从MySQL内部的插件式存储引擎上搜 索 ;  支持布尔,短语, 和近义词查询;   支持每个文档多个全文检索域(默认最大32个); 支持每个文档多属性;   支持断词; 支持单字节 编码与UTF-8编码;
 
源码安装,步骤
1.解压
2.安装 
3.修改配置
 
 
 
 
可能会需要依赖包,依赖包yum就可以
yum -y install make gcc gcc-c++ libtool autoconf automake imake mysql-devel libxml2-devel expat-devel
将包sphinx-2.1.9-release.tar.gz上传到指定目录/usr/local/src
cd /usr/local/src
tar -zxvf sphinx-2.1.9-release.tar.gz
cd sphinx-2.1.9-release
./configure --prefix=/usr/local/sphinx --with-mysql=/usr/local/mysql
make && make install
安装完毕!!!!!!!!!!!!!!!!

Sphinx的使用
也就是说,sphinx需要一张表,准确的说,需要mysql的一张表,作为数据源。
Etc下,有一张。导入到mysql中。
/usr/local/mysql/bin/mysql -uroot -p</usr/local/sphinx/etc/example.sql
cd /usr/local/sphinx/etc
cp sphinx.conf.dist sphinx.conf
vi sphinx.conf
35行  
sql_sock = /tmp/mysql.sock
79行 
sql_query_pre = SET NAMES utf8
cd /usr/local/sphinx/bin   ./indexer --all(如果报错)
248行
#Sql_query_info=”select * from 表名 where id=$id”
遇到问题:
./indexer: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
解决方案:
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
还可能遇到

配置一下配置文件、把rt这个配置项修改一下.
./search this 查看内容
安装coreseek
一、Coreseek 分两部分
(1)Csft=sphinx
(2)Mmseg(作用:分词)
三、解包coreseek
tar -zxvf coreseek-4.1-beta.tar.gz
有三个文件夹和一个文件   csft-4.1  mmseg-3.2.14 testpack README.txt
 
首先装mmseg
cd mmseg-3.2.14
./bootstrap #输出的warning信息可以忽略,如果出现error则需要解决
./configure --prefix=/usr/local/mmseg3
make 
make install
验证mmseg是否安装成功
cd /usr/local/mmseg3/bin下
建立一个a.txt文件
 vi a.txt
内容:我来自河北省武安市
运行:
./mmseg -d /usr/local/mmseg3/etc a.txt
 
CSFT配置
cd /usr/local/src/coreseek-4.1-beta/csft-4.1
./buildconf.sh  #输出的warning信息可以忽略,如果出现error则需要解决
./configure --prefix=/usr/local/coreseek --without-unixodbc --with-mmseg-includes=/usr/local/mmseg3/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg3/lib --with-mysql
make && make install
修改coreseek配置文件
cd /usr/local/coreseek/etc
将复制一份sphinx.conf.dist 为 csft.conf
cp sphinx.conf.dist csft.conf
vi csft.conf
Sock前面的注释去掉
sql_sock = /tmp/mysql.sock
开启 sql_query_pre = SET NAMES utf8
效果
./indexer --all
./search 词
 
安装sphinx服务
yum -y install php-devel
cd /usr/local/src
tar -zxvf sphinx-1.3.1.tgz
cd /usr/local/src/sphinx-1.3.1
/usr/local/php/bin/phpize
 
cd /usr/local/src/coreseek-4.1-beta/testpack/api/libsphinxclient/
./configure
make && make install
 
运行完sphinx-1.3.1.tgz下才有configure文件
cd /usr/local/src/sphinx-1.3.1
./configure --with-php-config=/usr/local/php/bin/php-config --with-sphinx
make 
make install
 
成功的标志:在/usr/local/php/lib/php/extensions/no-......./sphinx.so
文件或出现20121212
配置php
php.ini文件中开启sphinx的扩展
[sphinx]
extension=sphinx.so
0 0
原创粉丝点击