Problem/Motivation
We have multiple search attachment fields in our index and I've noticed that if certain fields have files while others do not, the empty fields get filled with the previous file content. This causes our index to contain duplicate data on fields that should not contain that information and negatively effects the relevance scoring.
Duplicate fields:

Expected result

Proposed resolution
If looks like $files will persist during different field iterations. So if the value is set, and on another iteration an empty field causes the statement to break out of the checks, it falls back to if (!empty($files) where it uses the previous file.
A simple solution is just to add a check for $all_fids such as: if (!empty($files) && !empty($all_fids)) {
A better fix may be to pull the loading of files outside the conditional check so that it's always updated.
$files = $this->entityTypeManager
->getStorage('file')
->loadMultiple($fids);

| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 3483434-duplication-for-empty-fields.patch | 961 bytes | j-barnes |
| issue-search-attachments.png | 414.2 KB | j-barnes | |
| duplcating_search_field_fixed.png | 131.02 KB | j-barnes | |
| duplicating_search_field.png | 630.01 KB | j-barnes |
Issue fork search_api_attachments-3483434
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
j-barnes commentedComment #5
izus commentedthis is now merged
thanks
Comment #6
izus commented