首先查看mysql 数据库编码
进入mysql , show variables like ‘characterset%’;
如果不是utf8。请更改数据库编码
~ vim /etc/my.conf
~ service mysqld stop
~ 在mysqld下面添加
~ character_set_server=utf8
~ init_connect='SET NAMES utf8'
~ service mysqld start .
查看是否有 /etc/csft.conf, 如果没有
$ cd /usr/local/coreseek/
$ cp etc/sphinx-min.conf.dist /etc/csft.conf
命令行测试mmseg分词,coreseek搜索(需要预先设置好字符集为zh_CN.UTF-8,确保正确显示中文)
$ cd testpack
$ cat var/test/test.xml #此时应该正确显示中文
$ /usr/local/mmseg3/bin/mmseg -d /usr/local/mmseg3/etc var/test/test.xml
$ /usr/local/coreseek/bin/indexer -c /etc/csft.conf --all
$ /usr/local/coreseek/bin/search -c /etc/csft.conf 网络搜索
我的 csft.conf 的配置
source src1
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = 123456
sql_db = test
sql_port = 3306 # optional, default is 3306
sql_query = \
SELECT id,title,content \
FROM documents
sql_query_pre = SET NAMES utf8
sql_query_info = SELECT * FROM documents WHERE id=$id
}
index test1
{
source = src1
path = /usr/local/coreseek/var/data/test1
docinfo = extern
#charset_type = sbcs
charset_dictpath = /usr/local/mmseg/etc/ # 必须 不然不能使用zh_cn.utf-8
charset_type = zh_cn.utf-8
}
indexer
{
mem_limit = 32M
}
searchd
{
port = 9312
listen = 9306:mysql41
log = /usr/local/coreseek/var/log/searchd.log
query_log = /usr/local/coreseek/var/log/query.log
read_timeout = 5
max_children = 30
pid_file = /usr/local/coreseek/var/log/searchd.pid
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 0
unlink_old = 1
}