【问题标题】:Rebuild Apache Solr index after Drupal commere product price updatedDrupal commere 产品价格更新后重建 Apache Solr 索引
【发布时间】:2014-07-10 10:50:53
【问题描述】:
有没有办法以编程方式更新单品 Sorl 索引?
这是我的价格更新模块中的一个 sn-p。我需要在它之后运行索引更新:
$wrapper = entity_metadata_wrapper('commerce_product', $pid);
$wrapper->commerce_price->amount = $price * 100;
$wrapper->commerce_price->currency_code = $currency;
$wrapper->save();
【问题讨论】:
标签:
drupal
solr
drupal-7
drupal-commerce
【解决方案1】:
我不知道您如何使用 Drupal 处理您的 solr。我自己用 curl 编写程序......但也许这对你有帮助......
你有两种方法:
第一种方式:删除旧产品重新添加:
$json = '{"delete":{"query":"id:' . $articleId . '"},"commit":{}}'
$url = 'http://solrhost/solr/yourcore/update/json';
用curl处理url,json字符串就是你的post字段
$json = '{"add":' . $json_of_article . ',"commit":{}}';
$url = 'http://solrhost/solr/yourcore/update/json';
用curl处理url,json字符串就是你的post字段
第二种方式:更新一个产品中的字段
$data = json_encode(array('doc' => array('id' => $articleId, 'price' => array('set' => $newPrice))));
$json = '{"add":' . $data . ',"commit":{}}';
$url = 'http://solrhost/solr/yourcore/update/json';
我希望这会有所帮助...