--------------------------【安装篇】:----------------------------------------------------------
在安装的过程中我们会碰到依赖包的问题
(1)、下载Sphinx
从sphinx官网上找到sphinx的安装源码
最新地址:http://sphinxsearch.com/downloads/ 在网盘保存有版本
解压:tar -zxvf /home/sphinx-2.1.3-release.tar.gz -C 【目录自己定】
(2)、编译安装
进入到sphinx的源码文件夹里,运行下列命令就可以安装sphinx了:
cd /usr/local/sphinx-2.1.3-release【目录自己定】
./configure --prefix=/usr/local/sphinx --with-mysql=/usr/local/mysql
make && make install【目录自己定】
Sphinx中重要的三个命令,(Sphinx安装的bin目录下)
Indexer 创建索引命令。Searchd 启动进程命令。Search 命令行搜索命令。(完)
(3)、配置sphinx.conf
自己找备份,此次留空
(4)、命令注解
创建索引命令:indexer
-c 指定配置文件
--all 对所有索引重新编制索引。
--rotate 用于轮换索引,主要是再不停止服务的时候,增加索引。
--buildstops --buildfreqs 要一起使用,
例:indexer myindex --buildstops text.txt 1000 --buildfreqs
会在当前目录下生成,一个名字叫text.txt,最多包含1000个词的词表。
--merge 合并索引 (后面会详细讲)
/usr/local/sphinx/bin/indexer -c /usr/local/sphinx/etc/sphinx.conf --all
(5)、API调用,直接sphinxapi.php文件放程序根目录,require_once "sphinxapi.php";
--------------------------【使用篇】:----------------------------------------------------------
1、解决Sphinx 使用报错:index 'test1': search error: query too complex, not enough stack (thread_stack=-65032K
sql_query_info = SELECT * FROM documents WHERE id=$id
2、在安装好sphinx 后,启动 searchd 服务时总是提示如下错误:
index 'test': search error: failed to open /var/data/test.sph: sphinx 错误解决 index 'test': search error: failed to open /var/data/test.sph:No such file or directory; NOT SERVING
这个错误可能是没有建立好索引导致的,所以 indexer --all --rotate ,重新建一次索引
--------------------------【配置文件详细说明篇】:----------------------------------------------------------
##
数据源src1
source src1
{
## 说明数据源的类型。数据源的类型可以是:mysql,pgsql,mssql,xmlpipe,odbc,python
## 有人会奇怪,python是一种语言怎么可以成为数据源呢?
## python作为一种语言,可以操作任意其他的数据来源来获取数据,更多数据请看:(http://www.coreseek.cn/products-install/python/)
type = mysql
## 下面是sql数据库特有的端口,用户名,密码,数据库名等。
sql_host = localhost
sql_user = test
sql_pass =
sql_db = test
sql_port = 3306
## 如果是使用unix sock连接可以使用这个。
# sql_sock = /tmp/mysql.sock
## indexer和mysql之间的交互,需要考虑到效率和安全性。
## 比如考虑到效率,他们两者之间的交互需要使用压缩协议;考虑到安全,他们两者之间的传输需要使用ssl
## 那么这个参数就代表这个意思,0/32/2048/32768 无/使用压缩协议/握手后切换到ssl/Mysql 4.1版本身份认证。
# mysql_connect_flags = 32
## 当mysql_connect_flags设置为2048(ssl)的时候,下面几个就代表ssl连接所需要使用的几个参数。
# mysql_ssl_cert = /etc/ssl/client-cert.pem
# mysql_ssl_key = /etc/ssl/client-key.pem
# mysql_ssl_ca = /etc/ssl/cacert.pem
## mssql特有,是否使用windows登陆
# mssql_winauth = 1
## mssql特有,是使用unicode还是单字节数据。
# mssql_unicode = 1 # request Unicode data from server
## odbc的dsn串
# odbc_dsn = DBQ=C:\data;DefaultDir=C:\data;Driver={Microsoft Text Driver (*.txt; *.csv)};
## sql某一列的缓冲大小,一般是针对字符串来说的。
## 为什么要有这么一种缓冲呢?
## 有的字符串,虽然长度很长,但是实际上并没有使用那么长的字