• linux下安装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 目录下并且解压

    三、进入安装目录执行,将程序安装到 /usr/local/sphinxforchinese目录下

      将 configure的第7804行 “$as_echo "#define USE_LIBICONV 0" >>confdefs.h”修改为“$as_echo "define USE_LIBICONV 0" >>confdefs.h”

      要不然会安装不成功然后执行下面命令

    ./configure  --prefix=/usr/local/sphinxforchinese  --with-mysql
    make
    make install

    四、生成字典(先进入到 /usr/local/sphinxforchinese)

      1.将文件夹中的 xdict_1.1.txt (点击下载)文件丢到 /usr/local/sphinxforchinese目录下

       2.执行如下命令   

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

     五、新建索引

      1、将 sphinx.conf 丢到 /usr/local/sphinxforchinese/etc 中并且配置数据库连接信息

      2、创建索引

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

      sphinx.conf 文件信息如下

    #
    # Minimal Sphinx configuration sample (clean, simple, functional)
    #
      
    source src1
    {
        # 你的数据库配置信息
        type            = mysql
      
        sql_host        = 127.0.0.1
        sql_user        = root
        sql_pass        = 123456
        sql_db          = shop
        sql_port        = 3306  # optional, default is 3306
      
        # 数据源
        sql_query       = 
            SELECT goods_id, goods_name,goods_desc, goods_lessen,goods_type,goods_brand,goods_price,goods_points,is_points,goods_heat,goods_status,goods_addtime FROM goods
        # 具体字段优化 
        # 正整数类型
        sql_attr_uint       = is_points
        # 时间戳类型
        sql_attr_timestamp  = goods_addtime
    }
    
    index test1
    {
        source          = src1
        # 确保目录存在,不存在创建
        path            = /usr/local/sphinxforchinese/var/data/test1
        # 配置中文字典
        chinese_dictionary = /usr/local/sphinxforchinese/etc/xdict
    }
    
    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
        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

     七、查看是否成功

      检查 /usr/local/sphinxforchinese/var/data 中是否有 test1开头的几个文件

    八、sphinx常用命令

      1、启动

    /usr/local/sphinxforchinese/bin/searchd

      2、停止

    /usr/local/sphinxforchinese/bin/searchd –stop

      3、创建索引

    /usr/local/sphinxforchinese/bin/indexer -c /usr/local/sphinxforchinese/etc/sphinx.conf  --all --rotate
    IT成长中的那些事儿
  • 相关阅读:
    ObjectQuery查询及方法
    SQL系列(十三)—— 关于表的DDL
    SQL系列(十二)—— insert update delete
    Git Push 避免用户名和密码方法
    Git系列 —— github提交一个空目录
    Git系列 —— 记一次Mac上git push时总是403的错误
    Mysql系列(三)—— Mysql主从复制配置
    SQL系列(十一)—— 函数(function)
    SQL系列(十)—— 联结(join)
    动态代理(二)—— CGLIB代理原理
  • 原文地址:https://www.cnblogs.com/life_lt/p/15348533.html
Copyright © 2020-2023  润新知