更新Drupal commere产品价格后重建Apache Solr索引

时间:2014-07-10 10:50:54

标签: drupal solr drupal-7 drupal-commerce

有没有办法以编程方式更新单个产品Solr索引? 以下是我的价格更新模块的摘录。我需要在它之后立即运行索引更新:

$wrapper = entity_metadata_wrapper('commerce_product', $pid);
$wrapper->commerce_price->amount = $price * 100;
$wrapper->commerce_price->currency_code = $currency;
$wrapper->save();

1 个答案:

答案 0 :(得分:0)

我不知道你是如何用Drupal处理你的solr的。我自己用卷曲编程......但也许这会帮助你顺利...

您有两种方式:

第一种方式:删除旧产品并重新添加:

$json = '{"delete":{"query":"id:' . $articleId . '"},"commit":{}}'
$url  = 'http://solrhost/solr/yourcore/update/json';

使用curl处理url,json字符串是你的帖子字段

$json = '{"add":' . $json_of_article . ',"commit":{}}';
$url  = 'http://solrhost/solr/yourcore/update/json';

使用curl处理url,json字符串是你的帖子字段

第二种方式:更新一个产品中的字段

$data = json_encode(array('doc' => array('id' => $articleId, 'price' => array('set' => $newPrice))));
$json = '{"add":' . $data . ',"commit":{}}';
$url  = 'http://solrhost/solr/yourcore/update/json';

我希望这会有所帮助......