Drupal Adding apache solr index for field-collection

If images / content are bounded by field collection module, you can try approach below to index to solr



//Index product images

$field_collection_items = field_get_items(‘node’, $node, ‘field_image_set’);

$field_collection_item_ids = array();

$i = 0;

foreach ($field_collection_items as $field_collection_item){

$field_collection_item_ids[$i] = $field_collection_item[‘value’];



$field_collection_item_fields = entity_load(‘field_collection_item’, $field_collection_item_ids);

$image_fields = array();

$i = 0;

foreach ($field_collection_item_fields as $field_collection_item_field){

$image_fields[$i] = field_get_items(‘field_collection_item’, $field_collection_item_field, ‘field_image’);




$i = 0;

foreach ($image_fields as $image_field){

foreach ($image_field as $image)

$path = file_create_url($image[‘uri’]);

$document->setMultiValue(‘sm_field_image_’.$i++, $path); //Set multiple field_image values




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s