Linux下Sphinx的安装和使用

Sphinx是一个基于SQL的全文检索引擎,可以结合MySQL,PostgreSQL做全文搜索,它可以提供比数据库本身更专业的搜索功能,使得应用程序更容易实现专业化的全文检索。Sphinx特别为一些脚本语言设计搜索API接口,如PHP,Python,Perl,Ruby等,同时为MySQL也设计了一个存储引擎插件。

Sphinx 单一索引最大可包含1亿条记录,在1千万条记录情况下的查询速度为0.x秒(毫秒级)。Sphinx创建索引的速度为:创建100万条记录的索引只需 3~4分钟,创建1000万条记录的索引可以在50分钟内完成,而只包含最新10万条记录的增量索引,重建一次只需几十秒。

安装

wget http://sphinxsearch.com/files/archive/sphinx-0.9.9.tar.gz
tar -zxvf sphinx-0.9.9.tar.gz
cd sphinx-0.9.9/
./configure --prefix=/usr/local/sphinx --with-mysql --with-python --enable-id64
make
make install

可能出现的问题:

1、./configure时出错

在这里插入图片描述

# 1、安装libmysqlclient-dev
sudo apt-get install libmysqlclient-dev
# 2、查看mysql_config位置,我的在/usr/bin/mysql_config
which mysql_config
./configure --prefix=/usr/local/sphinx --with-mysql=/usr --with-python --enable-id64
make && make install
2、make时出错

在这里插入图片描述

cd sphinx-0.9.9/src
vim sphinxexpr.cpp

快速跳到1047行修改(:行号,另外显示行号:set nu)
在这里插入图片描述
还有两行也需要修改,具体哪一行看报错信息。

配置

sphinx.conf.dist是配置模板,可以使用cp sphinx.conf.dist sphinx.conf然后在sphinx.conf上修改配置,或者直接新建sphinx.conf文件。

cd /usr/local/sphinx/etc
touch sphinx.conf

如何配置?
更多配置请看https://blog.youkuaiyun.com/phachon/article/details/52450970
配置完之后:

# 生成索引
/usr/local/sphinx/bin/indexer --all
# 打开 sphinx 进程
/usr/local/sphinx/bin/searchd

实例

配置文件:

source document
{
  type					= mysql
  sql_host				= 127.0.0.1
  sql_user				= root
  sql_pass				= 
  sql_db				= blog
  sql_port				= 3306
  sql_query_pre 		= SET NAMES UTF8
  sql_query				= SELECT art_id,title,content FORM 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值