sphinx-for-chinese 安装
背景:需要使用中文搜索
安装环境:debian11
下载安装包
sphinx-for-chinese2.2.1.tar.gz
解压
tar -xzf sphinx-for-chinese2.2.1.tar.gz
安装编译器
apt install build-essential
安装mysql
apt install -f lsb-release gnupg #安装依赖
下载存储库MySQL :: MySQL Community Downloads
安装,选择版本
dpkg -i mysql-apt-config_0.8.30-1_all.deb
更新
apt-get update
安装
apt-get install mysql-server #数据库在其他服务器可不安装
安装mysql-devel
apt-get install libmysqlclient-dev
apt-get install libmysqld-dev
#卸载MySQL
sudo apt-get autoremove mysql-server
sudo apt-get -f install
sudo apt-get remove --purge mysql-\*
sudo apt-get install mysql-server mysql-client
5.安装sphinx
cd sphinx-for-chinese-2.2.1-dev-r4311/
./configure --prefix=/usr/local/sphinxforchinese --with-mysql
#./configure --prefix=/usr/local/sphinxforchinese --without-mysql
make && make install
6.生成字典
cd /usr/local/sphinxforchinese
将文件夹中的 xdict_1.1.txt放入此目录xdict_1.1.tar.gz
/usr/local/sphinxforchinese/bin/mkdict xdict_1.1.txt etc/xdict
执行命令生成文件
重建索引
编辑/usr/local/sphinxforchinese/etc/sphinx.conf文件
#
# Minimal Sphinx configuration sample (clean, simple, functional)
#
source goods
{
type = mysql
sql_host = 192.168.109.220
sql_user = genegroup
sql_pass = genegroup*&^678
sql_db = genegroup
sql_port = 3306 # optional, default is 3306
sql_query_pre = SET NAMES utf8
# sql_attr_uint = group_id
# sql_attr_timestamp = date_added
# sql_query_info = SELECT * FROM documents WHERE id=$id
sql_query = SELECT id, site_id, add_time,status,cat_id,brand_id,goods_cattype,ischeck,is_on_sale,goods_name,goods_sn,goods_desc,features,parameter,support FROM oa_goods
sql_field_string = goods_name
sql_field_string = goods_sn
sql_field_string = goods_desc
sql_field_string = features
sql_field_string = parameter
sql_field_string = support
sql_attr_uint = site_id
sql_attr_uint = status
sql_attr_uint = cat_id
sql_attr_uint = brand_id
sql_attr_uint = goods_cattype
sql_attr_uint = ischeck
sql_attr_uint = is_on_sale
sql_attr_uint = add_time
}
index genegroupgoods
{
source = goods
path = /usr/local/sphinxforchinese/var/data/genegroupgoods
docinfo = extern
charset_type = utf-8
chinese_dictionary = /usr/local/sphinxforchinese/etc/xdict
#field = goods_name,goods_sn,goods_desc,features,parameter,support
#attr_uint = site_id,status,cat_id,brand_id,goods_cattype,ischeck,is_on_sale,add_time
charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F
min_word_len = 1
min_prefix_len = 0
min_infix_len = 2
ngram_len = 1
ngram_chars = U+3000..U+2FA1F
}
indexer
{
mem_limit = 256M
}
searchd
{
listen = 9312
listen = 9306:mysql41
log = /usr/local/sphinxforchinese/var/log/searchd.log
query_log = /usr/local/sphinxforchinese/var/log/query.log
read_timeout = 5
max_children = 30
pid_file = /usr/local/sphinxforchinese/var/log/searchd.pid
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
workers = threads # for RT to work
binlog_path = /usr/local/sphinxforchinese/var/data
}
/usr/local/sphinxforchinese/bin/indexer -c /usr/local/sphinxforchinese/etc/sphinx.conf --all --rotate
重建索引
/usr/local/sphinxforchinese/bin/searchd -c /usr/local/sphinxforchinese/etc/sphinx.conf
启动