Here is the code I wrote to add a new index field, and then add a new facet. Till here it works fine. The facet shows up in admin/config/search/apachesolr/settings/solr/facets

But the relevant block is not showing up at admin/structure/block


function jem_search_apachesolr_index_document_build($document, $entity, $entity_type, $env_id) {
  $collection_id = (int) $entity->field_address_collection['und'][0]['value'];
  $address_collection = entity_load('field_collection_item', array($collection_id));

  $fieldCollection_entity = $address_collection[$collection_id];

  $country = $fieldCollection_entity->field_country['und'][0]['value'];
  $state_province = $fieldCollection_entity->field_state_province['und'][0]['value'];
  $city = $fieldCollection_entity->field_city['und'][0]['value'];

  $document->ss_field_country = $country;
  $document->ss_field_state_provience = $state_province;
  $document->ss_field_city = $city;
}

function jem_search_facetapi_facet_info($searcher_info) {

  //dsm($searcher_info);

  $facets = array();

  // Facets are usually associated with the type of content stored in the index.
  if (isset($searcher_info['types']['node'])) {

    $facets['ss_field_country'] = array(
        'name' => 'my country',
        'label' => t('My country'),
        'field api name' => 'ss_field_country',
        'description' => t('Custom facet by amrit for countries.'),
        'map callback' => 'jem_search_map_ss_field_country',
        'query types' => array('term', 'date'),
        'dependency plugins' => array('role'),
        'default widget' => 'links',
    );
  }

  return $facets;
}

function jem_search_map_ss_field_country(array $values) {
  $map = array();
  foreach($values as $val) {
    $map[$val] = $val;
  }
  return $map;
}

Can anybody help? I want to write a complete Drupal 7 documentation after I figure this out.

Thx
Amrit

Comments

amrit_b’s picture

I added this add got the block listed.. but it doesn't comes up in the search page..

function jem_search_facetapi_force_delta_mapping() {
  return array(
    // The machine-readable name of the searcher.
    'apachesolr@solr' => array(
      // The realm we are mapping, usually block.
      'block' => array(
        // Machine readable names of facets whose mappping are being forced.
        // Regardless of whether they are enabled via the Facet API interface,
        // their blocks will be available to enable and position via
        // admin/structure/block.
        'ss_field_country',
      ),
    ),
  );
}
amrit_b’s picture

Status: Active » Fixed

Oops! my bad..

put wrong value in 'name' of facet_info()

Thank you guys! awesome module :p Spent 2 days to figure everything out! Now will create a widget and I am done!

cpliakas’s picture

amrit_b,

Thanks for posting back! Also, great job finding hook_facetapi_force_delta_mapping(). If you are using that hook properly, you are officially a Facet API rockstar.

Good luck building your widget,
Chris

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.