• php + mysql + sphinx 的全文检索(2)


    1. 简单 使用php api 去查询 sphinx 的索引数据
      1. $sphinx = new SphinxClient(); 
                    $sphinx->SetServer ( 'localhost', 9312 ); //sphinx的主机名和端口 
     
          //设置返回结果集为php数组格式
     
          $sphinx->SetArrayResult ( true );
     
          //匹配结果的偏移量,参数的意义依次为:起始位置,返回结果条数,最大匹配条数
     
          $sphinx->SetLimits(0, 20, 1000);
     
          //最大搜索时间
     
          $sphinx->SetMaxQueryTime(10);
     
          //执行简单的搜索,这个搜索将会查询所有字段的信息,要查询指定的字段请继续看下文
     
          $index = 'test1'; //索引源是配置文件中的 index 类,如果有多个索引源可使用,号隔开:'email,diary' 或者使用'*'号代表全部索引源
     
          $result = $sphinx->query ('doc', $index);
     
          echo '<pre>';
     
          print_r($result);
     
          echo '</pre>'; 
     
     
     
     
    从上面可以看出Query并不能全部取得我们想要的记录内容,比如说Title,Contents字段就没有取出来,根据官方的说明是sphinx并没 有连到mysql去取记录,只是根据它自己的索引内容进行计算,因此如果想用sphinxAPI去取得我们想要的记录,还必须将Query的结果为依据去 查询MySQL才可以得到最终我们想要的结果集.
  • 相关阅读:
    Linux Ubuntu安装Mysql5.7
    Linux Ubuntu安装maven3.3.9
    Linux Ubuntu安装tomcat9
    Linux Ubuntu安装JDK1.8
    Win10 U盘安装ubuntu16.04 LTS 双系统
    Linux Mysql5.7 常用语句与函数
    在Linux CentOS 6.6上安装Python 2.7.9
    CentOS6下docker的安装和使用
    How to Install Apache Solr 4.5 on CentOS 6.4
    SpringBoot的日志管理
  • 原文地址:https://www.cnblogs.com/yubinbin/p/4763212.html
Copyright © 2020-2023  润新知