sphinx使用说明

包括搜索和更新状态两个功能使用。


//实例化   
require_once("sphinxclient.class.php");   
$sphinx = new SphinxClient;   
//搜索功能   
$mode = SPH_MATCH_EXTENDED2;   //匹配模式   
$ranker = SPH_RANK_PROXIMITY_BM25; //统计相关度计算模式,仅使用BM25评分计算   
$sphinx->SetServer('127.0.0.1', '9312');   
$sphinx->SetArrayResult(true);   
$sphinx->SetMatchMode($mode);   
$sphinx->SetRankingMode($ranker);   
//过滤status字段,只显示正常帖子,不显示已删除帖子。字段要在sphinx配置为索引   
$sphinx->SetFilter('status', array(0));   
//过滤时间段   
if($StartTime > 0)   
{   
    $sphinx->SetFilterRange('senddate', $StartTime, time(), false);   
}   
//设置字段的权重   
$sphinx->SetFieldWeights(array('title' => 10, 'description' => 5, 'body' => 5));   
//设置排序,先按权重,再按id   
$sphinx->SetSortMode( SPH_SORT_EXTENDED, "@weight DESC, @id desc" );   
//分页   
$limitstart = 0;   
$row = 10;   
$sphinx->SetLimits($limitstart, (int)$row, ($row>1000) ? $row : 1000);   
//结果   
$res = array();   
$res = $sphinx->Query($this->Keywords." @flag !s", 'mysql, delta');   
var_dump($res);   
  
//删除索引,删除帖子时更新状态(主索引和增量索引),不让搜索时搜索出来   
$sphinx->UpdateAttributes('mysql', array('status'),array($aid => array(-2)));   
$sphinx->UpdateAttributes('delta', array('status'),array($aid => array(-2))); 

=========================================================================

 
 
可以在创建索引时,配置文件中设置以下属性: sql_attr_bool = del is_deleted 默认值为 0 ,当 记录要删除时,调用接口中的 UpdateAttributes设置其属性值为 1,在搜索和合并索引时增加过滤器只让 is_deleted 为 0 的 记录通过
 
select id, title, content, 1 as delfrom table

$s->UpdateAttributes('post_main, post_delta', array('del'), array($id => array(0)));
在合并索引的时候怎么设置过程器?
相关的开关是--merge-dst-range: indexer --merge main delta --merge-dst-range is_deleted 0 0 这个开关允许您在合并过程中对目标索引实施过滤。过滤器可以有多个,只有满足全部过滤 条件的文档才会在最终合并后的索引中出现。在此例子中,过滤器只允许“is_deleted”为 0 的那些条件通过,而去除所有标记为已删除(“is_deleted” 为非0)的 记录
==================================================================  public $client;     public function __construct($id, $module = null) {         parent::__construct ( $id, $module );         $this->client = new SphinxClient ();     }     public function actionTest(){                 $this->client->UpdateAttributes ( "products", array("deleted"), array(649768=>array(1)) );         $this->client->UpdateAttributes ( "products_delta", array("deleted"), array(649768=>array(1)) );          }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值