当前位置:首页 > Liunx教程 >

Centos安装sphinx-for-chinese 支持中文全文索引

发布时间:2019-06-05 20:06:07 作者:佚名 阅读:(240)

最近在做一个站,由于数据量比较大,搜索起来经常发现数据库卡住的问题,最后只好上sphinx分词搜索,接下来吾爱编程为大家介绍一下Centos安装sphinx-for-chinese 支持中文全文索引,有需要的小伙伴可以参考一下:

.需要安装mysql和Gcc和g++

yum install gcc
yum install g++

在linux下,C++的编译器不是g++这个名称,而是gcc-c++,由此看来的确是我想当然了。然后直接运行

yum install gcc-c++ libstdc++-devel

二.将sphinx-for-chinese.tar.gz 放在/usr/local 目录下并且解压

三.进入sphinx-for-chinese-2.2.1-dev-r4311目录执行,将程序安装到 /usr/local/sphinxforchinese目录下

cd sphinx-for-chinese-2.2.1-dev-r4311

./configure  --prefix=/usr/local/sphinxforchinese  --with-mysql
vim configure
7804行
$as_echo "define USE_LIBICONV 0" >>confdefs.h
make
make install

四.生成字典(先进入到)
1.将文件夹中的 xdict_1.1.txt 文件丢到 /usr/local/sphinxforchinese目录下
2.执行如下命令

cd /usr/local/sphinxforchinese
/usr/local/sphinxforchinese/bin/mkdict  xdict_1.1.txt  etc/xdict

五、修改配置文件
复制/usr/local/sphinxforchinese/etc/sphinx-min.conf.dist 改名为:/usr/local/sphinxforchinese/etc/sphinx.conf ,根据自己情况他修改配置文件内容

source src1
{
    type         = mysql

   sql_host      = localhost
   sql_user      = test
   sql_pass      =
    sql_db       = test
   sql_port      = 3306 # optional, default is 3306

   sql_query     = \
    SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content \
FROM documents

   sql_attr_uint     = group_id
   sql_attr_timestamp = date_added

   sql_query_info    = SELECT * FROM documents WHERE id=$id
}

index test1
{
    source       = src1
   path         = /usr/local/sphinxforchinese/var/data/test1
   docinfo          = extern
   charset_type      = sbcs
}

index testrt
{
    type         = rt
   rt_mem_limit      = 32M

   path         = /usr/local/sphinxforchinese/var/data/testrt
   charset_type      = utf-8

   rt_field      = title
   rt_field      = content
   rt_attr_uint      = gid
}

indexer
{
    mem_limit     = 32M
}

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
}

六、启动sphinx

/usr/local/sphinxforchinese/bin/searchd  -c  /usr/local/sphinxforchinese/etc/sphinx.conf

七、不停止 searchd 重新新建索引

/usr/local/sphinxforchinese/bin/indexer  -c  /usr/local/sphinxforchinese/etc/sphinx.conf  --all  --rotate

八:查看是否成功 检查 /usr/local/sphinxforchinese/var/data 中是否有 newindex开头的几个文件

欢迎分享转载→ Centos安装sphinx-for-chinese 支持中文全文索引

© 2015-2019 - 吾爱编程网 版权所有 苏ICP备18033726号-1关于我们 - 网站声明 - 联系我们