3.1.1版本安装
参考:http://sphinxsearch.com/docs/sphinx3.html
我安装的3.1.1版本
启动报错:no config file, using 'sphinxdata' folder...
参考:https://www.jianshu.com/p/f12c7301a0fd
解决:没有配置文件启动,自动在bin目录下创建sphinxdata目录启动
移动到/usr/local/sphinx
mv sphinx-3.1.1 /usr/local/sphinx
复制一个简单版配置文件:
cp /usr/local/sphinx/etc/sphinx-min.conf.dist /usr/local/sphinx/etc/sphinx.conf
配置数据目录
mkdir /usr/local/sphinx/data
连接数据库使用示例/usr/local/sphinx/etc/example.sql文件到test数据库下创建两个表
mysql>use test
mysql>source /usr/local/sphinx/etc/example.sql
创建索引,--rotate 参数进行 无缝更新,无需重启服务
全部:/usr/local/sphinx/bin/indexer -c /usr/local/sphinx/etc/sphinx.conf --all --rotate
单个(test1为索引名称):/usr/local/sphinx/bin/indexer -c /usr/local/sphinx/etc/sphinx.conf test1
创建单个test1索引报错:ERROR: index 'test1': sql_connect: failed to load libmysqlclient
参考:http://sphinxsearch.com/docs/sphinx3.html
解决:yum install mariadb-devel
再次创建索引又报错:ERROR: index 'test1': sql_connect: Can't connect to local MySQL server through socket
解决:修改mysql配置项用sock连接
创建索引成功,data目录下生成很多索引文件:
用配置文件启动
/usr/local/sphinx/bin/searchd -c /usr/local/sphinx/etc/sphinx.conf
phpdemo测试:
主查询,查询出所有在检索范围的数据,以关键词为 'test' 做测试
php实例代码,官方sphinxapi.php文件在目录api下面有:
命中的搜索数据: