You are here

function rich_snippets_apachesolr_image_indexing_callback in Rich Snippets 7

Indexing callback that stores the image uri.

1 string reference to 'rich_snippets_apachesolr_image_indexing_callback'
rich_snippets_apachesolr_field_mappings in ./rich_snippets.apachesolr.inc
Implements hook_apachesolr_field_mappings().

File

./rich_snippets.apachesolr.inc, line 205
Apache Solr Search Integration hook implementations and helper functions.

Code

function rich_snippets_apachesolr_image_indexing_callback($entity, $field_name, $index_key, $field_info) {
  $fields = array();
  if (!empty($entity->{$field_name}) && rich_snippets_has_schemaorg_mapping($entity, $field_name)) {
    $field = $entity->{$field_name};
    list($lang, $values) = each($field);
    for ($i = 0; $i < count($values); $i++) {

      // Load the file object of the styles image, bail if FALSE is returned.
      if (!($file = rich_snippets_create_styled_image($values[$i]['uri'], RICH_SNIPPETS_STYLE_NAME))) {
        continue;
      }

      // Get the raw binary data of the image.
      if (!($data = file_get_contents($file->source))) {
        watchdog('rich_snippets', 'Error reading contents of image @uri.', array(
          '@uri' => $derivative_uri,
        ), WATCHDOG_ERROR);
        continue;
      }

      // Store the base64 encoded image data.
      $fields[] = array(
        'key' => $index_key,
        'value' => base64_encode($data),
      );

      // Store the image info in an unindexed text field.
      $fields[] = array(
        'key' => rich_snippets_get_apachesolr_image_info_field($index_key),
        'value' => drupal_json_encode($file->info),
      );
    }
  }
  return $fields;
}