更新sphinx 索引属性方法 -UpdateAttributes 使用

本文介绍了一种使用Sphinx搜索引擎的实时更新方法,通过UpdateAttributes()API实现商品信息的即时更新,并强调了刷新缓存的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//sphinx把商品上架(deleted为0)
	public static function upProSphinx($proid) {
		$sphinxclient = new SphinxClient ();
		$sphinxclient->UpdateAttributes ( "products", array("deleted"), array($proid=>array(0)) );
		$sphinxclient->UpdateAttributes ( "products_delta", array("deleted"), array($proid=>array(0)) );
	}


//完全不起作用
//     //商品修改更新sphinx
//     public static function editProSphinx($id, $attributes) {
//         $sphinxclient = new SphinxClient ();
//         $fields = array("name","unit_price","min_qty","is_in_realize","location_state","location_city","status");
//         $values = array($id=>array($attributes["name"],$attributes["unit_price"]*100,$attributes["min_qty"],$attributes["is_in_realize"],$attributes["location_state"],$attributes["location_city"],$attributes["status"]));
//         $sphinxclient->UpdateAttributes ( "products", $fields, $values );
//         $sphinxclient->UpdateAttributes ( "products_delta", $fields, $values );
//     }

使用 UpdateAttributes()API调用更新的属性值将一直保存在内存中,直到一次这样的刷新

$status = $cl->FlushAttributes ();
if ( $status<0 )
	print "ERROR: " . $cl->GetLastError(); 



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值