I have created a custom field to the node index of apache solr. Here is the code.

function myModule_apachesolr_index_document_build_node(ApacheSolrDocument $document, $node, $env_id) {
  if($node->type == "feature") {
    $support = db_select("custom_table", 'a')
        ->fields("a", array('Support'))
        ->condition('nid', $node->nid)
      $document->addField('custom_field', $support);

And then for this custom field I have created the facet. Here is the code.

function myModule_facetapi_facet_info(array $searcher_info) {
  $facets = array();
     $facets['custom_abot_support'] = array(
      'label' => t('Custom Facet'),
      'description' => t('Filters by Support'),
      'field' => 'custom_field'

The facet successfully created and it has been present in the facets list. But the problem is on the search page. When I try to search some thing, on the search results page this facet only display the title of the facet block. It does not display any content.

Any one what is the problem?

2 Answers 2


I have found the solution.

  • if you wrote this hook hook_apachesolr_index_document_build_node then you have to delete the indexed data from apache solr search index and then reindex all the data. if you only reindex data then it will not work.

  • and 2nd point. you have to keep care of the prefixes of the field. if it is a single string then use ss if multivalue field then use sm

  • 3rd point is you have to call hook_apachesolr_query_alter.

    function myModule_apachesolr_query_alter($query){
       $query->addParams(array('fl' => array('ss_custom_field')));



// module name: apache_group // publicatin field : field_publcation_rits_dev //people rits : field_peoples_rits_term //research rits : $field_research_rits_term // $term_id = field_get_items('node', $node, $field_name);

function apache_group_apachesolr_index_document_build_node(ApacheSolrDocument $document, $node, $env_id) {

$support = db_select("node", 'a')
    ->fields("a", array('title'))
    ->condition('nid', $node->nid)
    ->condition('type', 'publications')
  $document->addField('field_publcation_rits_dev_abc', $support);


function apache_group_facetapi_facet_info(array $searcher_info) { $facets = array(); $facets['custom_abot_support'] = array( 'label' => t('Custom Facet'), 'description' => t('Filters by Support'), 'field' => 'field_publcation_rits_dev_abc' ); }

function apache_group_apachesolr_query_alter($query){ $query->addParam('fl', 'im_field_publcation_rits_dev_new'); // $query->addParams(array('fl' => array('field_publcation_rits_dev_abc'))); }

But no success, what is the issue ??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.