sphinx3.1.1的安装与使用

  1. 下载sphinx3.1.1

    • wget http://sphinxsearch.com/files/sphinx-3.1.1-612d99f-linux-amd64.tar.gz
  2. 解压 
    • tar zxf sphinx-3.1.1-612d99f-linux-amd64.tar.gz
  3. 改名 sphinx 并移动到 /usr/local/
    • mv sphinx-3.1.1 sphinx
    • mv sphinx /usr/local/
  4. 到sphinx目录下创建 data,log文件夹
    • cd /usr/local/sphinx
    • mkdir data && mkdir log
  5. 在/usr/local/sphinx/etc 编写 sphinx.conf 配置文件
    • vim /usr/local/sphinx/etc/sphinx.conf
    • #
      # Minimal Sphinx configuration sample (clean, simple, functional)
      #
      
      source src1
      {
          type                = mysql
          sql_host            = localhost
          sql_user            = root
          sql_pass            = root
          sql_db              = test
          sql_port            =     # optional, default is
          sql_query_pre       = SET NAMES utf8
          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
      }
      
      index test1
      {
          source                  = src1
          path                    = /usr/local/sphinx/data/test1
          min_word_len            =
          ngram_len               =
          ngram_chars             = U+..U+2FA1F
      }
      
      indexer
      {
          mem_limit        = 128M
      }
      
      searchd
      {
              listen                  =
              listen                  = :mysql41
              log                     = /usr/local/sphinx/log/searchd.log
              query_log               = /usr/local/sphinx/log/query.log
              read_timeout            =
              max_children            =
              pid_file                = /usr/local/sphinx/log/searchd.pid
              seamless_rotate         =
              preopen_indexes         =
              unlink_old              =
              binlog_path             = /usr/local/sphinx/data/
      }
  6. 在test数据库中 运行/usr/local/sphinx/etc目录下的example.sql文件
    • 进入mysql
    • use test;
    • source /usr/local/sphinx/etc/example.sql
  7. 添加索引
    • /usr/local/sphinx/bin/indexer -c  /usr/local/sphinx/etc/sphinx.conf test1
    • /usr/local/sphinx/bin/indexer -c /usr/local/sphinx/etc/sphinx.conf test1 --rotate  // 重新生成索引命令
  8. 运行sphinx
    • /usr/local/sphinx/bin/searchd -c  /usr/local/sphinx/etc/sphinx.conf
    • /usr/local/sphinx/bin/searchd -c /usr/local/sphinx/etc/sphinx.conf --stop  //停止sphinx命令

  9. php操作sphinx
    • 复制/usr/local/sphinx/api/ 目录下的 sphinxapi.php
    • $sphinx = new SphinxClient();
      $q      = $_GET['key'] ?? 'test'; //搜索关键字// 3.1已经弃用了setMatchMode!直接写查询语法就可以// 如果要匹配字符串中任意一个词或字使用如下写法// '"string1" | "string2" | "string3"'
      
      // '@(title,content) string'  @括号中的是要搜索的字段 可以写多个或单个
      
      // '^$string$'  表示全部匹配 类似mysql中的 fieldName = 'string'// 更多用法可以参考正则表达式或者官方文档
      
      // 中文分词扩展建议使用scws,官网安装和使用教程说明很详细,(不过sphinx自带的一元分词已经够用了,一般不需要scws//http://www.xunsearch.com/scws/
      $sql    = "";
      $host   = "127.0.0.1";
      $port   = 9312;
      $index  = "test1";
      $sphinx->SetServer($host, $port);
      $sphinx->SetConnectTimeout(10);
      $sphinx->SetArrayResult(true);
      $res = $sphinx->Query($q, $index);
      print_r($res);

      运行结果如下:

结束,记得数据库数据改变后需重新生成索引

分词搜索 sphinx3.1.1+php+mysql的更多相关文章

  1. linux环境下安装sphinx中文支持分词搜索(coreseek+mmseg)

     linux环境下安装sphinx中文支持分词搜索(coreseek+mmseg) 2013-11-10 16:51:14 分类: 系统运维 为什么要写这篇文章? 答:通过常规的三大步(./confi ...

  2. Sphinx + Coreseek 实现中文分词搜索

    Sphinx + Coreseek 实现中文分词搜索 Sphinx Coreseek 实现中文分词搜索 全文检索 1 全文检索 vs 数据库 2 中文检索 vs 汉化检索 3 自建全文搜索与使用Goo ...

  3. ECSHOP模糊分词搜索和商品列表关键字飘红功能

    ECSHOP联想下拉框 1.修改page_header.lbi模版文件,将搜索文本框修改为: <input name="keywords" type="text&q ...

  4. 【netcore基础】.Net core通过 Lucene.Net 和 jieba.NET 处理分词搜索功能

    业务要求是对商品标题可以进行模糊搜索 例如用户输入了[我想查询下雅思托福考试],这里我们需要先将这句话分词成[查询][雅思][托福][考试],然后搜索包含相关词汇的商品. 思路如下 首先我们需要把数据 ...

  5. 实操重写IK分词器源码,基于mysql热更新词库

    实操重写IK分词器源码,基于mysql热更新词库参考网址:https://blog.csdn.net/wuzhiwei549/article/details/80451302 问题一:按照这篇文章的介 ...

  6. 32.修改IK分词器源码来基于mysql热更新词库

    主要知识点, 修改IK分词器源码来基于mysql热更新词库     一.IK增加新词的原因 在第32小节中学习到了直接在es的词库中增加词语,来扩充自已的词库,但是这样做有以下缺点: (1)每次添加完 ...

  7. ElasticSearch 中文分词搜索环境搭建

    ElasticSearch 是强大的搜索工具,并且是ELK套件的重要组成部分 好记性不如乱笔头,这次是在windows环境下搭建es中文分词搜索测试环境,步骤如下 1.安装jdk1.8,配置好环境变量 ...

  8. 分词搜索 sphinx+php+mysql

    sphinx3.1.1的安装与使用 下载sphinx3.1.1 wget http://sphinxsearch.com/files/sphinx-3.1.1-612d99f-linux-amd64. ...

  9. Solr分词搜索结果不准确

    Solr的schema.xml默认配置分词后条件取 OR 例如:大众1.6T  系统会自动分词为  [大众] [1.6T](ps:不同分词器分词效果不同)   会搜索出包含 [大众 OR  1.6T] ...

随机推荐

  1. Prime Path (POJ - 3126 )(BFS)

    转载请注明出处:https://blog.csdn.net/Mercury_Lc/article/details/82697622     作者:Mercury_Lc 题目链接 题意:就是给你一个n, ...

  2. 五一培训 清北学堂 DAY5

    今天是吴耀轩老师的讲解- 今天的主要内容:图论 如何学好图论? 学好图论的基础:必须意识到图论! 图 邻接矩阵存图: 其缺点是显而易见的:1. 空间复杂度O(n^2)不能接受:2.有重边的时候很麻烦: ...

  3. mysql被收购 用mariadb

    ~]# systemctl start mysql.service 要启动MySQL数据库是却是这样的提示 Failed to start mysqld.service: Unit not found ...

  4. 使用selenium IDE 等一系列需要下载的东西的地址

    转载来自:http://blog.csdn.net/u012246342/article/details/53005730 selenium 官网 IDE 等一系列 下载地址:http://www.s ...

  5. No Desktop License Servers available to provide a license

    远程桌面连接失败,提示:“no Remote Desktop License Servers available to provide a license” 原因:没有remote desktop l ...

  6. arcgis 面或线要素类上的搜索游标

    import arcpy infc = arcpy.GetParameterAsText(0) # Identify the geometry field # desc = arcpy.Describ ...

  7. 前端知识点回顾——Javascript篇(一)

    DOM特殊元素获取 document.documentElement //HTML标签 document.head //head标签 document.title //title标签 document ...

  8. 使用KerasNet

    1.安装Python3.6,必须是3.6因为当前KerasNet的配套版本是3.6 https://www.python.org/ftp/python/3.6.8/python-3.6.8-amd64 ...

  9. Android中常见的默认实现类

    * Basexxx* Defaultxxx* Simplexxx* Baicxxx

  10. Django博客系统

    零.创建项目及配置 一.编写 Model 层的代码 二.配置 admin 页面 三.根据需求定制 admin