sphinx 高级筛选
  E8EDEmtgHB1o 2023年11月02日 40 0

此方法基于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

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  dwHry2iKGG0I   2023年12月26日   31   0   0 githubgithubhtmlhtml
  9J4CFPeHjrny   2023年12月24日   29   0   0 字段Java字段Java
E8EDEmtgHB1o
作者其他文章 更多

2023-11-02

2023-11-02