Impossible to index attachment in nested entity reference

Created on 23 October 2018, over 5 years ago
Updated 2 May 2024, about 2 months ago

Hello,

I have justed tested the module with the version 1.0-beta10 and tika 1.19.

I works fine for file fields directly on the index entity type and on index on media entity.

But my use case is that I want to index attachment with a following structure:

node > block content > media > file

Each ">" is an entity reference field.

The problem is that in search_api_attachments/src/Plugin/search_api/processor/FilesExtractor.php

  protected function getFileFieldsAndFileEntityItems() {
    $file_elements = [];

    // Retrieve file fields of indexed bundles.
    foreach ($this->getIndex()->getDatasources() as $datasource) {
      if ($datasource->getPluginId() == 'entity:file') {
        $file_elements[static::SAA_FILE_ENTITY] = $this->t('File entity');
      }
      foreach ($datasource->getPropertyDefinitions() as $property) {
        if ($property instanceof FieldDefinitionInterface) {
          if ($property->getType() == 'file') {
            $file_elements[$property->getName()] = $property->getLabel();
          }
          if ($property->getType() == "entity_reference") {
            if ($property instanceof FieldConfig) {
              $deps = $property->getDependencies();
              if (in_array('media.type.file', $deps['config'])) {
                $file_elements[$property->getName()] = $property->getLabel();
              }
            }
          }
        }
      }
    }
    return $file_elements;
  }

There is no possibility to explore deeply nested entity reference and there is a hardcoded dependency on the "media.type.file" media type.

Should a recursive scan of the entity reference fields can be done or should the architecture of the module should change completely?

Thanks for any help.

✨ Feature request
Status

Needs review

Version

1.0

Component

Miscellaneous

Created by

πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡³πŸ‡±Netherlands valgibson

    Can confirm that the patch in #17 also applies perfectly to Drupal 9.5.3 (saa 9.0.0). Hope this will be commited in the next stable release.

  • πŸ‡«πŸ‡·France Asterovim Paris

    Hello.

    It's work's with the patch into Drupal Core 10.0.9 and Search API attachments 9.0.1.

    Thanks you.

  • πŸ‡§πŸ‡ͺBelgium bramvandenbulcke

    We've been using patch #17 for some time now and it's working fine!

  • πŸ‡§πŸ‡ͺBelgium Ludo.R Brussels

    Hello,

    Patch #17 works fine.

    For the ones like me who didn't know how it works:
    This patch creates a new field under the file entity itself called "Search API attachments: extracted file".

    This is Node => Paragraph => Media => File:

    field_downloads:entity:field_files:entity:field_media_file:entity:search_api_attachments_extracted_file

Production build 0.69.0 2024