1

プログラムで単一製品の Sorl インデックスを更新する方法はありますか? これは私の価格更新モジュールのスニペットです。その直後に index update を実行する必要があります。

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

1 に答える 1

0

Drupal で solr をどのように扱っているかわかりません。私はcurlを使って自分でプログラムします...しかし、これは途中で役立つかもしれません...

2 つの方法があります。

最初の方法: 古い製品を削除して再度追加します:

$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 文字列は投稿フィールドです

2 番目の方法: 1 つの製品でフィールドを更新する

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

これが役立つことを願っています...

于 2014-07-10T18:21:07.007 に答える