AI Search single chunk, takes the lowest ranked chunk
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3504213. --> Reported by: [marcus_johansson](https://www.drupal.org/user/385947) Related to !450 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>We have the option search_api_ai_get_chunks_result, where if set to false you can choose to get only the highest rated item. This is failing currently.</p> <p>Looking at: <a href="https://git.drupalcode.org/project/ai/-/blob/1.0.x/modules/ai_search/src/Plugin/search_api/backend/SearchApiAiSearchBackend.php?ref_type=heads#L425">https://git.drupalcode.org/project/ai/-/blob/1.0.x/modules/ai_search/src/Plugin/search_api/backend/SearchApiAiSearchBackend.php?ref_type=heads#L425</a></p> <p>You see that if its not suppose to get all the chunks it iterates and tries to save that it has hit the first result, so it doesn't store the next. However the next else is completely open, causing the addResultItem to run again. Since it only has one ID for all chunks, it just keeps replacing it with a less relevant chunk.</p> <h4 id="summary-steps-reproduce">Steps to reproduce</h4> <p>Search for something multichunked in the API Explorer with only one chunk.<br> Compare to searching for it with all chunks.</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>Just change the else, to elseif ($get_chunked), so it skips this if the first conditional fails.<br> Also store the highest relevency score to see if it should override it.</p>
issue