Allow programmatic disabling of attachment search per Search API Query

Created on 5 August 2025, about 2 months ago

Problem/Motivation

While developing a custom "search mode" that should filter by a specific field only ("title"), I was unable to prevent the research to search inside of attached documents (documents fields in index).
Indeed in Drupal\es_attachment\EventSubscriber\QueryEvent.php, there is an alterQuery on "QueryParamsEvent" provided by elasticsearch_connector module, but it does not allow us to pass any value that tells not to search in document fields.

Steps to reproduce

- Add a "Search api attachments" field in index (eg. : "saa_field_pdf")
- Try researching only by 'title' textfield programmatically (eg. : $query->setFulltextFields(['title']); in HOOK__search_api_query_alter)
=> The research keeps searching in the attached documents, with no workaround.

Proposed resolution

Add the $query object as parameter in QueryParamsEvent so that we can retrieve passed options ? Or anything else that allows us to prevent this to happen

Remaining tasks

Feature request
Status

Active

Version

1.0

Component

Code

Created by

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

Comments & Activities

Production build 0.71.5 2024