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:
duplicated fields

Expected result
duplication fixed

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);

solution

Command icon 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

j-barnes created an issue. See original summary.

j-barnes’s picture

Status: Active » Needs review
StatusFileSize
new961 bytes

  • j-barnes committed c7e441c0 on 9.0.x
    Issue #3483434: Added check for all_fids to prevent duplication.
    
izus’s picture

Assigned: j-barnes » Unassigned
Status: Needs review » Fixed

this is now merged
thanks

izus’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.