I manage an ubercart store that is indexed by Apache Solr. The search indexes the sell price and it's one of the facets. However, the price is nowhere in search-result.tpl.php. It's also not available in the search results preprocess hook in template.php. Is there somewhere else I can inject it into the search results without performing a separate database query for each search result.
1 Answer
You can index it using solr's dynamic fields (see your schema.xml in the solr conf directory) and a custom module hook, namely hook_apachesolr_update_index()
.
Then you can, at search time, add the field you have indexed into the fields being fetched. For this you have three hooks or 'hooks' to choose from: hook_apachesolr_prepare_query()
, hook_apachesolr_modify_query()
and CALLER_finalize_query()
.
For further information on the hooks, see the README.txt in the apachesolr module directory.
Then in your search-result.tpl.php you'll have available the custom indexed field as $result['fields']['your_field_name']
.
-
Just discovered that drupal.stackexchange.com/a/5088/5678 pretty much covers the same basics, although not the search result template.– kekkisCommented Feb 20, 2012 at 13:02