下载对应版本:http://www.sphinxsearch.com/downloads/archive/
这是我的
上传或者下载到自己的服务器上
解压缩:tar -xzvf ***
进入解压的文件夹
./configure --prefix=/usr/local/sphinx --with-mysql-includes=/phpstudy/mysql/include/ --with-mysql-libs=/phpstudy/mysql/lib/
编译 这里的--prefix是要安装到的路径 --with-mysql-includes是mysql的加载路径 --with-mysql-libs是mysql的lib的根目录
应为一开始没有指定后两个路径 而且没有自动检索到mysql的配置报错为:
一开始以为是没有mysql_devel傻傻的去安装结果报错止不住。。。如下:
所以!最好能指定的指定目录这个 坑我遇到最多了 因为我懒。。。
继续编译:make
make install
cd sphinx/etc/
cp sphinx.conf.dist sphinx.conf
vi sphinx.conf //连接信息 修改为对应信息
sphinx.conf:配置文件
indexer 索引生成工具
查看searchd工具是否可用:
或者top
search --help:获取相关命令
sphinx:查询mysql数据
mysql -h0 -P9306
原因:
sphinx不能使用主键来做属性字段,你的索引配置文件中一定用了类似
sql_attr_uint = id (id为表的主键)
解决方法:
去掉sql_attr_uint = id
或改为
sql_query = SELECT id,id as aid,body from table
sql_attr_uint = aid
即:在sql_query中给id用as 重新命个名子
/usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/sphinx.conf 开启searchd
/usr/local/sphinx/bin/searchd --stop 关闭searchd
生成index索引 /usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/sphinx.conf --all
更新index索引 /usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/sphinx.conf --all --rotate
sql_field_string 字符串
sql_attr_int 数字
sql_attr_timestamp 时间戳
top*sphinx能查询的字段在于你返回的字段