- π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
π Unable to render EntityFields in views with search_api_opensearch Fixed was committed to search_api. Is there anything left here to do?
If I index an item and then try to render it with the "Rendered item" field in Views, Search API crashes:
TypeError: Illegal offset type in isset or empty in Drupal\search_api\Entity\Index->isValidDatasource() (line 358 of /var/www/html/web/modules/contrib/search_api/src/Entity/Index.php).
Drupal\search_api\Entity\Index->isValidDatasource(Array) (Line: 137)
Drupal\search_api\Plugin\views\field\SearchApiRenderedItem->render(Object) (Line: 1158)
Drupal\views\Plugin\views\field\FieldPluginBase->advancedRender(Object) (Line: 238)
This is ultimately because search_api_datasource
is an array, and the code only ever expects it to be a string.
I initially thought this was a side effect of
π
All fields being indexed as arrays
Active
but Elasticsearch Connector doesn't suffer from the same issue. It turns out that in fact Elasticsearch Connector does not index the search_api_id
, search_api_datasource
or search_api_language
fields separately. Instead, the Search API ResultRow object has a magic getter and special code to lazy-load these values from methods on the original Item object:
/**
* The lazy-loaded properties, as property names mapped to item methods.
*
* @var string[]
*/
protected static $lazyLoad = [
'search_api_id' => 'getId',
'search_api_datasource' => 'getDatasourceId',
'search_api_language' => 'getLanguage',
'search_api_relevance' => 'getScore',
'search_api_excerpt' => 'getExcerpt',
];
Commenting out the call to $this->addSpecialFields()
in IndexParamBuilder::buildIndexParams()
avoids these fields ever being added to the index in the first place.
Create a view that uses the "Rendered item" field, and use it to render a search result.
Remove IndexParamBuilder::addSpecialFields()
.
Postponed: needs info
2.0
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
π Unable to render EntityFields in views with search_api_opensearch Fixed was committed to search_api. Is there anything left here to do?