下面是添加用于排序和输出的字段的代码示例。
/**
* 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 清除主题注册表
或者如前所述,您可以使用预处理器挂钩覆盖。
问候, 斯拉瓦