search_api_node_access_records_alter() makes assumptions about how indexes handle entities

Created on 17 May 2024, 5 months ago

Problem/Motivation

search_api_node_access_records_alter() makes several assumptions about how an index is handling entities and search item Ids:

    foreach ($index->getDatasources() as $datasource_id => $datasource) {
      switch ($datasource->getEntityTypeId()) {
        case 'node':
SNIP
          $item_id = $datasource->getItemId($node->getTypedData());

Here it's assuming that any data source that handles nodes is forming search items from the node's typed data representation.

          $item_id = $datasource->getItemId($node->getTypedData());
          if ($item_id !== NULL) {
            $index->trackItemsUpdated($datasource_id, [$item_id]);
          }

Here it's assuming that there will be only one index ID for a particular node.

However, neither of these two assumptions are always correct!

I'm in the process of writing a SearchAPI datasource for entities with https://www.drupal.org/project/date_recur . It's very similar to this sandbox https://www.drupal.org/sandbox/sam/3200275 but instead of passing custom typed data into the index, I'm passing multiple versions of the same entity, one for each occurrence of the recurring date, with different date value each time.

Steps to reproduce

Proposed resolution

Remaining tasks

Feature request
Status

Active

Version

1.0

Component

General code

Created by

🇬🇧United Kingdom joachim

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

Comments & Activities

Production build 0.71.5 2024