I got an headache trying to understand why Search API interface does not allow me to index the "description" part of my file field.
Actually _search_api_wrapper_add_all_properties() uses entity_get_all_property_info() to retrieve all indexable properties for a given entity type.
But entity_get_all_property_info() does this:

  foreach ($info['bundles'] as $bundle => $bundle_info) {
    $bundle_info += array('properties' => array());
    $info['properties'] += $bundle_info['properties'];
  }

This means that for a given field, only the field's property info from the field instance of the first bundle will be retrieved. I have checked the file description property of my file field only for some bundles, and not for the first. Thus this property is not detected by Search API and I can't index it.
Here's a way to have it work, but I don't know if it might break things elsewhere:

  foreach ($info['bundles'] as $bundle => $bundle_info) {
    $bundle_info += array('properties' => array());
    $info['properties'] += $bundle_info['properties'];

    foreach ($bundle_info['properties'] as $name => $property) {
      if (isset($property['property info'])) {
        $info['properties'][$name]['property info'] += $property['property info'];
      }
    }
  }
CommentFileSizeAuthor
#1 0001-Issue-2300139.patch1.15 KBgaëlg

Comments

gaëlg’s picture

StatusFileSize
new1.15 KB

Here's a way to have it work, but I don't know if it might break things elsewhere

Yes, it does break things, under certain circumstances.
If a same long text field is used in two bundles, the first as plain text and the second as filtered text, $info['properties'][$name]['property info'] is not set even if $property['property info'] is set.
This can be solved with an empty array as default value :

  $info['properties'][$name] += array('property info' => array());

Here's the patch.

joelpittet’s picture

@GaëlG is this missing property info expected or should we maybe throw a watchdog error with a backtrace to determine why it's missing in the first place?

gaëlg’s picture

It's expected. To me, the source problem is here, in entity_get_all_property_info() which implicitly makes the assumption that the properties which have the same name across several bundles share the same info in all those bundles. This is not the case for some field properties.

chris matthews’s picture

The 3 year old patch to entity.property.inc applied cleanly to the latest entity 7.x-1.x-dev and (if still relevant) needs review.