当前位置 : 主页 > 网络编程 > PHP >

sphinx 高级筛选

来源:互联网 收集:自由互联 发布时间:2023-11-09
此方法基于sphinx_client.class封装sphinx版本在2.0以上 $where = arrray(); $whrer['index'] = String --查询索引名 $where['search_key'] = String --模糊查询 $where['field'] = String --查询返回字段 $where['key'] = ['字段

此方法基于sphinx_client.class封装sphinx版本在2.0以上


$where = arrray();

$whrer['index'] = String --查询索引名

$where['search_key'] = String --模糊查询

$where['field'] = String --查询返回字段

$where['key'] = ['字段1'=>[值1,值2,],'字段2'=>[值1,值2,]] --等量查询多维数组

$where['not_key'] = ['字段1'=>[值1,值2,],'字段2'=>[值1,值2,]] --取反查询

$where['or_key'] = String --范围查询

$where['or_min'] = int -- 范围查询起点

$where['or_max'] = int -- 范围查询终点

$where['where_or'] = String --或操作 a OR b

$where['sorting'] = String --排序id DESC/ASC

$where['group_key'] = String --分组查询

$where['group_key_order'] = String -- 分组查询排序方式 DESC ASC

$where['start'] = int -- 分页偏移开始

$where['limit'] = int --获取数据条数


/**sphinx查询

* @param $where

*/

public function sphinx_api($where){

$this->config->load('sphinx');

$this->load->library('sphinx_client');

$this->sphinx_client->setServer(主机IP, 端口 port);

$this->sphinx_client->setMatchMode(SPH_MATCH_ALL);

$this->sphinx_client->setMaxQueryTime(设置超时时间);

$this->sphinx_client->ResetFilters();

$this->sphinx_client->ResetGroupBy();

if (array_key_exists("field",$where)) {

if(array_key_exists("where_or",Misplaced &where['where_or'])){

where['field'].',if(('.$where['where_or'].'),1,0) as or_filter';

$this->sphinx_client->SetFilter('or_filter', [1]);

}

where['field']);

}else{

$where['field'] = '*';

if(array_key_exists("where_or",Misplaced &where['where_or'])){

where['field'].',if(('.$where['where_or'].'),1,0) as or_filter';

$this->sphinx_client->SetFilter('or_filter', [1]);

}

where['field']);

}

if (array_key_exists("sorting",$where)) {

where['sorting']);

}

if (array_key_exists("key",Misplaced &where['key'])) {

foreach (key=>$value) {

key, $value);

}

}

if (array_key_exists("not_key",Misplaced &where['not_key'])) {

foreach (key=>$value) {

key, $value,true);

}

}

if (array_key_exists("or_key",$where)) {

where['or_key'], where['or_max']);

}

if(array_key_exists('group_key',$where)) {

if (array_key_exists('group_key_order',$where)) {

where['group_key'], SPH_GROUPBY_ATTR,$where['group_key_order']);

}else{

where['group_key'], SPH_GROUPBY_ATTR);

}

}

if(array_key_exists("limit",Misplaced &where)){

where["start"],$where['limit'],15000);

}


if (!array_key_exists("search_key",$where)) {

$where['search_key'] = '';

}

if (!array_key_exists("index",$where)) {

return false;

}

this->sphinx_client->query(where['index']);

this->sphinx_client->GetLastError();

if(!empty($error)) return false;

if($res['total']==0) return false;

if($res){

res["matches"]);

res['total'];

return $arr;

}else{

return false;

}

}

github: https://github.com/wulimax

上一篇:GD问题
下一篇:没有了
网友评论