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

dave reid’s picture

Category: Feature request » Support request
Issue summary: View changes
madhusudanmca’s picture

Hi 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.

function mymodule_search_apachesolr_index_document_build($document, $entity, $entity_type, $env_id) {
      $document->setMultiValue('myfield_1', $val1);
      $document->setMultiValue('myfield_2', $val2);
}

then use "mymodule_preprocess_search_result(&$variables) " function as shown below:

function mymodule_preprocess_search_result(&$variables) {
  $variables['myfield_1'] = $variables['result']['fields']['myfield_1'];
  $variables['myfield_2'] = $variables['result']['fields']['myfield_2'];
}

By using above code snippets you can index fields and can use them in "search-result.tpl.php".

Thanks,
Madhusudan