PHP调用Sphinx类API
最近TP5的项目用到了sphinx,sphinx如何安装配置百度都有,但是如何用php调用sphinx第三方,网上能直接使用的并不多,所以做了一个简单的可以直接使用的调用sphinx API的类,直接上代码
<?php
namespace Sphinx;
/**
* sphinx公共查询类
* @author 五个A的猪
* @version 1.0 版本号
*/
class Sphinx
{
/**
*sphinx 查询
*
* @access public
* @param string $ip 服务器ip
* @param string $name 查询sphinx名称
* @param array $where 查询条件:数组传参,单字段多数据传$where['test']=array(1,2,3);
* @param array $where['between'] 查询在字段值在某两个值之间参数,$where['between']['test'] = array(1,10);
* @param int $page 分页
* @param int $return_type aid返回类型:默认数组,1为字符串
* @param string $wherelogic 查询条件逻辑符号 & 和 |
* @param string $whereconn 查询条件连接符号 空格 和 =
* @param string $page_count 每页显示的数量
* @return array 返回类型
*/
public function sphinx_search($ip='',$name='',$where=array(),$page='',$return_type=0,$wherelogic="&",$whereconn=' ',$page_count=50){
$cl = new \sphinx\SphinxClient();
$cl->SetServer ($ip, 9312);
$cl->SetMatchMode (SPH_MATCH_EXTENDED2);//默认模式
$cl->SetSortMode (SPH_SORT_EXTENDED,"@id DESC");
if