Fix SolrDocument::loadMultiple()

Created on 2 March 2023, over 1 year ago
Updated 14 June 2023, over 1 year ago

While trying to get a setup to work with an index containing both Drupal-internal and external documents, I came across two problems in \Drupal\search_api_solr\Plugin\search_api\datasource\SolrDocument::loadMultiple():

  1. At least for me, the setup only worked when including an ss_search_api_id field (as well as a few others) for all external documents with a value starting with solr_document/. This makes sense, as it will allow the Search API to correctly determine the datasource. However, the \Drupal\search_api_solr\Plugin\search_api\datasource\SolrDocument::loadMultiple() method receives raw item IDs, with their solr_document/ stripped – which the code currently doesn’t take into account properly. We should either add that prefix again before creating the load query, or include both variants of the IDs (with and without prefix) in $ids to be on the safe side (in case it’s possible to get the setup to work with ss_search_api_id values that are not prefixed that way).
  2. Once I got the load query to return any results, $this->solrDocumentFactory turned out to be NULL, resulting in a fatal error. I think $this->getSolrDocumentFactory() should be used instead.

I’m not 100% sure the first one is a bug, or my setup is just wrong, but the second is definitely a problem.

🐛 Bug report
Status

Fixed

Version

4.0

Component

Solr Document Datasources

Created by

🇦🇹Austria drunken monkey Vienna, Austria

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

Comments & Activities

Production build 0.71.5 2024