How to add custom fields in Apache Solr's search result? I'm trying to add some custom fields(image field, text field) in Apache Solr's search result.
I ended up found the code below; however, I don't know:


Where to put this code (is it template.php?) 
How to get the information to display them.


`

function mymodule_apachesolr_update_index($document, $node, $namespace) {
  // When indexing nodes, add field from my custom content type.
  if ($node-&gt;type === 'my_contenttype') {
    // Grab the image URI and the description.
    $image_uri = $node-&gt;field_image['und'][0]['uri'];
    $description = $node-&gt;field_description['und'][0]['safe_value'];
    // Add the image and description to the document in the solr index.
    $document-&gt;addField('ss_my_contenttype_image', $image_uri);
    $document-&gt;addField('ts_my_contenttype_description', $description);
  }
}

function mymodule_apachesolr_query_prepare($query) {
  // Add the image.
  $query-&gt;addParam('fl', 'ss_my_contenttype_image');
  // Add the description text.
  $query-&gt;addParam('fl', 'ts_my_contenttype_description');
}


I appreciate any advice.
Thank you.
If you have D7 and latest Solr search integration module then you can follow these steps:


Create a custom module with the following code (If your field is single value text then you should add "ts_" prefix to its name.)

function mymodule_apachesolr_query_alter($query) {
  $query-&gt;addParam('fl', 'ts_field_name');
}

Add the following function in the template.php file

function YOUR_THEME_preprocess_search_result(&amp;$variables) {
  $variables['ts_field_name'] = $variables['result']['fields']['ts_field_name'];
}

Display the field in search-result.tpl.php

&lt;?php if ($ts_field_name): ?&gt;
  &lt;?php print $ts_field_name; ?&gt;
&lt;?php endif; ?&gt;



This is a quick way that doesn't use any  theme function like theme_apachesolr_search_snippets() for search results snippets. 

You can find more information here:


http://archive.org/details/ApacheSolrSearchMastery_250
http://www.slideshare.net/AcquiaInc/apache-solr-search-mastery