Add an entity reference field via Processor & index as id

Created on 11 January 2024, 11 months ago
Updated 16 April 2024, 8 months ago

Problem/Motivation

I'm not sure if this is a feature request or a support request.

I would like to create a fake / aggregated field in the index that will aggregate 2 different entity reference fields together.

So assuming the following data model:

Node Type: Report
Field: Report Topic (field_report_topic) entity reference to Topic node type

Node Type: Program
FIeld: Program Topic (field_program_topic) entity reference to Topic node type

Node Type: Topic

I would like to create a field in the search index that will apply to both Report and Program types, and will combine their 2 topic fields into one. This way, I can use one facet to filter both of them.

I have found examples of how to add an entity reference field via Processor here : https://git.drupalcode.org/project/search_api/-/blob/HEAD/tests/modules/...

This works well to add all the subfields of Topic to the index but it doesn't allow me to just create an integer field for the reference. I can chain in the nid of the Topic node but then I don't get the option to replace the ID with the node title when using a facet, because the field isn't recognized as an entity reference field.

I have tried adding a mapping from 'entity:node' to 'integer' in DataTypeHelper.php as brought up here : https://www.drupal.org/project/search_api/issues/2732341 but that didn't seem to do anything other than remove 'entity_node' fields from the unmapped list. It doesn't allow an integer field to be added to the index that will be recognized by TranslateEntityProcessor facet as an entity reference.

I see that between a couple issues there might be a patch to get me closer:

https://www.drupal.org/project/search_api/issues/2858061 Support for entity reference filtering like TaxonomyIndexTid Postponed
https://www.drupal.org/project/search_api/issues/3253260 Add an entity argument handler Needs work

But it looks like they are still not ready or stale. I'm not quite sure what the referenced core issue is.

Any help appreciated here.

Feature request
Status

Active

Version

1.0

Component

General code

Created by

🇨🇦Canada dtarc

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

Comments & Activities

  • Issue created by @dtarc
  • 🇦🇷Argentina drupal-son

    Hi,

    Any progress on it?

    I have a similar requirement.
    I have a Provider content type with 3 entity reference fields to another Location content type.

    I would like to combine the 3 location fields into 1, then drill down this new index field to get the latitude / longitude of a geofield existing on the Location node and be able to filter by location distance from them.

    Thank you.

Production build 0.71.5 2024