Drupal 7:
Below is the code, I am using in my custom module to index custom cck fields in apache solr index. Its getting the fields indexed.
function modulename_apachesolr_update_index($document, $node, $namespace) {
// When indexing nodes, add field from my custom content type
if ($node->type == 'pdf') {
$pdf_uri = $node->field_file['und'][0]['uri'];
$access = $node->field_access['und'][0]['value'];
$cusvar = "Test";
$document->addField('ss_pdf_file', $pdf_uri);
$document->addField('ss_pdf_access', $access);
$document->addField('ss_pdf_cusvar', $cusvar);
}
}
function modulename_apachesolr_query_prepare($query) {
$query->addParam('fl', 'ss_pdf_file');
$query->addParam('fl', 'ss_pdf_access');
$query->addParam('fl', 'ss_pdf_cusvar');
}
But the assigned values are not able to get from template.php from the following function:
function template_preprocess_search_result(&$vars) {
$result = $vars['result'];
print "
"; print_r($result); print "
";
}
Any one can help?
Comments
Comment #1
dave reidComment #2
madhusudanmca commentedHi elangoa,
I'm not sure what's the issue with your code, but I have succesfully implemeted the thing you are trying to do by using "Hook_apachesolr_index_document_build($document, $entity, $entity_type, $env_id)".
E.g.
then use "mymodule_preprocess_search_result(&$variables) " function as shown below:
By using above code snippets you can index fields and can use them in "search-result.tpl.php".
Thanks,
Madhusudan