zoukankan      html  css  js  c++  java
  • 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成长中的那些事儿
  • 相关阅读:
    [Luogu 2261] CQOI2007 余数求和
    [Luogu 3178] HAOI2013 树上操作
    「模板」 树链剖分 HLD
    「模板」 线段树——区间乘 && 区间加 && 区间求和
    [Luogu 2221] HAOI2012 高速公路
    [Luogu 3973] TJOI2015 线性代数
    「模板」 01 Trie实现平衡树功能
    [Luogu 1640] SCOI2010 连续攻击游戏
    [Luogu 1402] 酒店之王
    [Luogu 1963] NOI2009 变换序列
  • 原文地址:https://www.cnblogs.com/life_lt/p/15348533.html
Copyright © 2011-2022 走看看