以下は、ソート用および出力用のフィールドを追加するコードの例です。
/**
* Implementation of hook_apachesolr_update_index()
* Here we're adding custom fields to index, so that they available for sorting. To make this work, it's required to re-index content.
*/
function somemodule_apachesolr_update_index(&$document, $node) {
if ($node->type == 'product') {
$document->addField('sm_default_qty', $node->default_qty);
$document->addField('sm_sell_price', $node->sell_price);
$document->addField('sm_model', $node->model);
foreach ($node->field_images AS $image) {
//$imagecached_filepath = imagecache_create_path('product', $image['filepath']);
$document->addField('sm_field_images', $image['filepath']);
}
}
}
/**
* Implementation of hook_apachesolr_modify_query()
* Here we point what additional fields we need to get from solr
*/
function somemodule_apachesolr_modify_query(&$query, &$params, $caller) {
$params['fl'] .= ',sm_default_qty,sm_field_images,sm_sell_price,sm_model';
}
出力を完全にカスタマイズしたい場合は、以下を実行する必要があります: 1) search-results.tpl.php と search-result.tpl.php を /modules/search からテーマのフォルダーにコピーします。2) search-result.tpl.php 内で必要に応じて $result オブジェクトを使用します 3) admin/build/themes にアクセスしてテーマレジストリをクリアすることを忘れないでください
または、前述のように、プリプロセッサ フックを使用してオーバーライドできます。
よろしく、 スラバ