Closed (fixed)
Project:
Facet API
Version:
7.x-1.0-rc4
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
10 May 2012 at 07:13 UTC
Updated:
24 May 2012 at 15:30 UTC
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
Comment #1
amrit_b commentedI added this add got the block listed.. but it doesn't comes up in the search page..
Comment #2
amrit_b commentedOops! 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!
Comment #3
cpliakas commentedamrit_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