- πΊπΈUnited States damondt
As of 4.3 this hook has been removed in favor of using event subscribers.
See https://www.drupal.org/project/search_api_solr/issues/3254486#comment-14... π Move and revise code examples from hooks to events Active
In the api file, this hook is listed:
/**
* Alter Solr documents before they are sent to Solr for indexing.
*
* @param \Solarium\QueryType\Update\Query\Document\Document[] $documents
* An array of \Solarium\QueryType\Update\Query\Document\Document objects
* ready to be indexed, generated from $items array.
* @param \Drupal\search_api\IndexInterface $index
* The search index for which items are being indexed.
* @param \Drupal\search_api\Item\ItemInterface[] $items
* An array of items to be indexed, keyed by their item IDs.
*/
function hook_search_api_solr_documents_alter(array $documents, \Drupal\search_api\IndexInterface $index, array $items) {
// Adds a "foo" field with value "bar" to all documents.
foreach ($documents as $document) {
$document->setField('foo', 'bar');
}
}
I attempted to implement it:
/**
* Alter Solr documents before they are sent to Solr for indexing.
*
* @param \Solarium\QueryType\Update\Query\Document\Document[] $documents
* An array of \Solarium\QueryType\Update\Query\Document\Document objects
* ready to be indexed, generated from $items array.
* @param \Drupal\search_api\IndexInterface $index
* The search index for which items are being indexed.
* @param \Drupal\search_api\Item\ItemInterface[] $items
* An array of items to be indexed, keyed by their item IDs.
*/
function mymodule_search_api_solr_documents_alter(array $documents, IndexInterface $index, array $items) {
$search_config = \Drupal::config('mymodule.settings');
$site_id = $search_config->get('site_id');
// Ensure we have a default value if none set.
$site_id = !empty($site_id) ? $site_id : 'mymodule';
// Add the configured site id to all documents.
foreach ($documents as $document) {
$document->setField('site_id', $site_id);
}
}
I set a breakpoint and all of this code is getting hit, the $document
object has a new field added. I don't see the custom field in the solr item of the solr admin.
What did I miss?
Fixed
Documentation
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
As of 4.3 this hook has been removed in favor of using event subscribers.
See
https://www.drupal.org/project/search_api_solr/issues/3254486#comment-14...
π
Move and revise code examples from hooks to events
Active