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

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

发布时间:2024-02-17 12:51:35 作者:佚名 阅读:(36)

最发现网站后台搜索起来经常很卡,原因是随着数据量不断的增加发现数据库负载过高,最后只好上sphinx分词搜索,接下来云梦编程为大家介绍一下Centos安装sphinx-for-chinese支持中文全文索引,有需要的小伙伴可以参考一下:

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      = root
   sql_pass      =
    sql_db       = test
   sql_port      = 3306 # optional, default is 3306

   sql_query     = \
    SELECT id,channID,UNIX_TIMESTAMP(addtime) AS create_at,title,content \
FROM web_gonglue

   sql_attr_uint     = channID
   sql_attr_timestamp = addtime

   sql_query_info    = SELECT * FROM web_gonglue 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方法全部内容了,了解更多相关文章请关注吾云梦编程网!

© 2023 - 云梦编程网 版权所有 鲁ICP备2021017318号-4