记录在此,作为分享,也作为自己的存档。
不要用原生Sphinx,因为中文支持不好。要用sphinx-for-chinese,数据库编码要用utf-8,既能很好的受sphinx支持,又符合php规范。
git clone https://github.com/eric1688/sphinx
cd sphinx
./configure --prefix=/usr/local/sphinx --with-mysql
make & make install
从xdict_1.1.txt生成xdict文件,xdict_1.1.txt文件可以根据需要进行修改
/usr/local/sphinx/bin/mkdict xdict_1.1.txt xdict
xdict生成完成显示:
Preparing...
Making Chinese dictionary: 100% |******************************|
Total words: 284757
File size: 2854912 bytes
Compression ratio: 100 %
Chinese dictionary was successfully created!
将xdict放入sphinx目录:
cp xdict /usr/local/sphinx/etc/
修改sphinx.conf索引配置文件:
cd /usr/local/sphinx/etc/
cp sphinx.conf.dist sphinx.conf
vim sphinx.conf
配置文件参考网上一个人写的吧,搬来:
# sphinx基本配置
# 索引源
source goods_src
{
# 数据库类型
type = mysql
# MySQL主机IP
sql_host = localhost
# MySQL用户名
sql_user = sphinxuser
# MySQL密码
sql_pass = sphinxpass
# MySQL数据库
sql_db = sphinx
#

本文档介绍了如何在Ubuntu 16.04上配置Sphinx-for-chinese,以实现中文全文搜索,并结合PHP进行排序、筛选和分页的基本操作。建议使用sphinx-for-chinese以获得更好的中文支持,同时确保数据库编码为utf-8。在重新构建索引时,需注意如果Sphinx守护进程正在运行,需先停止再重建。详细的操作指南可参考官方文档。
最低0.47元/天 解锁文章
5222

被折叠的 条评论
为什么被折叠?



