Excerpt with multiple aggregate field shows retrieve field Property Path only of first aggregate field

Created on 20 June 2022, over 2 years ago
Updated 3 March 2024, 9 months ago

Problem/Motivation

We were refactoring our list of fields to use only a few aggregate one and manage more easily the boost value like that.
So we start by adding some aggregate fields:
- for date
- for title
- for text

And like before, we want to have the Excerpt text of the search.
When removing the old fields and leaving only the aggregate fields, we didn't get any more the Excerpt from the result list.

We test many configuration from the Search API backend, also on Solr and on fields.
Then the next step is to check in code, and we found the problem to be in "src/Utility/FieldsHelper.php",
function "extractItemValues()".
In src/Utility/FieldsHelper.php line 245, the field are listed and to get the correct field, the property path is used.
But for aggregate fields, they are all with same datasource id and property path:
#datasourceId: null
#datasource: null
#propertyPath: "aggregated_field"

So it will just return the field aggregate field that is define and not the correct one in our case because aggregate for text is in 3 position.

Steps to reproduce

Get a drupal with search api and search api solr working on a test environment.

Create a media entity and a content entity with both title and text fields. And add both entity on the search api index.

Create 2 aggregates fields:
- the first on on "changed" date for media and content
- the second on the body text for media and content

Enable the excerpt on search api and the processor Highlight so it always return value.

Create a view of the search result page to display the entity list, with a full text input field has a filter.
Display the excerpt text in the result list.

Search on some text that are in the media and/or content and in the result list, no excerpt will be visible.

If you remove the "changed" aggregate field, excerpt will appear because the first aggregate field is now the body.
Or if you add the body text separately on media and content in the field list of the index, it will appear because it will use this fields for the excerpt.

Proposed resolution

Use also the Field Identifier in the problematic function so we really are using the correct aggregate field.

Problem in:

          // If a field with the right property path is already set on the item,
          // use it. This might actually make problems in case the values have
          // already been processed in some way, or use a data type that
          // transformed their original value. But that will hopefully not be a
          // problem in most situations.
          foreach ($this->filterForPropertyPath($item->getFields(FALSE), $datasource_id, $property_path) as $field) {
            $item_values[$combined_id] = $field->getValues();
            continue 2;
          }

Would be good to check if this problem is only in this class or in others places too.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

General code

Created by

πŸ‡©πŸ‡ͺGermany Tomefa Dresden

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.

Production build 0.71.5 2024